I have written an extension method helper for loading fake data into the DbContext
public static void RegisterFakeData<T>(this DbContext databaseContext, ObjectSet<T> action, IEnumerable<T> fakeData) where T : class
{
Isolate.WhenCalled(() => action).WillReturnCollectionValuesOf(fakeData.AsQueryable());
}
This works as desired but I was wondering if it is possible to derive the property on the dbcontext being passed in (action parameter) from the type of the fake data.
So if I'm setting the Customer property I just pass in a list of customers.
Current usage:
Isolate.Fake.StaticConstructor<DbContext>();
var databaseContext = Isolate.Fake.Instance<DbContext>();
databaseContext.RegisterFakeData(databaseContext.Customer, new List<Customer> { new Customer { CustID = "cust1", RegionCode = "region1"}})
Desired usage:
databaseContext.RegisterFakeData(new List<Customer> { new Customer { CustID = "cust1", RegionCode = "region1"}})
I'm Bar from Typemock.
Because we don't fake any reflection methods you can use this workaround: