Skip to content

Simple Fluent API for mocking DbContexts and DbSets. Allows easy setups for Set<T>, Model, e => e.Prop style accessors.

License

Notifications You must be signed in to change notification settings

jolmari/efcore-mock-dbcontext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EFCore 3.1 - DbContext Mocker

Simple Fluent API for mocking DbContexts and DbSets. Allows easy setups for Set<T>, Model, e => e.Prop style accessors.

Usage

Mocking a database context

_mockDbContext = MockDbContextBuilder
    .BuildMockDbContext<ISampleDbContext>();

Mocking the result of a Set call:

MockDbContextBuilder
    .BuildMockDbContext<ISampleDbContext>();
    .AttachMockDbSetToSetMethodCall(MockDbContextBuilder.BuildMockDbSet(_persons));
    
// Usage:
var result = _mockDbContext.Object
    .Set<Person>()
    .Where(p => p.Identification == "123456-1234A")
    .ToList();

Mocking the result of a property call:

// Mock:
MockDbContextBuilder
    .BuildMockDbContext<ISampleDbContext>();
    .AttachMockDbSetToPropertyCall(MockDbContextBuilder.BuildMockDbSet(_pets), context => context.Pets));
      
// Usage:
var result = _mockDbContext.Object
    .Pets
    .Where(p => p.FullName == "Bella");

Mocking the result of a Model["key"] call:

// Mock:
MockDbContextBuilder
    .BuildMockDbContext<ISampleDbContext>();
    .AttachMockDbSetToModelCall(MockDbContextBuilder.BuildMockDbSet(_hobbies), "Hobbies");
    
// Usage:
var result = _mockDbContext.Object
    .Model["Hobbies"];

About

Simple Fluent API for mocking DbContexts and DbSets. Allows easy setups for Set<T>, Model, e => e.Prop style accessors.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages