Posty

AutoCodeCoverage - how it can help you find a bug

Obraz
Hi Last time I shown you what is AutoCodeCoverage. Today I would like to show you how it can help you. I'll show you how it can find small mistakes in you code. Let's start. Last time i shown my example solution which was covered in 100% by unit tests with AutoCodeCoverage.  There were 3 projects - SimpleClassLibrary, SimpleClassLibrary2 and UnitTestProject1. It looked like:  Now it looks like: I added more empty implementations of interface Inter1Lib2 and change logic of Class2. Old Class2 was looking like this: namespace SimpleClassLibrary { public class Class2 { public void HowIWasCreated(Class1 cl) { if (cl == null) { Console.WriteLine("null"); return; } if (cl.HowCreated() == EnumHowCreated.DefaultConstructor) { Console.WriteLine("Default"); } if (cl.HowCreated() == EnumHowCreated.ParameterConstructor) { Console.WriteLine("Paramet

AutoCodeCoverage - nuget package for covering .net code with tests

Obraz
Hi I was wondering for some time about code coverage in c#. I'm using a lot of DTO objects which should be covered by unit tests. I thought that it should be covered by default. I wrote simple project FakeCodeCoverage. It used reflection to cover the simplest way in constructors and methods. It was not enough for me. It was really only fake coverage. I abandoned this project but I started new project AutoCodeCoverage. This is different from the previous one because it tries cover all statements, branches and conditions. As result you can get all exceptions which was thrown while invoking methods, constructors, properties, etc. It allows to inject implementation of interface or instance of type which will be used at all times when this type will be exist as parameter. In DTOs or simple projects AutoCodeCoverage could cover up to 100% lines of your code. It is published on nuget https://www.nuget.org/packages/AutoCodeCoverage Actually it support .net4.x, .netcore

[Part 2] Is c# safe? Readonly fields... Really readonly?

Hi Today I present you part 2 of "Is c# safe" series.  Few days ago I though about whether possibility to set value to readonly field outside the constructor. Quoting the Microsoft website: "The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class. Example In this example, the value of the field year cannot be changed in the method ChangeYear, even though it is assigned a value in the class constructor..." As last time, I wrote unit tests to see if it is possible.  commit to my github Unfortunately Microsoft... Using reflection above sentence isn't true. I added new class named " InternalCallReadonlyVsConst " and it looks like below namespace InternalClasses { class InternalCallReadonlyVsConst { private readonly int privateR

[Part 1] Is c# safe? Are Internal class accessible only from the same assembly?

Obraz
Hi I was wondering for some time about encapsulation in C#. Are internal class accessible only from the same assembly? Are private fields accessible only from inside class? Quoting the Microsoft website: "Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared...." "Internal types or members are accessible only within files in the same assembly..." It looks like true. I believed it, but I decided to check it out. There is a possibility to read and modify private fields and create instances of internal classes when reflection is used. Reflection is the built-in mechanizm allowing to dynamically create instance of class or invoke methods. Unfortunately it allows access to private fields and much more... I wrote a simple example showing how powerful is reflection. Code is uploaded to github.  GITHUB - PrivateFieldsInternalClass My soluti

Wzmacniacze smaku w produktach

Obraz
Cześć, Ostatni temat na dzisiaj to wzmacniacze smaku. Są to produkty, powodujące, że odczuwany smak danego produktu jest wzmocniony. Większość z nich uzależnia i powoduje, że jedzenie bez wzmacniacza smaku jest niesmaczne. Dodatkowo wzmacniacze smaku mogą powodować bóle głowy reakcje alergiczne oraz zawroty głowy. Aksam Beskidzkie Paluszki o smaku ser cebulka 220 g mąka pszenna, preparat serowo-cebulowy [warzywa suszone (cebula - 1,9%, por), sól, drożdże autolizowane, cukier, maltodekstryna, ekstrakt drożdżowy (zawiera gluten), wzmacniacz smaku: glutaminian monosodowy, olej roślinny słonecznikowy, ser w proszku (z mleka) (0,1%), regulator kwasowości: kwas cytrynowy, serwatka (z mleka), ekstrakt przyprawy], olej roślinny rzepakowy, sól, cukier, regulator kwasowości: wodorotlenek sodu, substancje spulchniające: węglany sodu, węglany amonu

Olej palmowy w produktach

Obraz
Cześć, Poprzedni post zawiera listę niezdrowych produktów zawierających utwardzony tłuszcz, natomiast naszło mnie przemyślenie, że producenci nie muszą podawać, że dany produkt zawiera utwardzony tłuszcz roślinny. Najczęściej spotykany może on być pod postacią oleju lub tłuszczu palmowego. Poniżej lista produktów jakie udało się odnaleźć z tymi składnikami. 3Bit Baton w czekoladzie mlecznej z nadzieniem mlecznym i herbatnikiem 46 g cukier, tłuszcz roślinny (palmowy), herbatnik 14% [mąka pszenna, cukier, olej palmowy, pełne mleko w proszku, sól, substancje spulchniające (węglany sodu, węglany amonu), emulgator (E 481)], odtłuszczone mleko w proszku (w nadzieniu 7%), serwatka w proszku (z mleka), tłuszcz kakaowy, miazga kakaowa, tłuszcz mleczny, emulgator (E 442, lecytyna sojowa, lecytyna słonecznikowa), aromaty, sól, Oprócz tłuszczu kakaowego zawiera tłuszcze roślinne 3Bit Baton w czekoladzie mlecznej z nadzieniem o smaku orzechowym i herbatnikiem 46 g cukier, tłuszcz ro