public void HttpNotFoundObjectResult_InitializesStatusCode() { // Arrange & act var notFound = new NotFoundObjectResult(null); // Assert Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode); }
public void HttpNotFoundObjectResult_InitializesStatusCodeAndResponseContent() { // Arrange & act var notFound = new NotFoundObjectResult("Test Content"); // Assert Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode); Assert.Equal("Test Content", notFound.Value); }
/// <summary> /// Creates an <see cref="HttpException" /> that produces a Not Found (404) response. /// </summary> /// <param name="response">The HTTP response.</param> /// <param name="error">The error to be returned to the client.</param> public static HttpException NotFound(this HttpResponse response, object error) { var disposable = error as IDisposable; if (disposable != null) { response.RegisterForDispose(disposable); } var result = new NotFoundObjectResult(error); return(new HttpException(result)); }
public async Task HttpNotFoundObjectResult_ExecuteSuccessful() { // Arrange var httpContext = GetHttpContext(); var actionContext = new ActionContext() { HttpContext = httpContext, }; var result = new NotFoundObjectResult("Test Content"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode); }