Hi, I am testing this piece of code:
What I would like is to force that exception in some way, right now I have tried this:
public void SaveChanges()
{
try
{
//some code here
}
catch (MyException dbEValEx)
{
RaiseValidationError(dbEValEx);
}
catch (MySecondException dbUpdateException)
{
RaiseUpdateException(dbUpdateException);
}
}
What I would like is to force that exception in some way, right now I have tried this:
Any ideas of how to do it?//Class to be tested
var fooUnitOfWork = Mock.Create<
UnitOfWork
>(Behavior.CallOriginal);
//Mock private method
Mock.NonPublic.Arrange(fooUnitOfWork, "RaiseValidationError", dbEntityValidationException).DoNothing().MustBeCalled();
//Execute method to test
fooUnitOfWork.SaveChanges();Mock.Arrange(() => fooUnitOfWork.SaveChanges()).Throws(new DbEntityValidationException());
//Make sure that the RaiseDBValidationError is called
Mock.Assert(fooUnitOfWork);