chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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
asked by brauks (1.6k points)

1 Answer

0 votes
The code you've written here should work fine.

Typemock VerifyException should have been thrown from your test regardless of the fact that you have ExcpetetedException attribute for another exception.

Perhaps you're using an old version of Typemock Isolator?

Please try to upgrade to a newer version and check if the issue still happens
answered by dhelper (11.9k points)
...