[Fixes #4085] Controller helper inconsistency: HttpNotFound(), Ok()

This commit is contained in:
Kiran Challa 2016-02-16 08:29:19 -08:00
parent 75c05be2f7
commit fd3ee49987
38 changed files with 123 additions and 123 deletions

View File

@ -22,14 +22,14 @@ namespace JsonPatchSample.Web.Controllers
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return new ObjectResult(customer); return new ObjectResult(customer);
} }
else else
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
} }
@ -44,7 +44,7 @@ namespace JsonPatchSample.Web.Controllers
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return new ObjectResult(customer); return new ObjectResult(customer);

View File

@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
/// <summary> /// <summary>
/// A <see cref="HttpStatusCodeResult"/> that when /// A <see cref="StatusCodeResult"/> that when
/// executed will produce a Bad Request (400) response. /// executed will produce a Bad Request (400) response.
/// </summary> /// </summary>
public class BadRequestResult : HttpStatusCodeResult public class BadRequestResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Creates a new <see cref="BadRequestResult"/> instance. /// Creates a new <see cref="BadRequestResult"/> instance.

View File

@ -289,22 +289,22 @@ namespace Microsoft.AspNetCore.Mvc
} }
/// <summary> /// <summary>
/// Creates a <see cref="HttpOkResult"/> object that produces an empty OK (200) response. /// Creates a <see cref="OkResult"/> object that produces an empty OK (200) response.
/// </summary> /// </summary>
/// <returns>The created <see cref="HttpOkResult"/> for the response.</returns> /// <returns>The created <see cref="OkResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual HttpOkResult Ok() public virtual OkResult Ok()
{ {
return new HttpOkResult(); return new OkResult();
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpOkObjectResult"/> object that produces an OK (200) response. /// Creates an <see cref="OkObjectResult"/> object that produces an OK (200) response.
/// </summary> /// </summary>
/// <param name="value">The content value to format in the entity body.</param> /// <param name="value">The content value to format in the entity body.</param>
/// <returns>The created <see cref="HttpOkObjectResult"/> for the response.</returns> /// <returns>The created <see cref="OkObjectResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual HttpOkObjectResult Ok(object value) public virtual OkObjectResult Ok(object value)
{ {
var disposableValue = value as IDisposable; var disposableValue = value as IDisposable;
if (disposableValue != null) if (disposableValue != null)
@ -312,7 +312,7 @@ namespace Microsoft.AspNetCore.Mvc
Response.RegisterForDispose(disposableValue); Response.RegisterForDispose(disposableValue);
} }
return new HttpOkObjectResult(value); return new OkObjectResult(value);
} }
/// <summary> /// <summary>
@ -701,31 +701,31 @@ namespace Microsoft.AspNetCore.Mvc
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpUnauthorizedResult"/> that produces an Unauthorized (401) response. /// Creates an <see cref="UnauthorizedResult"/> that produces an Unauthorized (401) response.
/// </summary> /// </summary>
/// <returns>The created <see cref="HttpUnauthorizedResult"/> for the response.</returns> /// <returns>The created <see cref="UnauthorizedResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual HttpUnauthorizedResult Unauthorized() public virtual UnauthorizedResult Unauthorized()
{ {
return new HttpUnauthorizedResult(); return new UnauthorizedResult();
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpNotFoundResult"/> that produces a Not Found (404) response. /// Creates an <see cref="NotFoundResult"/> that produces a Not Found (404) response.
/// </summary> /// </summary>
/// <returns>The created <see cref="HttpNotFoundResult"/> for the response.</returns> /// <returns>The created <see cref="NotFoundResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual HttpNotFoundResult NotFound() public virtual NotFoundResult NotFound()
{ {
return new HttpNotFoundResult(); return new NotFoundResult();
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpNotFoundObjectResult"/> that produces a Not Found (404) response. /// Creates an <see cref="NotFoundObjectResult"/> that produces a Not Found (404) response.
/// </summary> /// </summary>
/// <returns>The created <see cref="HttpNotFoundObjectResult"/> for the response.</returns> /// <returns>The created <see cref="NotFoundObjectResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual HttpNotFoundObjectResult NotFound(object value) public virtual NotFoundObjectResult NotFound(object value)
{ {
var disposableValue = value as IDisposable; var disposableValue = value as IDisposable;
if (disposableValue != null) if (disposableValue != null)
@ -733,7 +733,7 @@ namespace Microsoft.AspNetCore.Mvc
Response.RegisterForDispose(disposableValue); Response.RegisterForDispose(disposableValue);
} }
return new HttpNotFoundObjectResult(value); return new NotFoundObjectResult(value);
} }
/// <summary> /// <summary>

View File

@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
throw new ArgumentNullException(nameof(context)); throw new ArgumentNullException(nameof(context));
} }
context.Result = new HttpUnauthorizedResult(); context.Result = new UnauthorizedResult();
} }
} }
} }

