public void HttpNotFound_IDisposableObject_RegistersForDispose() { // Arrange var mockHttpContext = new Mock<DefaultHttpContext>(); mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>())); var controller = new TestableController() { ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor()) }; var input = new DisposableObject(); // Act var result = controller.HttpNotFound(input); // Assert Assert.IsType<HttpNotFoundObjectResult>(result); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Same(input, result.Value); mockHttpContext.Verify( x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()), Times.Once()); }
public void HttpNotFound_SetsStatusCode() { // Arrange var controller = new TestableController(); // Act var result = controller.HttpNotFound(); // Assert Assert.IsType<HttpNotFoundResult>(result); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); }
public void HttpNotFound_SetsStatusCodeAndResponseContent() { // Arrange var controller = new TestableController(); // Act var result = controller.HttpNotFound("Test Content"); // Assert Assert.IsType<HttpNotFoundObjectResult>(result); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Equal("Test Content", result.Value); }
public void HttpNotFound_IDisposableObject_RegistersForDispose() { // Arrange var mockHttpContext = new Mock<HttpContext>(); mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>())); var controller = new TestableController(); controller.ControllerContext.HttpContext = mockHttpContext.Object; var input = new DisposableObject(); // Act var result = controller.HttpNotFound(input); // Assert Assert.IsType<HttpNotFoundObjectResult>(result); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Same(input, result.Value); mockHttpContext.Verify( x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()), Times.Once()); }