C
C#2y 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.
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.
3 Replies
Saber
Saber2y ago
dont mock it problem solved 🙂
Alexicon
Alexicon2y ago
Usually if I need to have a dbcontext for my unit tests, I will use the entity framework core in memory database rather than a mock. You can also use sqlite in memory if your using a relational database setup.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server