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); }