huysentruitw / entity-framework-core-mock

Easy Mock wrapper for mocking EFCore5 DbContext and DbSet using Moq or NSubstitute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mock database provider

lonix1 opened this issue · comments

For some kinds of method calls, I get this:

{System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

For example, it will happen if I call contextMock.Object.Database.GetPendingMigrationsAsync().

Does this library help me in that regard?

For all other cases, this library works very well, thank you for making it!

The use-case of this library is to mock DbSet for simple unit-tests, for more complex scenarios, please consider using the available EF Core InMemory database or more end-to-end with SQL lite or an actual database. See also: https://docs.microsoft.com/en-us/ef/core/testing/in-memory