I m doing EF with repository and Unit of Work, and my controller has Unit of Work
interface which I m instantiating in constructor.
It was a little easy to mock while using repositories but I am really not getting how to mock UoW interface in test class. I m using JustMock Light
for mocking, please guide me how to do it ?
Thanks
There's a chain dependency in UoW. UoW is dependent on IGenericRepository interface, IGenericRepository is dependent on DBContext object, your question here is really how to mock up DBContext object. Here's a good documentation to explain it. click me
Basically what you need to do is create an interface for DbContext to implement and wrap DbContext methods with interface methods. Then you mock up the interface you created and do the unit test.In here you have two options, 1. config the mock framework to fake the interface or 2. create a fake class implements the interface. I recommend option 2 as the fake class is reusable.