Skip to main content


Showing posts with the label NSBuilder

Unit Testing with NBuilder and NSubstitute using either a FakeDBSet or a mock DbSet

In the previous blog post I showed how you can unit test with NBuilder and NSubstitute by using a FakeDbSet implementation. The thing is that we do not necessarily have to use a FakeDbSet but can also try and mock the DbSet. Let's see how we can changes the implementation from last week's blog post to mock DbSet instead. First thing to note is that a lot of examples for mocking the DbSet using other mocking frameworks such as Moq (such as this one) will demonstrate using DbSet and IQueryable, but it turns out that people using NSubstitute run into all sort of problems with this, as this SO question demonstrates. The solution seems to be to use IDbSet throughout. Both for defining the type of your DbSet in the DbContext, and also when mocking the DbSet.
✔
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the lin…