public void ShouldErrorWhenNumberIsTooBigAndCheckDivideByParameter() { var calc = new BasicCalculator(); Assert.That(() => calc.Divide(number: 101, divideBy: 2), Throws.TypeOf <ArgumentOutOfRangeException>() .With.Matches <ArgumentOutOfRangeException>(x => x.ParamName == "divideBy")); }
public void ShouldNotAllowDividingByZero() { var calc = new BasicCalculator(); //first parameter = code we expect to throw the exception //setcond parameter = exception which is thrown Assert.That(() => calc.Divide(number: 100, divideBy: 0), Throws.Exception); //The following does not work //Action action = () => { calc.Divide(number: 100, divideBy: 0); }; //Assert.That(action, Throws.Exception); //Does not work //Action action = () => calc.Divide(number: 100, divideBy: 0); //Assert.That(action, Throws.Exception); //works fine TestDelegate dlg = () => calc.Divide(number: 100, divideBy: 0); Assert.That(dlg, Throws.Exception); //Explicit exception type Assert.That(() => calc.Divide(number: 100, divideBy: 0), Throws.TypeOf <DivideByZeroException>()); }
public void AfterEachTest() { Console.WriteLine($"Executed After the test"); sut = null; }
public void BeforeEachTest() { Console.WriteLine($"Executed Before the test"); sut = new BasicCalculator(); }
public void ShouldErrorWhenNumberIsTooBig() { var calc = new BasicCalculator(); Assert.That(() => calc.Divide(number: 101, divideBy: 2), Throws.TypeOf <ArgumentOutOfRangeException>()); }