Hi Christian,
The issue you raised regarding faking Microsoft Entity Framework classes is a complicated one and the solution depends on what you’re testing and what you’re trying to fake.
Faking DbSet is as easy as faking any other class. Bu it may not be enough.
For instance, in your code example, using:
var items = _entityDbSet.Where(e => true); will return null because _entityDbSet is fake. It maybe that you want to return another value:
//Act
Var COLLECTION_OF_ENTITIES = new list…
Isolate.WhenCalled(() => _entityDbSet.Where(e => true)).WillReturn(COLLECTION_OF_ENTITIES );
But this may not solve your problem. That’s why it’s important for us to see what you’re trying to test.
By the way, in your example, both of the lines below are equivalent since Members.ReturnRecursiveFakes is the default parameter passed to Isolate.Fake.Instance<>().
//Arrange
var _entityDbSet = Isolate.Fake.Instance<DbSet<SomeEntityClass>>();
//Arrange?
//_entityDbSet = Isolate.Fake.Instance<DbSet<SomeEntityClass>>(Members.ReturnRecursiveFakes);
I hope it will answer your question!