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# - Mocking EF core dbcontext and dbset - Stack Overflow
stackoverflow.com › questions › 54219742Jan 16, 2019 · 6 Answers. Sorted by: 172. I see you are using EF core DbContext in your MovieRepository. So instead of using mock, Using EF Core InMemory database will be a great option for you. This will also reduce the complexity. Write your GetAllTest () method as follows: [Fact] public void GetAllTest () { var options = new DbContextOptionsBuilder<MovieDbContext> () .UseInMemoryDatabase (databaseName: "MovieListDatabase") .Options; // Insert seed data into the database using one instance of the ...