C#C
C#4y ago
Esa

❔ Mocking with EntityFrameworkCore

Hm,
I'm creating unit tests for a class that has a private readonly MyDbContext dbContext; that causes a few problems.

InternalDbSet<MyEntity> invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.


And you can't really mock that as you would everything else, because you cannot instantiate any DbSet collections as they don't have a non-private constructor.

Anybody who has mocked stuff with DbContexts on them? I'm not sure how to approach this.
Was this page helpful?