public void NotFound_Returns_404_StatusCode() { // Arange int expectedCode = 404; var mockHttpContext = new Mock<HttpContextBase>(); var response = new Mock<HttpResponseBase>(); mockHttpContext.SetupGet(x => x.Response).Returns(response.Object); StaticController staticController = new StaticController() { ControllerContext = new ControllerContext { HttpContext = mockHttpContext.Object } }; // Act var result = staticController.NotFound() as ViewResult; // Asert Assert.IsNotNull(result, "Expected ViewResult to be returned"); response.VerifySet(x => x.StatusCode = expectedCode, Times.Once()); }
public void NotFound_Returns_Missing_ViewResult() { // Arange string expectedViewName = "Missing"; var mockHttpContext = new Mock<HttpContextBase>(); var response = new Mock<HttpResponseBase>(); mockHttpContext.SetupGet(x => x.Response).Returns(response.Object); StaticController staticController = new StaticController() { ControllerContext = new ControllerContext { HttpContext = mockHttpContext.Object } }; // Act var result = staticController.NotFound() as ViewResult; // Asert Assert.IsNotNull(result, "Expected ViewResult to be returned"); Assert.AreEqual(expectedViewName, result.ViewName); }