View File

@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
if (contentType == null) if (contentType == null)
{ {
// no contentType exists for the format, return 404 // no contentType exists for the format, return 404
context.Result = new HttpNotFoundResult(); context.Result = new NotFoundResult();
return; return;
} }
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
// type than requested e.g. OK if "text/*" requested and action supports "text/plain". // type than requested e.g. OK if "text/*" requested and action supports "text/plain".
if (!IsSuperSetOfAnySupportedMediaType(contentType, supportedMediaTypes)) if (!IsSuperSetOfAnySupportedMediaType(contentType, supportedMediaTypes))
{ {
context.Result = new HttpNotFoundResult(); context.Result = new NotFoundResult();
} }
} }
} }

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
public class NoContentResult : HttpStatusCodeResult public class NoContentResult : StatusCodeResult
{ {
public NoContentResult() public NoContentResult()
: base(StatusCodes.Status204NoContent) : base(StatusCodes.Status204NoContent)

View File

@ -8,13 +8,13 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// An <see cref="ObjectResult"/> that when executed will produce a Not Found (404) response. /// An <see cref="ObjectResult"/> that when executed will produce a Not Found (404) response.
/// </summary> /// </summary>
public class HttpNotFoundObjectResult : ObjectResult public class NotFoundObjectResult : ObjectResult
{ {
/// <summary> /// <summary>
/// Creates a new <see cref="HttpNotFoundObjectResult"/> instance. /// Creates a new <see cref="NotFoundObjectResult"/> instance.
/// </summary> /// </summary>
/// <param name="value">The value to format in the entity body.</param> /// <param name="value">The value to format in the entity body.</param>
public HttpNotFoundObjectResult(object value) public NotFoundObjectResult(object value)
: base(value) : base(value)
{ {
StatusCode = StatusCodes.Status404NotFound; StatusCode = StatusCodes.Status404NotFound;

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
/// <summary> /// <summary>
/// Represents an <see cref="HttpStatusCodeResult"/> that when /// Represents an <see cref="StatusCodeResult"/> that when
/// executed will produce a Not Found (404) response. /// executed will produce a Not Found (404) response.
/// </summary> /// </summary>
public class HttpNotFoundResult : HttpStatusCodeResult public class NotFoundResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Creates a new <see cref="HttpNotFoundResult"/> instance. /// Creates a new <see cref="NotFoundResult"/> instance.
/// </summary> /// </summary>
public HttpNotFoundResult() : base(StatusCodes.Status404NotFound) public NotFoundResult() : base(StatusCodes.Status404NotFound)
{ {
} }
} }

View File

@ -9,13 +9,13 @@ namespace Microsoft.AspNetCore.Mvc
/// An <see cref="ObjectResult"/> that when executed performs content negotiation, formats the entity body, and /// An <see cref="ObjectResult"/> that when executed performs content negotiation, formats the entity body, and
/// will produce a <see cref="StatusCodes.Status200OK"/> response if negotiation and formatting succeed. /// will produce a <see cref="StatusCodes.Status200OK"/> response if negotiation and formatting succeed.
/// </summary> /// </summary>
public class HttpOkObjectResult : ObjectResult public class OkObjectResult : ObjectResult
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HttpOkObjectResult"/> class. /// Initializes a new instance of the <see cref="OkObjectResult"/> class.
/// </summary> /// </summary>
/// <param name="value">The content to format into the entity body.</param> /// <param name="value">The content to format into the entity body.</param>
public HttpOkObjectResult(object value) public OkObjectResult(object value)
: base(value) : base(value)
{ {
StatusCode = StatusCodes.Status200OK; StatusCode = StatusCodes.Status200OK;

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
/// <summary> /// <summary>
/// An <see cref="HttpStatusCodeResult"/> that when executed will produce an empty /// An <see cref="StatusCodeResult"/> that when executed will produce an empty
/// <see cref="StatusCodes.Status200OK"/> response. /// <see cref="StatusCodes.Status200OK"/> response.
/// </summary> /// </summary>
public class HttpOkResult : HttpStatusCodeResult public class OkResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HttpOkResult"/> class. /// Initializes a new instance of the <see cref="OkResult"/> class.
/// </summary> /// </summary>
public HttpOkResult() public OkResult()
: base(StatusCodes.Status200OK) : base(StatusCodes.Status200OK)
{ {
} }

View File

@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Mvc
// body correctly. // body correctly.
if (!string.Equals(filterContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase)) if (!string.Equals(filterContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
{ {
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status403Forbidden); filterContext.Result = new StatusCodeResult(StatusCodes.Status403Forbidden);
} }
else else
{ {

View File

@ -12,14 +12,14 @@ namespace Microsoft.AspNetCore.Mvc
/// Represents an <see cref="ActionResult"/> that when executed will /// Represents an <see cref="ActionResult"/> that when executed will
/// produce an HTTP response with the given response status code. /// produce an HTTP response with the given response status code.
/// </summary> /// </summary>
public class HttpStatusCodeResult : ActionResult public class StatusCodeResult : ActionResult
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HttpStatusCodeResult"/> class /// Initializes a new instance of the <see cref="StatusCodeResult"/> class
/// with the given <paramref name="statusCode"/>. /// with the given <paramref name="statusCode"/>.
/// </summary> /// </summary>
/// <param name="statusCode">The HTTP status code of the response.</param> /// <param name="statusCode">The HTTP status code of the response.</param>
public HttpStatusCodeResult(int statusCode) public StatusCodeResult(int statusCode)
{ {
StatusCode = statusCode; StatusCode = statusCode;
} }
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc
} }
var factory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>(); var factory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();
var logger = factory.CreateLogger<HttpStatusCodeResult>(); var logger = factory.CreateLogger<StatusCodeResult>();
logger.HttpStatusCodeResultExecuting(StatusCode); logger.HttpStatusCodeResultExecuting(StatusCode);

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
/// <summary> /// <summary>
/// Represents an <see cref="HttpUnauthorizedResult"/> that when /// Represents an <see cref="UnauthorizedResult"/> that when
/// executed will produce an Unauthorized (401) response. /// executed will produce an Unauthorized (401) response.
/// </summary> /// </summary>
public class HttpUnauthorizedResult : HttpStatusCodeResult public class UnauthorizedResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Creates a new <see cref="HttpUnauthorizedResult"/> instance. /// Creates a new <see cref="UnauthorizedResult"/> instance.
/// </summary> /// </summary>
public HttpUnauthorizedResult() : base(StatusCodes.Status401Unauthorized) public UnauthorizedResult() : base(StatusCodes.Status401Unauthorized)
{ {
} }
} }

View File

@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
{ {
/// <summary> /// <summary>
/// A <see cref="HttpStatusCodeResult"/> that when /// A <see cref="StatusCodeResult"/> that when
/// executed will produce a UnsupportedMediaType (415) response. /// executed will produce a UnsupportedMediaType (415) response.
/// </summary> /// </summary>
public class UnsupportedMediaTypeResult : HttpStatusCodeResult public class UnsupportedMediaTypeResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Creates a new instance of <see cref="UnsupportedMediaTypeResult"/>. /// Creates a new instance of <see cref="UnsupportedMediaTypeResult"/>.

View File

@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
{ {
// If this was a preflight, there is no need to run anything else. // If this was a preflight, there is no need to run anything else.
// Also the response is always 200 so that anyone after mvc can handle the pre flight request. // Also the response is always 200 so that anyone after mvc can handle the pre flight request.
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK); context.Result = new StatusCodeResult(StatusCodes.Status200OK);
} }
// Continue with other filters and action. // Continue with other filters and action.

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
!StringValues.IsNullOrEmpty(accessControlRequestMethod)) !StringValues.IsNullOrEmpty(accessControlRequestMethod))
{ {
// Short circuit if the request is preflight as that should not result in action execution. // Short circuit if the request is preflight as that should not result in action execution.
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK); context.Result = new StatusCodeResult(StatusCodes.Status200OK);
} }
// Let the action be executed. // Let the action be executed.

View File

@ -415,35 +415,35 @@ namespace System.Web.Http
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpNotFoundResult"/> (404 Not Found). /// Creates an <see cref="NotFoundResult"/> (404 Not Found).
/// </summary> /// </summary>
/// <returns>A <see cref="HttpNotFoundResult"/>.</returns> /// <returns>A <see cref="NotFoundResult"/>.</returns>
[NonAction] [NonAction]
public virtual HttpNotFoundResult NotFound() public virtual NotFoundResult NotFound()
{ {
return new HttpNotFoundResult(); return new NotFoundResult();
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpOkResult"/> (200 OK). /// Creates an <see cref="OkResult"/> (200 OK).
/// </summary> /// </summary>
/// <returns>An <see cref="HttpOkResult"/>.</returns> /// <returns>An <see cref="OkResult"/>.</returns>
[NonAction] [NonAction]
public virtual HttpOkResult Ok() public virtual OkResult Ok()
{ {
return new HttpOkResult(); return new OkResult();
} }
/// <summary> /// <summary>
/// Creates an <see cref="HttpOkObjectResult"/> (200 OK) with the specified values. /// Creates an <see cref="OkObjectResult"/> (200 OK) with the specified values.
/// </summary> /// </summary>
/// <typeparam name="T">The type of content in the entity body.</typeparam> /// <typeparam name="T">The type of content in the entity body.</typeparam>
/// <param name="content">The content value to negotiate and format in the entity body.</param> /// <param name="content">The content value to negotiate and format in the entity body.</param>
/// <returns>An <see cref="HttpOkObjectResult"/> with the specified values.</returns> /// <returns>An <see cref="OkObjectResult"/> with the specified values.</returns>
[NonAction] [NonAction]
public virtual HttpOkObjectResult Ok<T>(T content) public virtual OkObjectResult Ok<T>(T content)
{ {
return new HttpOkObjectResult(content); return new OkObjectResult(content);
} }
/// <summary> /// <summary>
@ -531,14 +531,14 @@ namespace System.Web.Http
} }
/// <summary> /// <summary>
/// Creates a <see cref="HttpStatusCodeResult"/> with the specified status code. /// Creates a <see cref="StatusCodeResult"/> with the specified status code.
/// </summary> /// </summary>
/// <param name="status">The HTTP status code for the response message</param> /// <param name="status">The HTTP status code for the response message</param>
/// <returns>A <see cref="HttpStatusCodeResult"/> with the specified status code.</returns> /// <returns>A <see cref="StatusCodeResult"/> with the specified status code.</returns>
[NonAction] [NonAction]
public virtual HttpStatusCodeResult StatusCode(HttpStatusCode status) public virtual StatusCodeResult StatusCode(HttpStatusCode status)
{ {
return new HttpStatusCodeResult((int)status); return new StatusCodeResult((int)status);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -9,7 +9,7 @@ namespace System.Web.Http
/// <summary> /// <summary>
/// An action result that returns an empty <see cref="StatusCodes.Status409Conflict"/> response. /// An action result that returns an empty <see cref="StatusCodes.Status409Conflict"/> response.
/// </summary> /// </summary>
public class ConflictResult : HttpStatusCodeResult public class ConflictResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ConflictResult"/> class. /// Initializes a new instance of the <see cref="ConflictResult"/> class.

View File

@ -9,7 +9,7 @@ namespace System.Web.Http
/// <summary> /// <summary>
/// An action result that returns an empty <see cref="StatusCodes.Status500InternalServerError"/> response. /// An action result that returns an empty <see cref="StatusCodes.Status500InternalServerError"/> response.
/// </summary> /// </summary>
public class InternalServerErrorResult : HttpStatusCodeResult public class InternalServerErrorResult : StatusCodeResult
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="InternalServerErrorResult"/> class. /// Initializes a new instance of the <see cref="InternalServerErrorResult"/> class.

View File

@ -765,10 +765,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController(); var controller = new TestableController();
// Act // Act
var result = controller.HttpUnauthorized(); var result = controller.Unauthorized();
// Assert // Assert
Assert.IsType<HttpUnauthorizedResult>(result); Assert.IsType<UnauthorizedResult>(result);
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode); Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
} }
@ -779,10 +779,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController(); var controller = new TestableController();
// Act // Act
var result = controller.HttpNotFound(); var result = controller.NotFound();
// Assert // Assert
Assert.IsType<HttpNotFoundResult>(result); Assert.IsType<NotFoundResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
} }
@ -793,10 +793,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController(); var controller = new TestableController();
// Act // Act
var result = controller.HttpNotFound("Test Content"); var result = controller.NotFound("Test Content");
// Assert // Assert
Assert.IsType<HttpNotFoundObjectResult>(result); Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
Assert.Equal("Test Content", result.Value); Assert.Equal("Test Content", result.Value);
} }
@ -814,10 +814,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var input = new DisposableObject(); var input = new DisposableObject();
// Act // Act
var result = controller.HttpNotFound(input); var result = controller.NotFound(input);
// Assert // Assert
Assert.IsType<HttpNotFoundObjectResult>(result); Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
Assert.Same(input, result.Value); Assert.Same(input, result.Value);
mockHttpContext.Verify( mockHttpContext.Verify(
@ -835,7 +835,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var result = controller.Ok(); var result = controller.Ok();
// Assert // Assert
Assert.IsType<HttpOkResult>(result); Assert.IsType<OkResult>(result);
Assert.Equal(StatusCodes.Status200OK, result.StatusCode); Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
} }
@ -855,7 +855,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var result = controller.Ok(input); var result = controller.Ok(input);
// Assert // Assert
Assert.IsType<HttpOkObjectResult>(result); Assert.IsType<OkObjectResult>(result);
Assert.Equal(StatusCodes.Status200OK, result.StatusCode); Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
Assert.Same(input, result.Value); Assert.Same(input, result.Value);
mockHttpContext.Verify( mockHttpContext.Verify(
@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController(); var controller = new TestableController();
// Act // Act
var result = controller.HttpBadRequest(); var result = controller.BadRequest();
// Assert // Assert
Assert.IsType<BadRequestResult>(result); Assert.IsType<BadRequestResult>(result);
@ -885,7 +885,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var obj = new object(); var obj = new object();
// Act // Act
var result = controller.HttpBadRequest(obj); var result = controller.BadRequest(obj);
// Assert // Assert
Assert.IsType<BadRequestObjectResult>(result); Assert.IsType<BadRequestObjectResult>(result);
@ -906,7 +906,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var input = new DisposableObject(); var input = new DisposableObject();
// Act // Act
var result = controller.HttpBadRequest(input); var result = controller.BadRequest(input);
// Assert // Assert
Assert.IsType<BadRequestObjectResult>(result); Assert.IsType<BadRequestObjectResult>(result);
@ -924,7 +924,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController(); var controller = new TestableController();
// Act // Act
var result = controller.HttpBadRequest(new ModelStateDictionary()); var result = controller.BadRequest(new ModelStateDictionary());
// Assert // Assert
Assert.IsType<BadRequestObjectResult>(result); Assert.IsType<BadRequestObjectResult>(result);

View File

@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
// Assert // Assert
var actionResult = resourceExecutingContext.Result; var actionResult = resourceExecutingContext.Result;
Assert.IsType<HttpNotFoundResult>(actionResult); Assert.IsType<NotFoundResult>(actionResult);
} }
[Fact] [Fact]
@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
// Assert // Assert
var actionResult = resourceExecutingContext.Result; var actionResult = resourceExecutingContext.Result;
Assert.IsType<HttpNotFoundResult>(actionResult); Assert.IsType<NotFoundResult>(actionResult);
} }
[Theory] [Theory]
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
filter.OnResourceExecuting(resourceExecutingContext); filter.OnResourceExecuting(resourceExecutingContext);
// Assert // Assert
var result = Assert.IsType<HttpNotFoundResult>(resourceExecutingContext.Result); var result = Assert.IsType<NotFoundResult>(resourceExecutingContext.Result);
} }
[Theory] [Theory]

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpNotFoundObjectResult_InitializesStatusCode() public void HttpNotFoundObjectResult_InitializesStatusCode()
{ {
// Arrange & act // Arrange & act
var notFound = new HttpNotFoundObjectResult(null); var notFound = new NotFoundObjectResult(null);
// Assert // Assert
Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpNotFoundObjectResult_InitializesStatusCodeAndResponseContent() public void HttpNotFoundObjectResult_InitializesStatusCodeAndResponseContent()
{ {
// Arrange & act // Arrange & act
var notFound = new HttpNotFoundObjectResult("Test Content"); var notFound = new NotFoundObjectResult("Test Content");
// Assert // Assert
Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc
HttpContext = httpContext, HttpContext = httpContext,
}; };
var result = new HttpNotFoundObjectResult("Test Content"); var result = new NotFoundObjectResult("Test Content");
// Act // Act
await result.ExecuteResultAsync(actionContext); await result.ExecuteResultAsync(actionContext);

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpNotFoundResult_InitializesStatusCode() public void HttpNotFoundResult_InitializesStatusCode()
{ {
// Arrange & act // Arrange & act
var notFound = new HttpNotFoundResult(); var notFound = new NotFoundResult();
// Assert // Assert
Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpOkObjectResult_InitializesStatusCodeAndValue(object value) public void HttpOkObjectResult_InitializesStatusCodeAndValue(object value)
{ {
// Arrange & Act // Arrange & Act
var result = new HttpOkObjectResult(value); var result = new OkObjectResult(value);
// Assert // Assert
Assert.Equal(StatusCodes.Status200OK, result.StatusCode); Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc
public async Task HttpOkObjectResult_SetsStatusCode(object value) public async Task HttpOkObjectResult_SetsStatusCode(object value)
{ {
// Arrange // Arrange
var result = new HttpOkObjectResult(value); var result = new OkObjectResult(value);
var httpContext = new DefaultHttpContext var httpContext = new DefaultHttpContext
{ {

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpOkResult_InitializesStatusCode() public void HttpOkResult_InitializesStatusCode()
{ {
// Arrange & Act // Arrange & Act
var result = new HttpOkResult(); var result = new OkResult();
// Assert // Assert
Assert.Equal(StatusCodes.Status200OK, result.StatusCode); Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc
httpContext.RequestServices = CreateServices().BuildServiceProvider(); httpContext.RequestServices = CreateServices().BuildServiceProvider();
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
var result = new HttpOkResult(); var result = new OkResult();
// Act // Act
await result.ExecuteResultAsync(context); await result.ExecuteResultAsync(context);

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpStatusCodeResult_ExecuteResultSetsResponseStatusCode() public void HttpStatusCodeResult_ExecuteResultSetsResponseStatusCode()
{ {
// Arrange // Arrange
var result = new HttpStatusCodeResult(StatusCodes.Status404NotFound); var result = new StatusCodeResult(StatusCodes.Status404NotFound);
var httpContext = GetHttpContext(); var httpContext = GetHttpContext();
var routeData = new RouteData(); var routeData = new RouteData();

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc
public void HttpUnauthorizedResult_InitializesStatusCode() public void HttpUnauthorizedResult_InitializesStatusCode()
{ {
// Arrange & act // Arrange & act
var result = new HttpUnauthorizedResult(); var result = new UnauthorizedResult();
// Assert // Assert
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode); Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);

View File

@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var authorizationContext = GetAuthorizationContext(services => var authorizationContext = GetAuthorizationContext(services =>
services.AddSingleton(authorizationService.Object)); services.AddSingleton(authorizationService.Object));
authorizationContext.Result = new HttpUnauthorizedResult(); authorizationContext.Result = new UnauthorizedResult();
// Act // Act
await authorizeFilter.OnAuthorizationAsync(authorizationContext); await authorizeFilter.OnAuthorizationAsync(authorizationContext);

View File

@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Mvc
// Assert // Assert
Assert.NotNull(authContext.Result); Assert.NotNull(authContext.Result);
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result); var result = Assert.IsType<StatusCodeResult>(authContext.Result);
Assert.Equal(StatusCodes.Status403Forbidden, result.StatusCode); Assert.Equal(StatusCodes.Status403Forbidden, result.StatusCode);
} }
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc
attr.OnAuthorization(authContext); attr.OnAuthorization(authContext);
// Assert // Assert
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result); var result = Assert.IsType<StatusCodeResult>(authContext.Result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
} }
@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Mvc
{ {
protected override void HandleNonHttpsRequest(AuthorizationFilterContext filterContext) protected override void HandleNonHttpsRequest(AuthorizationFilterContext filterContext)
{ {
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status404NotFound); filterContext.Result = new StatusCodeResult(StatusCodes.Status404NotFound);
} }
} }

View File

@ -242,7 +242,7 @@ namespace Microsoft.AspNetCore.Mvc
// Assert // Assert
Assert.NotNull(result); Assert.NotNull(result);
var httpNotFoundResult = Assert.IsType<HttpNotFoundResult>(result); var httpNotFoundResult = Assert.IsType<NotFoundResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundResult.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundResult.StatusCode);
} }
@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Mvc
// Assert // Assert
Assert.NotNull(result); Assert.NotNull(result);
var httpNotFoundObjectResult = Assert.IsType<HttpNotFoundObjectResult>(result); var httpNotFoundObjectResult = Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundObjectResult.StatusCode); Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundObjectResult.StatusCode);
Assert.Equal("Test Content", httpNotFoundObjectResult.Value); Assert.Equal("Test Content", httpNotFoundObjectResult.Value);
} }
@ -688,22 +688,22 @@ namespace Microsoft.AspNetCore.Mvc
public IActionResult HttpBadRequest_Action() public IActionResult HttpBadRequest_Action()
{ {
return HttpBadRequest(); return BadRequest();
} }
public IActionResult HttpBadRequestObject_Action(object error) public IActionResult HttpBadRequestObject_Action(object error)
{ {
return HttpBadRequest(error); return BadRequest(error);
} }
public IActionResult HttpNotFound_Action() public IActionResult HttpNotFound_Action()
{ {
return HttpNotFound(); return NotFound();
} }
public IActionResult HttpNotFoundObject_Action(object value) public IActionResult HttpNotFoundObject_Action(object value)
{ {
return HttpNotFound(value); return NotFound(value);
} }
} }

