Helper methods for unit testing code with Entity Framework contexts and Moq
Empty context with no data, to mock a bare bones table
var mockedContext = new InjectableMockedContext<AdventureWorksContext>();
mockedContext.MockEntity(x => x.Products); // No seed to mock empty db
var classUnderTest = new SomeDal(mockedContext.MockedContext.Object);
//OR
var classUnderTest = new SomeDal(){
Context = mockedContext.MockedContext.Object
}
Or if you want to seed some data or put in values to test and see if you logic is building the query correctly and passing it along
var mockedContext = new InjectableMockedContext<AdventureWorksContext>();
var seedLIst = new List<Product>();
seedLIst.Add(new Product { ProductId = 1, Transactions = new List<TransactionHistory> { new TransactionHistory { TransactionId = 1 } } });
seedLIst.Add(new Product { ProductId = 2 });
mockedContext.MockEntity(x => x.Products, seedLIst);
var classUnderTest = new SomeDal(mockedContext.MockedContext.Object);
//OR
var classUnderTest = new SomeDal(){
Context = mockedContext.MockedContext.Object
}
Just open an issue above
Download from NuGet.
Download the continuously integrated Binaries from AppVeyor.