Mocking Entity Framework when Unit Testing ASP.NET Web API 2
learn.microsoft.com › en-us › aspnetSep 29, 2022 · Select Web API 2 Controller with actions, using Entity Framework. Set the following values: Controller name: ProductController; Model class: Product; Data context class: [Select New data context button which fills in the values seen below] Click Add to create the controller with automatically-generated code. The code includes methods for creating, retrieving, updating and deleting instances of the Product class.
NuGet Gallery | Moq.EntityFrameworkCore 7.0.0.2
www.nuget.org › packages › MoqMoq.EntityFrameworkCore 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: