Why can't I call the UseInMemoryDatabase method on DbContextOptionsBuilder?
According to EF Core: Testing with InMemory reference, you need to add the Microsoft.EntityFrameworkCore.InMemory package to use UseInMemoryDatabase()
extension method with DbContextOptionsBuilder
:
Install-Package Microsoft.EntityFrameworkCore.InMemory
Afterwards, you can follow example given in "Writing tests" section like this:
var options = new DbContextOptionsBuilder<ProductContext>().UseInMemoryDatabase(databaseName: "database_name").Options;
using (var context = new ProductContext(options))
{
// add service here
}
You need it to use UseInMemoryDatabase
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0" />
</ItemGroup>