Posts

Showing posts from August, 2015

Mocking EF DataContext with Moq

So I wanted to mock the interface I use as base for my data context in my unit tests. Mocking the interface itself is pretty easy, but I wanted to check if the properties of type DbSet have changed correctly. So, all we need to do is mock the methods of the DbSet we are using, e.g. Add() and AddRange(), and use a callback to send the value of the method calls to a List . As you can see, the method calls to a DbSet can easily be captured and send to another List which we can use for our asserts.