I have these classes:
public static class UnitOfWorkSS
{
public static IUnitOfWork Begin()
{
return IoC.Resolve();
}
}
public clas
It looks like the only thing you are doing with the call to Begin() is returning your configured class for that particular interface: IUnitOfWork
You really just need to make sure that your call to Begin() returns a mock implementation of IUnitOfWork
One of two ways you can do this:
Option One - Refactor UnitOfWorkSS
so that you can set the instance of IUnitOfWork
to be returned
public static class UnitOfWorkSS
{
private static IUnitOfWork _unitOfWork;
public static IUnitOfWork UnitOfWork
{
set { _unitOfWork = value; }
private get{ _unitOfWork ?? (_unitOfWork = IoC.Resolve()); }
}
public static IUnitOfWork Begin()
{
return UnitOfWork;
}
}
[TestMethod]
public void DoStuff()
{
var mockUnitOfWork = new Mock();
UnitOfWorkSS.UnitOfWork = mockUnitOfWork.Object;
//Do some setup and verify
}
Option Two - Simply register a mock instance of IUnitOfWork
with your IoC Container
private Mock _mockUnitOfWork;
[TestInitialize]
public void Init()
{
_mockUnitOfWork = new Mock();
//Making a lot of assumptions about your IoC here...
IoC.Register(_mockUnitOfWork.Object);
}
[TestMethod]
public void DoStuff()
{
_mockUnitOfWork.Setup( ... );
//Do some verification
}