Tag Archives: mocking

Mocking “this”

Let’s assume we have a simple service that is also using an inner service, providing a few operations as follows: public interface IService {     string A();     string B();     string C(); } public class Service : IService {     private readonly IInnerService innerService;     public Service(IInnerService innerService)     {         this.innerService = innerService;     }     public string A()     {         return “A”;     }     public string B()     {         return b(); … Continue reading

Posted in .NET, C# | Tagged , , , | Leave a comment

When optionals are… required

Assume you have developed a service, with methods requiring arguments, properly extracted into a interface. Then you (or your customers) would write nice clients for your service. Of course, such clients will probably be unit tested in isolation, such as … Continue reading

Posted in C# | Tagged , , , | Leave a comment

Mocking Entity Framework to unit test your data services

It’s not easy to write unit tests for services that use DbContext and DbSet<T> classes from Entity Framework (or Entity Framework Core), and there are complex solutions to approach this, like separating the data access layer completely, as I propose in my UnitOfWork-EntityFramework implementation. … Continue reading

Posted in Architecture, C# | Tagged , , , , , , | Leave a comment