I am creating a unit test that invokes a create task method. The create task method calls some mocked external object which are the purpose of my test, but inside my tested method there is also a SaveChanges call that saves my task.
What I am trying to do is to shim the DbContext class inside System.Data.Entity so that the SaveChanges method no longer accesses the database.
I have added a fake assembly for System.Data.Entity but when I use System.Data.Entity.Fakes it says "cannot resolve symbol 'Fakes'", though I can access System.Data.Fakes (but I have't added a fake assembly for System.Data)
I have faked other methods in my entities context, but I can't fake SaveChanges method on my entity since the method is inherited from DbContext.
ShimDBEntities.AllInstances.SaveChanges = (x) => { ... };
the upper chunk of code says "cannot resolve symbol 'SaveChanges'".
So how can I shim DbContext using Microsoft Fakes?
I have managed to do it by creating a SaveChanges method in my BaseRepository class and use it in all of my derived repositories where I had db.SaveChanges.
Then I shimed my BaseRepository so that my SaveChanges method would do nothing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With