© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
3 replies
Esa

❔ Mocking with EntityFrameworkCore

Hm,
I'm creating unit tests for a class that has a
private readonly MyDbContext dbContext;
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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ EntityFrameworkCore
C#CC# / help
4y ago
✅ EntityFrameworkCore lists
C#CC# / help
4y ago
✅ Problems with mocking a ServiceProvider
C#CC# / help
3y ago
WPF Database records question (EntityFrameworkCore)
C#CC# / help
3y ago