I've had this problem for a while now, and I'm not sure if I'm doing it right.
I have a BL that should be raising an exception. But I want to make sure that it's calling the DAL to verify the values. When I write the actual code
without calling the DAL, but still raise an exception, the test passes. I was expecting that the test would fail, because [VerifyMocks] should tell me that ChargeCodeDal constructor has one more expected call, as well as the call to Retrieve.
[TestMethod]
[VerifyMocks]
[ExpectedException(typeof(ValidationException))]
public void blShouldRaiseException()
{
ChargeCodeType chargeCodeType = new ChargeCodeType();
chargeCodeType.Id = "1";
ChargeCodeTypeCollection chargeCodesFromDatabase = new ChargeCodeTypeCollection();
chargeCodesFromDatabase.Add(chargeCodeType);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// retrieve the charge code from database
// if this isn't implemented in the code, this should cause
// the test to fail because of [VerifyMocks], but doesn't
ChargeCodeDal dataAccessLayer = new ChargeCodeDal();
dataAccessLayer.RetrieveRateChargeCodes(chargeCodeType);
recorder.Return(chargeCodesFromDatabase);
}
ChargeCodeBL testObj = new ChargeCodeBL();
try
{
testObj.Delete(chargeCodeType, null, null);
}
catch (ValidationException e)
{
Assert.AreEqual("Unable to delete the Charge Code - the Charge Code is in use.", e.Message);
throw;
}
}
public ChargeCodeType Delete(ChargeCodeType obj, Database database, DbTransaction transaction)
{
throw new ValidationException(
"Unable to delete the Charge Code - the Charge Code is in use.");
}
________
Xtz 750