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

            // Assert
            Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
        }
예제 #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));
        }
예제 #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);
        }