An ObjectResult that when executed will produce a Not Found (404) response.
Inheritance: Microsoft.AspNetCore.Mvc.ObjectResult
Beispiel #1
0
        public void HttpNotFoundObjectResult_InitializesStatusCode()
        {
            // Arrange & act
            var notFound = new NotFoundObjectResult(null);

            // Assert
            Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
        }
Beispiel #2
0
        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));
        }
Beispiel #4
0
        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);
        }