Excluding certain properties when asserting objects with FluentAssertion

It’s very common that we assert if two objects are equivalent in unit tests. Using FluentAssertion, this looks like the following

However, there are times where you want to exclude certain properties when comparing objects. This might be because the value of the property cannot be predicted or you just don’t want to include … [Read more…]

Json.net serialisation issue when returning Entity Framework models in Web API

It’s very typical for Entity Framework models to have circular references. For example:

This, however, will cause serialisation error when returning these EF models in Web API controller because it detects that there are circular references. The json serialiser does not know how to handle circular reference.

There are a few solutions to … [Read more…]

Code review, why it matters

This is the first post in my series of blog posts about some of the bad codes or bad practices I’ve come across. Note that this is my personal opinion and some of the things I mention could be debatable. Post 1: Code review, why it matters Post 2: Not including JS, CSS and static content … [Read more…]

Organising unit tests into partial classes

When unit testing a service, I tend to have a base class where I do all the setting up/initialisation. For each method in the service, I’d have a separate unit test class which derives from the base class. For example, if I want to unit test two methods GetAllNews and GetNewsById in SampleNewsService, I’ll have a SampleNewsServiceTestsBase … [Read more…]