[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)
{
return HttpBadRequest(ModelState);
return BadRequest(ModelState);
}
return new ObjectResult(customer);
}
else
{
return HttpBadRequest(ModelState);
return BadRequest(ModelState);
}
}
@ -44,7 +44,7 @@ namespace JsonPatchSample.Web.Controllers
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
return BadRequest(ModelState);
}
return new ObjectResult(customer);

View File

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

View File

@ -289,22 +289,22 @@ namespace Microsoft.AspNetCore.Mvc
}
/// <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>
/// <returns>The created <see cref="HttpOkResult"/> for the response.</returns>
/// <returns>The created <see cref="OkResult"/> for the response.</returns>
[NonAction]
public virtual HttpOkResult Ok()
public virtual OkResult Ok()
{
return new HttpOkResult();
return new OkResult();
}
/// <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>
/// <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]
public virtual HttpOkObjectResult Ok(object value)
public virtual OkObjectResult Ok(object value)
{
var disposableValue = value as IDisposable;
if (disposableValue != null)
@ -312,7 +312,7 @@ namespace Microsoft.AspNetCore.Mvc
Response.RegisterForDispose(disposableValue);
}
return new HttpOkObjectResult(value);
return new OkObjectResult(value);
}
/// <summary>
@ -701,31 +701,31 @@ namespace Microsoft.AspNetCore.Mvc
}
/// <summary>
/// Creates an <see cref="HttpUnauthorizedResult"/> that produces an Unauthorized (401) response.
/// Creates an <see cref="UnauthorizedResult"/> that produces an Unauthorized (401) response.
/// </summary>
/// <returns>The created <see cref="HttpUnauthorizedResult"/> for the response.</returns>
/// <returns>The created <see cref="UnauthorizedResult"/> for the response.</returns>
[NonAction]
public virtual HttpUnauthorizedResult Unauthorized()
public virtual UnauthorizedResult Unauthorized()
{
return new HttpUnauthorizedResult();
return new UnauthorizedResult();
}
/// <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>
/// <returns>The created <see cref="HttpNotFoundResult"/> for the response.</returns>
/// <returns>The created <see cref="NotFoundResult"/> for the response.</returns>
[NonAction]
public virtual HttpNotFoundResult NotFound()
public virtual NotFoundResult NotFound()
{
return new HttpNotFoundResult();
return new NotFoundResult();
}
/// <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>
/// <returns>The created <see cref="HttpNotFoundObjectResult"/> for the response.</returns>
/// <returns>The created <see cref="NotFoundObjectResult"/> for the response.</returns>
[NonAction]
public virtual HttpNotFoundObjectResult NotFound(object value)
public virtual NotFoundObjectResult NotFound(object value)
{
var disposableValue = value as IDisposable;
if (disposableValue != null)
@ -733,7 +733,7 @@ namespace Microsoft.AspNetCore.Mvc
Response.RegisterForDispose(disposableValue);
}
return new HttpNotFoundObjectResult(value);
return new NotFoundObjectResult(value);
}
/// <summary>

View File

