Return to Snippet

Revision: 66796
at July 4, 2014 00:01 by heathbo


Initial Code
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void PricingService_CalculateProvisionalPrice_NullReference_Test()
{
     // Action
     target.CalculateProvisionalPrice(null);

     Assert.Fail("Should have thrown ArgumentNullException");
}

Initial URL


Initial Description
The ExpectedException section under [TestMethod] is where you tell Moq what type of exception your listening for.  If that exception is thrown, then this test will pass and it will stop running all the code under the target.CalculateProvisionalPrice.

In case the exception isn't thrown, the Assert.Fail will throw an exception alerting you that the ArgumentNullException wasn't thrown.

Initial Title
Moq: test to see if exception is thrown

Initial Tags
c#

Initial Language
C#