Ejemplo n.º 1
0
        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"));
        }
Ejemplo n.º 2
0
        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>());
        }
Ejemplo n.º 3
0
 public void AfterEachTest()
 {
     Console.WriteLine($"Executed After the test");
     sut = null;
 }
Ejemplo n.º 4
0
 public void BeforeEachTest()
 {
     Console.WriteLine($"Executed Before the test");
     sut = new BasicCalculator();
 }
Ejemplo n.º 5
0
        public void ShouldErrorWhenNumberIsTooBig()
        {
            var calc = new BasicCalculator();

            Assert.That(() => calc.Divide(number: 101, divideBy: 2), Throws.TypeOf <ArgumentOutOfRangeException>());
        }