Project Description
Links
GitHub: https://github.com/MichalJankowskii/Moq.EntityFrameworkCore
NuGet: https://www.nuget.org/packages/Moq.EntityFrameworkCore/
Description
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.
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 to implement following 3 steps:
1. Create DbContext mock:
var userContextMock = new Mock<UsersContext>();
2. Generate your entities:
IList<User> users = ...;
3. Setup DbSet property:
userContextMock.Setup(x => x.Users).Returns(users);
And this is all. You can use your DbContext in your tests.
Leave A Comment