View File

@ -278,7 +278,7 @@ namespace System.Web.Http
var result = controller.NotFound(); var result = controller.NotFound();
// Assert // Assert
Assert.Equal(404, Assert.IsType<HttpNotFoundResult>(result).StatusCode); Assert.Equal(404, Assert.IsType<NotFoundResult>(result).StatusCode);
} }
[Fact] [Fact]
@ -291,7 +291,7 @@ namespace System.Web.Http
var result = controller.Ok(); var result = controller.Ok();
// Assert // Assert
Assert.Equal(200, Assert.IsType<HttpOkResult>(result).StatusCode); Assert.Equal(200, Assert.IsType<OkResult>(result).StatusCode);
} }
@ -306,7 +306,7 @@ namespace System.Web.Http
var result = controller.Ok(product); var result = controller.Ok(product);
// Assert // Assert
var okResult = Assert.IsType<HttpOkObjectResult>(result); var okResult = Assert.IsType<OkObjectResult>(result);
Assert.Same(product, okResult.Value); Assert.Same(product, okResult.Value);
} }
@ -400,7 +400,7 @@ namespace System.Web.Http
var result = controller.StatusCode(HttpStatusCode.ExpectationFailed); var result = controller.StatusCode(HttpStatusCode.ExpectationFailed);
// Assert // Assert
Assert.Equal(StatusCodes.Status417ExpectationFailed, Assert.IsType<HttpStatusCodeResult>(result).StatusCode); Assert.Equal(StatusCodes.Status417ExpectationFailed, Assert.IsType<StatusCodeResult>(result).StatusCode);
} }
private class Product private class Product

