public void CalcAValue_ThrowsDivideByZeroException()
        {
            //System.Diagnostics.Debugger.Launch();

            // arrange
            var mock = new Mock<ICalcEngine>();
            mock.Setup(x => x.Calc(It.IsAny<int>())).Throws<DivideByZeroException>();

            var controller = new CalcController(mock.Object);

            // act and assert
            Assert.Throws<DivideByZeroException>(() => { controller.CalcAValue(int.MinValue); });
        }
        public void CalcBValue_ReturnsOkNegotiatedContentResult()
        {
            //System.Diagnostics.Debugger.Launch();

            // arrange
            var mock = new Mock<ICalcEngine>();
            mock.Setup(x => x.Calc(It.IsInRange<int>(1, int.MaxValue, Range.Inclusive))).Returns<int>(v => 10 % v);

            var controller = new CalcController(mock.Object);

            // act
            IHttpActionResult actionResult = controller.CalcBValue(10);

            //  assert
            Assert.IsType<OkNegotiatedContentResult<int>>(actionResult);
        }
        public void CalcBValue_ReturnsExceptionResult()
        {
            //System.Diagnostics.Debugger.Launch();

            // arrange
            var mock = new Mock<ICalcEngine>();
            mock.Setup(x => x.Calc(It.IsAny<int>())).Throws<DivideByZeroException>();

            var controller = new CalcController(mock.Object);

            // act
            IHttpActionResult actionResult = controller.CalcBValue(int.MinValue);

            // assert
            Assert.IsType<ExceptionResult>(actionResult);
            Assert.IsType<DivideByZeroException>(((ExceptionResult)actionResult).Exception);
        }
        public async void CalcCValue_ReturnsInternalServerErrorWithReasonPhrase()
        {
            //System.Diagnostics.Debugger.Launch();

            // arrange
            var mock = new Mock<ICalcEngine>();
            mock.Setup(x => x.Calc(It.IsAny<int>())).Throws<DivideByZeroException>();

            var controller = new CalcController(mock.Object).ConfigureForGet(int.MinValue);

            // act
            IHttpActionResult actionResult = controller.CalcCValue(int.MinValue);

            // assert
            Assert.IsType<WrappedHttpActionResult>(actionResult);

            HttpResponseMessage response = await actionResult.ExecuteAsync(CancellationToken.None);
            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.Equal("Internal Server Error: Check your calculation!", response.ReasonPhrase);
        }