How to Mock Entity Framework DbContext for Unit Testing
dotnetthoughts.net › how-to-mock-dbcontext-forAug 6, 2019 · This post is about how to mock entity framework DbContext class for unit testing without any third party framework. The dotnet core framework designed and developed considering testability of the apps in mind. Usually for testing the applications which interacts with database, we used to follow two approaches 1) We will be using a repository layer to interact with Database and using any mock framework (without a mocking framework also we can implement it.), we will mock the repository and ...
c# - How to mock up dbcontext? - Stack Overflow
stackoverflow.com › questions › 37630564Jun 4, 2016 · You could abstract your DbContext to make it mockable. public interface IDbContext { DbSet<Blog> Blogs { get; set; } //...other properties and members needed for db context int SaveChanges(); } public class ApplicationDbContext : DbContext, IDbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<Blog> Blogs { get; set; } }
c# - Mocking EF DbContext with Moq - Stack Overflow
stackoverflow.com › questions › 25960192I created an interface IDbContext with the following functions: public interface IDbContext : IDisposable { IDbSet<T> Set<T> () where T : class; DbEntityEntry<T> Entry<T> (T entity) where T : class; int SaveChanges (); } My real context implements this interface IDbContext and DbContext. Now I'm trying to mock the IDbSet<T> in the context, so it returns a List<User> instead.