View File

@ -45,7 +45,7 @@ namespace BasicWebSite.Controllers
public IActionResult NoContentResult() public IActionResult NoContentResult()
{ {
return new HttpStatusCodeResult(StatusCodes.Status204NoContent); return new StatusCodeResult(StatusCodes.Status204NoContent);
} }
[AcceptVerbs("GET", "POST")] [AcceptVerbs("GET", "POST")]

View File

@ -20,7 +20,7 @@ namespace BasicWebSite
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return Ok(person); return Ok(person);
@ -31,7 +31,7 @@ namespace BasicWebSite
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return Ok(person); return Ok(person);

View File

@ -13,7 +13,7 @@ namespace FormatterWebSite.Controllers
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return new HttpStatusCodeResult(StatusCodes.Status400BadRequest); return new StatusCodeResult(StatusCodes.Status400BadRequest);
} }
return Content(test); return Content(test);

View File

@ -33,7 +33,7 @@ namespace FormatterWebSite.Controllers
{ {
if(!ModelState.IsValid) if(!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return new ObjectResult(employee); return new ObjectResult(employee);

View File

@ -13,7 +13,7 @@ namespace FormatterWebSite.Controllers
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return Content("Hello World!"); return Content("Hello World!");

View File

@ -25,7 +25,7 @@ namespace WebApiCompatShimWebSite
}) })
}); });
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK); context.Result = new StatusCodeResult(StatusCodes.Status200OK);
} }
} }
} }

View File

@ -40,7 +40,7 @@ namespace XmlFormattersWebSite.Controllers
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
return HttpBadRequest(ModelState); return BadRequest(ModelState);
} }
return Content("Hello World!"); return Content("Hello World!");