@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
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)
{
// no contentType exists for the format, return 404
context.Result = new HttpNotFoundResult();
context.Result = new NotFoundResult();
return;
}
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
// type than requested e.g. OK if "text/*" requested and action supports "text/plain".
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
{
public class NoContentResult : HttpStatusCodeResult
public class NoContentResult : StatusCodeResult
{
public NoContentResult()
: base(StatusCodes.Status204NoContent)

View File

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

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// Represents an <see cref="HttpStatusCodeResult"/> that when
/// Represents an <see cref="StatusCodeResult"/> that when
/// executed will produce a Not Found (404) response.
/// </summary>
public class HttpNotFoundResult : HttpStatusCodeResult
public class NotFoundResult : StatusCodeResult
{
/// <summary>
/// Creates a new <see cref="HttpNotFoundResult"/> instance.
/// Creates a new <see cref="NotFoundResult"/> instance.
/// </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
/// will produce a <see cref="StatusCodes.Status200OK"/> response if negotiation and formatting succeed.
/// </summary>
public class HttpOkObjectResult : ObjectResult
public class OkObjectResult : ObjectResult
{
/// <summary>
/// Initializes a new instance of the <see cref="HttpOkObjectResult"/> class.
/// Initializes a new instance of the <see cref="OkObjectResult"/> class.
/// </summary>
/// <param name="value">The content to format into the entity body.</param>
public HttpOkObjectResult(object value)
public OkObjectResult(object value)
: base(value)
{
StatusCode = StatusCodes.Status200OK;

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc
{
/// <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.
/// </summary>
public class HttpOkResult : HttpStatusCodeResult
public class OkResult : StatusCodeResult
{
/// <summary>
/// Initializes a new instance of the <see cref="HttpOkResult"/> class.
/// Initializes a new instance of the <see cref="OkResult"/> class.
/// </summary>
public HttpOkResult()
public OkResult()
: base(StatusCodes.Status200OK)
{
}

View File

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

View File

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

View File

@ -6,15 +6,15 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// Represents an <see cref="HttpUnauthorizedResult"/> that when
/// Represents an <see cref="UnauthorizedResult"/> that when
/// executed will produce an Unauthorized (401) response.
/// </summary>
public class HttpUnauthorizedResult : HttpStatusCodeResult
public class UnauthorizedResult : StatusCodeResult
{
/// <summary>
/// Creates a new <see cref="HttpUnauthorizedResult"/> instance.
/// Creates a new <see cref="UnauthorizedResult"/> instance.
/// </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
{
/// <summary>
/// A <see cref="HttpStatusCodeResult"/> that when
/// A <see cref="StatusCodeResult"/> that when
/// executed will produce a UnsupportedMediaType (415) response.
/// </summary>
public class UnsupportedMediaTypeResult : HttpStatusCodeResult
public class UnsupportedMediaTypeResult : StatusCodeResult
{
/// <summary>
/// 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.
// 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.

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal
!StringValues.IsNullOrEmpty(accessControlRequestMethod))
{
// 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.

View File

@ -415,35 +415,35 @@ namespace System.Web.Http
}
/// <summary>
/// Creates an <see cref="HttpNotFoundResult"/> (404 Not Found).
/// Creates an <see cref="NotFoundResult"/> (404 Not Found).
/// </summary>
/// <returns>A <see cref="HttpNotFoundResult"/>.</returns>
/// <returns>A <see cref="NotFoundResult"/>.</returns>
[NonAction]
public virtual HttpNotFoundResult NotFound()
public virtual NotFoundResult NotFound()
{
return new HttpNotFoundResult();
return new NotFoundResult();
}
/// <summary>
/// Creates an <see cref="HttpOkResult"/> (200 OK).
/// Creates an <see cref="OkResult"/> (200 OK).
/// </summary>
/// <returns>An <see cref="HttpOkResult"/>.</returns>
/// <returns>An <see cref="OkResult"/>.</returns>
[NonAction]
public virtual HttpOkResult Ok()
public virtual OkResult Ok()
{
return new HttpOkResult();
return new OkResult();
}
/// <summary>
/// Creates an <see cref="HttpOkObjectResult"/> (200 OK) with the specified values.
/// Creates an <see cref="OkObjectResult"/> (200 OK) with the specified values.
/// </summary>
/// <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>
/// <returns>An <see cref="HttpOkObjectResult"/> with the specified values.</returns>
/// <returns>An <see cref="OkObjectResult"/> with the specified values.</returns>
[NonAction]
public virtual HttpOkObjectResult Ok<T>(T content)
public virtual OkObjectResult Ok<T>(T content)
{
return new HttpOkObjectResult(content);
return new OkObjectResult(content);
}
/// <summary>
@ -531,14 +531,14 @@ namespace System.Web.Http
}
/// <summary>
/// Creates a <see cref="HttpStatusCodeResult"/> with the specified status code.
/// Creates a <see cref="StatusCodeResult"/> with the specified status code.
/// </summary>
/// <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]
public virtual HttpStatusCodeResult StatusCode(HttpStatusCode status)
public virtual StatusCodeResult StatusCode(HttpStatusCode status)
{
return new HttpStatusCodeResult((int)status);
return new StatusCodeResult((int)status);
}
/// <inheritdoc />

View File

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

View File

@ -9,7 +9,7 @@ namespace System.Web.Http
/// <summary>
/// An action result that returns an empty <see cref="StatusCodes.Status500InternalServerError"/> response.
/// </summary>
public class InternalServerErrorResult : HttpStatusCodeResult
public class InternalServerErrorResult : StatusCodeResult
{
/// <summary>
/// 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();
// Act
var result = controller.HttpUnauthorized();
var result = controller.Unauthorized();
// Assert
Assert.IsType<HttpUnauthorizedResult>(result);
Assert.IsType<UnauthorizedResult>(result);
Assert.Equal(StatusCodes.Status401Unauthorized, result.StatusCode);
}
@ -779,10 +779,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController();
// Act
var result = controller.HttpNotFound();
var result = controller.NotFound();
// Assert
Assert.IsType<HttpNotFoundResult>(result);
Assert.IsType<NotFoundResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
}
@ -793,10 +793,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController();
// Act
var result = controller.HttpNotFound("Test Content");
var result = controller.NotFound("Test Content");
// Assert
Assert.IsType<HttpNotFoundObjectResult>(result);
Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
Assert.Equal("Test Content", result.Value);
}
@ -814,10 +814,10 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var input = new DisposableObject();
// Act
var result = controller.HttpNotFound(input);
var result = controller.NotFound(input);
// Assert
Assert.IsType<HttpNotFoundObjectResult>(result);
Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
Assert.Same(input, result.Value);
mockHttpContext.Verify(
@ -835,7 +835,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var result = controller.Ok();
// Assert
Assert.IsType<HttpOkResult>(result);
Assert.IsType<OkResult>(result);
Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
}
@ -855,7 +855,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var result = controller.Ok(input);
// Assert
Assert.IsType<HttpOkObjectResult>(result);
Assert.IsType<OkObjectResult>(result);
Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
Assert.Same(input, result.Value);
mockHttpContext.Verify(
@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController();
// Act
var result = controller.HttpBadRequest();
var result = controller.BadRequest();
// Assert
Assert.IsType<BadRequestResult>(result);
@ -885,7 +885,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var obj = new object();
// Act
var result = controller.HttpBadRequest(obj);
var result = controller.BadRequest(obj);
// Assert
Assert.IsType<BadRequestObjectResult>(result);
@ -906,7 +906,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var input = new DisposableObject();
// Act
var result = controller.HttpBadRequest(input);
var result = controller.BadRequest(input);
// Assert
Assert.IsType<BadRequestObjectResult>(result);
@ -924,7 +924,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
var controller = new TestableController();
// Act
var result = controller.HttpBadRequest(new ModelStateDictionary());
var result = controller.BadRequest(new ModelStateDictionary());
// Assert
Assert.IsType<BadRequestObjectResult>(result);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Mvc
// Assert
Assert.NotNull(authContext.Result);
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result);
var result = Assert.IsType<StatusCodeResult>(authContext.Result);
Assert.Equal(StatusCodes.Status403Forbidden, result.StatusCode);
}
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.Mvc
attr.OnAuthorization(authContext);
// Assert
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result);
var result = Assert.IsType<StatusCodeResult>(authContext.Result);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
}
@ -145,7 +145,7 @@ namespace Microsoft.AspNetCore.Mvc
{
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.NotNull(result);
var httpNotFoundResult = Assert.IsType<HttpNotFoundResult>(result);
var httpNotFoundResult = Assert.IsType<NotFoundResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundResult.StatusCode);
}
@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Mvc
// Assert
Assert.NotNull(result);
var httpNotFoundObjectResult = Assert.IsType<HttpNotFoundObjectResult>(result);
var httpNotFoundObjectResult = Assert.IsType<NotFoundObjectResult>(result);
Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundObjectResult.StatusCode);
Assert.Equal("Test Content", httpNotFoundObjectResult.Value);
}
@ -688,22 +688,22 @@ namespace Microsoft.AspNetCore.Mvc
public IActionResult HttpBadRequest_Action()
{
return HttpBadRequest();
return BadRequest();
}
public IActionResult HttpBadRequestObject_Action(object error)
{
return HttpBadRequest(error);
return BadRequest(error);
}
public IActionResult HttpNotFound_Action()
{
return HttpNotFound();
return NotFound();
}
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();
// Assert
Assert.Equal(404, Assert.IsType<HttpNotFoundResult>(result).StatusCode);
Assert.Equal(404, Assert.IsType<NotFoundResult>(result).StatusCode);
}
[Fact]
@ -291,7 +291,7 @@ namespace System.Web.Http
var result = controller.Ok();
// 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);
// Assert
var okResult = Assert.IsType<HttpOkObjectResult>(result);
var okResult = Assert.IsType<OkObjectResult>(result);
Assert.Same(product, okResult.Value);
}
@ -400,7 +400,7 @@ namespace System.Web.Http
var result = controller.StatusCode(HttpStatusCode.ExpectationFailed);
// Assert
Assert.Equal(StatusCodes.Status417ExpectationFailed, Assert.IsType<HttpStatusCodeResult>(result).StatusCode);
Assert.Equal(StatusCodes.Status417ExpectationFailed, Assert.IsType<StatusCodeResult>(result).StatusCode);
}
private class Product

View File

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

View File

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

View File

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

View File

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

View File

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