i need to mock EF for my unit tests. Many tests are already working, but now i'm in a test that needs to mock the Database-Object in my DbContext, because the MyDbContext.Database.ExecuteSqlCommand is called.
Like this (almost 3 years ago and unanswered) Moq Entity Frameworks ExecuteSQLCommand
But with NSubstitue.
UPDATE:
I'm using the identity framework. So if nsubstitute is not throwing an exception itself, i get an exception from the identity framework
Castle.Proxies.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
Castle.Proxies.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
I tried all the following:
DBContextMock.When(x => { var get = x.Database; }).DoNotCallBase();
DBContextMock.When(x => { var get = x.Database.ExecuteSqlCommand("UPDATE"); }).DoNotCallBase();
DBContextMock.Database.ExecuteSqlCommand("UPDATE").ReturnsForAnyArgs(0);
Any ideas to mock the Database object?