Questions tagged [mockdbset]

MockDbSet is a framework for mocking Entity Framework code.

MockDbSet (a.k.a. FakeDbSet) is a framework for mocking Entity Framework code.

Resources

4 questions
4
votes
1 answer

Enumerating a Moq'ed IDbSet throws exception: "Collection was modified; enumeration operation may not execute."

I'm trying to Mock IDbSet using the Moq framework. The unit test should add a new record (entity) to an existing Mocked DbSet collection (SetUp) and return the count of the new collection. My TestInitialize Setup looks like: public class BlogTests …
Javi Kroonenburg
  • 1,050
  • 8
  • 11
2
votes
1 answer

Entity Framework Core FromSqlRaw mock test cases

I am creating a integration test for api method which have some query like below public async static Task> ForSysAll(this DbSet dbSet,int id) where T : class { return await dbSet.FromSqlRaw($"SELECT * FROM dbo.TableName…
1
vote
1 answer

Mocking database context class with DbSet instead of IDbSet in Entity Framework

I am developing an Asp.Net mvc application. I am doing unit testing to my application. I use Moq to mock objects. In my test I need to mock database context and its DbSets. I can mock database context and test. But the problem is I have to change…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
0
votes
1 answer

InMemoryDb unit test exception

I try to write unit test for repository. I use InMemoryDb (https://www.nuget.org/packages/FakeDbSet) set to mock DbSet but I get exception "Expression is not a method invocation: p => p". What do I there wrong? try { …
Jacek
  • 11,661
  • 23
  • 69
  • 123