Reputation: 845
Suppose that I have the following code:
public Item CoolFunction(int i) {
var result = SomeContext.Item.First(t => t.Id == i);
return result;
}
Suppose for whatever reason I want to unit test this method. In this case, I can use MS Fakes to fake the context. But if I want to test this code against a real Db, I have to write another unit test to do so. Is there a (nice or convenient or recommended) way to write one unit test with a switch that can test with the fake context or real db?
Upvotes: 0
Views: 336
Reputation: 2103
I definitely recommend checking out Effort: https://effort.codeplex.com/
It's an "Entity Framework Unit Testing Tool" that sets up an in-memory database. The database can either be "transient" (recreated for each test) or "persistent" (the same database is maintained for all unit tests).
The best of both worlds for unit and integration testing. I've found it to be simpler than just mocking the IDbSet.
Upvotes: 1