Skip to content

MichalJankowskii/Moq.EntityFramework6.Helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moq.EntityFramework.Helpers

Build Status Downloads

This library helps you with mocking EntityFramework contexts. Now you will be able to test methods that are using DbSet<TEntity> from DbContext in effective way.

Installation - NuGet Packages

Install-Package Moq.EntityFramework.Helpers

Usage

For example we can assume that we have following production code:

public class UsersContext : DbContext
{
    public virtual DbSet<User> Users { get; set; }
}

For mocking Users you need only implement following 3 steps:

1. Create DbContext mock:

var userContextMock = new Mock<UsersContext>();

2. Generate your entities:

IList<User> users = ...;

3. Setup DbSet propery:

userContextMock.Setup(x => x.Users).Returns(users);

And this is all. You can use your DbContext in your tests.

You will find examples of this library in repository.

About

Library that provides methods that will help you with mocking EntityFramework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published