Skip to content

Helper methods for unit testing code with Entity Framework contexts and Moq

License

Notifications You must be signed in to change notification settings

mondayuk/EFUnitTestsExtensions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EFUnitTestsExtensions Build status

Helper methods for unit testing code with Entity Framework contexts and Moq

Usage

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
}

Issues and feature Requests

Just open an issue above

Downloads

Download from NuGet.

Download the continuously integrated Binaries from AppVeyor.

About

Helper methods for unit testing code with Entity Framework contexts and Moq

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%