Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

License

Notifications You must be signed in to change notification settings

intrinity/Moq.EntityFrameworkCore

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moq.EntityFrameworkCore

Build Status Downloads

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

Installation - NuGet Packages

Install-Package Moq.EntityFrameworkCore

Usage

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

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

    public virtual DbQuery<Role> Roles { get; set; }
}

To mock Users and Roles you only need to implement the following 3 steps:

1. Create DbContext mock:

var userContextMock = new Mock<UsersContext>();

2. Generate your entities:

IList<User> users = ...;
IList<Roles> roles = ...;

3. Setup DbSet or DbQuery property:

userContextMock.Setup(x => x.Users).ReturnsDbSet(users);
userContextMock.Setup(x => x.Roles).ReturnsDbQuery(roles);

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

You will find examples of this library in the repository.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.