Replaced status code number with constants

This commit is contained in:
Ajay Bhargav Baaskaran 2015-01-29 13:56:49 -08:00
parent 3c380bc38e
commit ac6a1a6a80
48 changed files with 142 additions and 93 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
@ -17,7 +18,7 @@ namespace Microsoft.AspNet.Mvc
public BadRequestObjectResult(object error)
: base(error)
{
StatusCode = 400;
StatusCode = StatusCodes.Status400BadRequest;
}
/// <summary>
@ -27,7 +28,7 @@ namespace Microsoft.AspNet.Mvc
public BadRequestObjectResult([NotNull] ModelStateDictionary modelState)
: base(new SerializableError(modelState))
{
StatusCode = 400;
StatusCode = StatusCodes.Status400BadRequest;
}
}
}

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
/// <summary>
@ -13,7 +15,7 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="BadRequestResult"/> instance.
/// </summary>
public BadRequestResult()
: base(400)
: base(StatusCodes.Status400BadRequest)
{
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc
@ -30,7 +31,7 @@ namespace Microsoft.AspNet.Mvc
ActionName = actionName;
ControllerName = controllerName;
RouteValues = TypeHelper.ObjectToDictionary(routeValues);
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}
/// <summary>

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc
@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Mvc
{
RouteName = routeName;
RouteValues = TypeHelper.ObjectToDictionary(routeValues);
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}
/// <summary>

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
@ -22,7 +23,7 @@ namespace Microsoft.AspNet.Mvc
: base(value)
{
Location = location;
StatusCode = 201;
StatusCode = StatusCodes.Status201Created;
}
/// <summary>

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
/// <summary>
@ -12,7 +14,7 @@ namespace Microsoft.AspNet.Mvc
/// <summary>
/// Creates a new <see cref="HttpNotFoundResult"/> instance.
/// </summary>
public HttpNotFoundResult() : base(404)
public HttpNotFoundResult() : base(StatusCodes.Status404NotFound)
{
}
}

View File

@ -1,12 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
public class NoContentResult : HttpStatusCodeResult
{
public NoContentResult()
: base(204)
: base(StatusCodes.Status204NoContent)
{
}
}

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc
if (selectedFormatter == null)
{
// No formatter supports this.
context.HttpContext.Response.StatusCode = 406;
context.HttpContext.Response.StatusCode = StatusCodes.Status406NotAcceptable;
return;
}

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
/// <summary>
@ -12,7 +14,7 @@ namespace Microsoft.AspNet.Mvc
/// <summary>
/// Creates a new instance of <see cref="UnsupportedMediaTypeResult"/>.
/// </summary>
public UnsupportedMediaTypeResult() : base(415)
public UnsupportedMediaTypeResult() : base(StatusCodes.Status415UnsupportedMediaType)
{
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Mvc
protected virtual void Fail([NotNull] AuthorizationContext context)
{
context.Result = new HttpStatusCodeResult(401);
context.Result = new HttpStatusCodeResult(StatusCodes.Status401Unauthorized);
}
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -44,7 +45,7 @@ namespace Microsoft.AspNet.Mvc
{
var response = context.ActionContext.HttpContext.Response;
response.ContentLength = 0;
response.StatusCode = context.StatusCode ?? 204;
response.StatusCode = context.StatusCode ?? StatusCodes.Status204NoContent;
return Task.FromResult(true);
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -32,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
public Task WriteAsync(OutputFormatterContext context)
{
var response = context.ActionContext.HttpContext.Response;
response.StatusCode = 406;
response.StatusCode = StatusCodes.Status406NotAcceptable;
return Task.FromResult(true);
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.WebUtilities;
namespace Microsoft.AspNet.Mvc
{
@ -25,7 +26,7 @@ namespace Microsoft.AspNet.Mvc
// body correctly.
if (!string.Equals(filterContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
{
filterContext.Result = new HttpStatusCodeResult(403);
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status403Forbidden);
}
else
{

View File

@ -4,11 +4,12 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="System.Net.HttpStatusCode.BadRequest"/> response and performs
/// An action result that returns a <see cref="StatusCodes.Status400BadRequest"/> response and performs
/// content negotiation on an <see cref="HttpError"/> with a <see cref="HttpError.Message"/>.
/// </summary>
public class BadRequestErrorMessageResult : ObjectResult
@ -29,7 +30,7 @@ namespace System.Web.Http
/// <inheritdoc />
public override async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
await base.ExecuteResultAsync(context);
}
}

View File

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.Conflict"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status409Conflict"/> response.
/// </summary>
public class ConflictResult : HttpStatusCodeResult
{
@ -15,7 +15,7 @@ namespace System.Web.Http
/// Initializes a new instance of the <see cref="ConflictResult"/> class.
/// </summary>
public ConflictResult()
: base((int)HttpStatusCode.Conflict)
: base(StatusCodes.Status409Conflict)
{
}
}

View File

@ -1,14 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="HttpStatusCode.InternalServerError"/> response and
/// An action result that returns a <see cref="StatusCodes.Status500InternalServerError"/> response and
/// performs content negotiation on an <see cref="HttpError"/> based on an <see cref="Exception"/>.
/// </summary>
public class ExceptionResult : ObjectResult
@ -41,7 +41,7 @@ namespace System.Web.Http
/// <inheritdoc />
public override Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
return base.ExecuteResultAsync(context);
}
}

View File

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.InternalServerError"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status500InternalServerError"/> response.
/// </summary>
public class InternalServerErrorResult : HttpStatusCodeResult
{
@ -15,7 +15,7 @@ namespace System.Web.Http
/// Initializes a new instance of the <see cref="InternalServerErrorResult"/> class.
/// </summary>
public InternalServerErrorResult()
: base((int)HttpStatusCode.InternalServerError)
: base(StatusCodes.Status500InternalServerError)
{
}
}

View File

@ -1,15 +1,15 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns a <see cref="System.Net.HttpStatusCode.BadRequest"/> response and performs
/// An action result that returns a <see cref="StatusCodes.Status400BadRequest"/> response and performs
/// content negotiation on an <see cref="HttpError"/> based on a <see cref="ModelStateDictionary"/>.
/// </summary>
public class InvalidModelStateResult : ObjectResult
@ -39,7 +39,7 @@ namespace System.Web.Http
/// <inheritdoc />
public override async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
await base.ExecuteResultAsync(context);
}
}

View File

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace System.Web.Http
{
/// <summary>
/// An action result that returns an empty <see cref="HttpStatusCode.OK"/> response.
/// An action result that returns an empty <see cref="StatusCodes.Status200OK"/> response.
/// </summary>
public class OkResult : HttpStatusCodeResult
{
@ -15,7 +15,7 @@ namespace System.Web.Http
/// Initializes a new instance of the <see cref="OkResult"/> class.
/// </summary>
public OkResult()
: base((int)HttpStatusCode.OK)
: base(StatusCodes.Status200OK)
{
}
}

View File

@ -1,8 +1,9 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Xunit;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
{
@ -16,7 +17,7 @@ namespace Microsoft.AspNet.Mvc
var badRequestObjecResult = new BadRequestObjectResult(obj);
// Assert
Assert.Equal(400, badRequestObjecResult.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, badRequestObjecResult.StatusCode);
Assert.Equal(obj, badRequestObjecResult.Value);
}
@ -27,7 +28,7 @@ namespace Microsoft.AspNet.Mvc
var badRequestObjecResult = new BadRequestObjectResult(new ModelStateDictionary());
// Assert
Assert.Equal(400, badRequestObjecResult.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, badRequestObjecResult.StatusCode);
var errors = Assert.IsType<SerializableError>(badRequestObjecResult.Value);
Assert.Equal(0, errors.Count);
}

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -14,7 +15,7 @@ namespace Microsoft.AspNet.Mvc
var badRequest = new BadRequestResult();
// Assert
Assert.Equal(400, badRequest.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, badRequest.StatusCode);
}
}
}

View File

@ -10,6 +10,7 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Mvc
await result.ExecuteResultAsync(actionContext);
// Assert
Assert.Equal(201, httpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
}

View File

@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -52,7 +53,7 @@ namespace Microsoft.AspNet.Mvc
await result.ExecuteResultAsync(actionContext);
// Assert
Assert.Equal(201, httpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
}

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -41,7 +42,7 @@ namespace Microsoft.AspNet.Mvc
await result.ExecuteResultAsync(actionContext);
// Assert
Assert.Equal(201, httpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
Assert.Equal(location, httpContext.Response.Headers["Location"]);
}
@ -59,7 +60,7 @@ namespace Microsoft.AspNet.Mvc
await result.ExecuteResultAsync(actionContext);
// Assert
Assert.Equal(201, httpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
Assert.Equal(location, httpContext.Response.Headers["Location"]);
}

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -14,7 +15,7 @@ namespace Microsoft.AspNet.Mvc
var notFound = new HttpNotFoundResult();
// Assert
Assert.Equal(404, notFound.StatusCode);
Assert.Equal(StatusCodes.Status404NotFound, notFound.StatusCode);
}
}
}

View File

@ -3,6 +3,7 @@
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -13,7 +14,7 @@ namespace Microsoft.AspNet.Mvc
public void HttpStatusCodeResult_ExecuteResultSetsResponseStatusCode()
{
// Arrange
var result = new HttpStatusCodeResult(404);
var result = new HttpStatusCodeResult(StatusCodes.Status404NotFound);
var httpContext = new DefaultHttpContext();
var routeData = new RouteData();
@ -25,7 +26,7 @@ namespace Microsoft.AspNet.Mvc
result.ExecuteResult(context);
// Assert
Assert.Equal(404, httpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
}
}
}

View File

@ -11,6 +11,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel;
@ -401,7 +402,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
// Assert
// Asserts that content type is not text/custom.
httpResponse.VerifySet(r => r.StatusCode = 406);
httpResponse.VerifySet(r => r.StatusCode = StatusCodes.Status406NotAcceptable);
}
[Fact]
@ -436,7 +437,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
{
// Arrange
var stream = new MemoryStream();
var expectedStatusCode = 201;
var expectedStatusCode = StatusCodes.Status201Created;
var httpResponse = new Mock<HttpResponse>();
httpResponse.SetupGet(r => r.Body).Returns(stream);

View File

@ -12,6 +12,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing;
using Microsoft.AspNet.WebUtilities;
#if ASPNET50
using Moq;
#endif
@ -384,7 +385,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Same(uri, result.Location);
}
@ -400,7 +401,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal(uri.OriginalString, result.Location);
}
@ -416,7 +417,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal(uri.OriginalString, result.Location);
}
@ -431,7 +432,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
}
@ -450,7 +451,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Equal(controllerName, result.ControllerName);
}
@ -474,7 +475,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedAtActionResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal("SampleAction", result.ActionName);
Assert.Equal("SampleController", result.ControllerName);
Assert.Equal(expected, result.RouteValues);
@ -511,7 +512,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedAtRouteResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Equal(expected, result.RouteValues);
}
@ -532,7 +533,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<CreatedAtRouteResult>(result);
Assert.Equal(201, result.StatusCode);
Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
Assert.Same(routeName, result.RouteName);
Assert.Equal(expected, result.RouteValues);
}
@ -651,7 +652,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<HttpNotFoundResult>(result);
Assert.Equal(404, result.StatusCode);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
}
[Fact]
@ -665,7 +666,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<BadRequestResult>(result);
Assert.Equal(400, result.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
}
[Fact]
@ -680,7 +681,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(400, result.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
Assert.Equal(obj, result.Value);
}
@ -695,7 +696,7 @@ namespace Microsoft.AspNet.Mvc.Test
// Assert
Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(400, result.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
var errors = Assert.IsType<SerializableError>(result.Value);
Assert.Equal(0, errors.Count);
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -100,7 +101,7 @@ namespace Microsoft.AspNet.Mvc
var createdResult = Assert.IsType<CreatedResult>(result);
Assert.Equal(uri, createdResult.Location);
Assert.Equal(content, createdResult.Value);
Assert.Equal(201, createdResult.StatusCode);
Assert.Equal(StatusCodes.Status201Created, createdResult.StatusCode);
}
[Theory]
@ -206,7 +207,7 @@ namespace Microsoft.AspNet.Mvc
Assert.NotNull(result);
var httpNotFoundResult = Assert.IsType<HttpNotFoundResult>(result);
Assert.Equal(404, httpNotFoundResult.StatusCode);
Assert.Equal(StatusCodes.Status404NotFound, httpNotFoundResult.StatusCode);
}
[Fact]
@ -222,7 +223,7 @@ namespace Microsoft.AspNet.Mvc
Assert.NotNull(result);
var httpBadRequest = Assert.IsType<BadRequestResult>(result);
Assert.Equal(400, httpBadRequest.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, httpBadRequest.StatusCode);
}
[Fact]
@ -239,7 +240,7 @@ namespace Microsoft.AspNet.Mvc
Assert.NotNull(result);
var httpBadRequest = Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(400, httpBadRequest.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, httpBadRequest.StatusCode);
Assert.Same(error, httpBadRequest.Value);
// Arrange
@ -252,7 +253,7 @@ namespace Microsoft.AspNet.Mvc
Assert.NotNull(result);
httpBadRequest = Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(400, httpBadRequest.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, httpBadRequest.StatusCode);
Assert.Null(httpBadRequest.Value);
}

View File

@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Security;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Moq;
using Xunit;
@ -227,7 +228,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
services.AddInstance(authorizationService.Object)
);
authorizationContext.Result = new HttpStatusCodeResult(401);
authorizationContext.Result = new HttpStatusCodeResult(StatusCodes.Status401Unauthorized);
// Act
await authorizeAttribute.OnAuthorizationAsync(authorizationContext);

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Net.Http.Headers;
using Xunit;
@ -125,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.Test
await formatter.WriteAsync(formatterContext);
// Assert
Assert.Equal(204, defaultHttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status204NoContent, defaultHttpContext.Response.StatusCode);
}
[Fact]
@ -137,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.Test
{
Object = null,
ActionContext = new ActionContext(defaultHttpContext, new RouteData(), new ActionDescriptor()),
StatusCode = 201
StatusCode = StatusCodes.Status201Created
};
var formatter = new HttpNoContentOutputFormatter();
@ -146,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.Test
await formatter.WriteAsync(formatterContext);
// Assert
Assert.Equal(201, defaultHttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status201Created, defaultHttpContext.Response.StatusCode);
}
}
}

View File

@ -6,6 +6,7 @@ using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -120,7 +121,7 @@ namespace Microsoft.AspNet.Mvc
// Assert
Assert.NotNull(authContext.Result);
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result);
Assert.Equal(403, result.StatusCode);
Assert.Equal(StatusCodes.Status403Forbidden, result.StatusCode);
}
[Fact]
@ -138,14 +139,14 @@ namespace Microsoft.AspNet.Mvc
// Assert
var result = Assert.IsType<HttpStatusCodeResult>(authContext.Result);
Assert.Equal(404, result.StatusCode);
Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
}
private class CustomRequireHttpsAttribute : RequireHttpsAttribute
{
protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
{
filterContext.Result = new HttpStatusCodeResult(404);
filterContext.Result = new HttpStatusCodeResult(StatusCodes.Status404NotFound);
}
}

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.TestHost;
using Microsoft.AspNet.WebUtilities;
using Newtonsoft.Json;
using Xunit;
@ -27,17 +28,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
yield return new object[] {
"{\"ByteProperty\":1, \"NullableByteProperty\":5, \"ByteArrayProperty\":[1,2,3]}",
400,
StatusCodes.Status400BadRequest,
"The field ByteProperty must be between 2 and 8."};
yield return new object[] {
"{\"ByteProperty\":8, \"NullableByteProperty\":1, \"ByteArrayProperty\":[1,2,3]}",
400,
StatusCodes.Status400BadRequest,
"The field NullableByteProperty must be between 2 and 8."};
yield return new object[] {
"{\"ByteProperty\":8, \"NullableByteProperty\":2, \"ByteArrayProperty\":[1]}",
400,
StatusCodes.Status400BadRequest,
"The field ByteArrayProperty must be a string or array type with a minimum length of '2'."};
}
}
@ -130,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
var response = await client.PostAsync("http://localhost/Validation/CreateProject", content);
//Assert
Assert.Equal(400, (int)response.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, (int)response.StatusCode);
var responseContent = await response.Content.ReadAsStringAsync();
var responseObject = JsonConvert.DeserializeObject<Dictionary<string, ErrorCollection>>(responseContent);

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -33,7 +34,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(400, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, context.HttpContext.Response.StatusCode);
}
[Fact]

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace System.Web.Http
@ -22,7 +23,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(409, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status409Conflict, context.HttpContext.Response.StatusCode);
}
}
}

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -33,7 +34,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(500, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status500InternalServerError, context.HttpContext.Response.StatusCode);
}
[Fact]

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace System.Web.Http
@ -22,7 +23,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(500, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status500InternalServerError, context.HttpContext.Response.StatusCode);
}
}
}

View File

@ -9,6 +9,7 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -38,7 +39,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(400, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, context.HttpContext.Response.StatusCode);
}
[Fact]

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;
@ -33,7 +34,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(200, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status200OK, context.HttpContext.Response.StatusCode);
}
private IServiceProvider CreateServices()

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Xunit;
namespace System.Web.Http
@ -22,7 +23,7 @@ namespace System.Web.Http
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(200, context.HttpContext.Response.StatusCode);
Assert.Equal(StatusCodes.Status200OK, context.HttpContext.Response.StatusCode);
}
}
}

View File

@ -10,6 +10,7 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Newtonsoft.Json;
using Xunit;
@ -60,7 +61,7 @@ namespace System.Web.Http
var result = controller.BadRequest();
// Assert
Assert.Equal(400, Assert.IsType<BadRequestResult>(result).StatusCode);
Assert.Equal(StatusCodes.Status400BadRequest, Assert.IsType<BadRequestResult>(result).StatusCode);
}
[Fact]
@ -185,7 +186,7 @@ namespace System.Web.Http
var result = controller.Conflict();
// Assert
Assert.Equal(409, Assert.IsType<ConflictResult>(result).StatusCode);
Assert.Equal(StatusCodes.Status409Conflict, Assert.IsType<ConflictResult>(result).StatusCode);
}
[Fact]
@ -201,7 +202,7 @@ namespace System.Web.Http
// Assert
var contentResult = Assert.IsType<NegotiatedContentResult<Product>>(result);
Assert.Equal((int)HttpStatusCode.Found, contentResult.StatusCode);
Assert.Equal(StatusCodes.Status302Found, contentResult.StatusCode);
Assert.Equal(content, contentResult.Value);
}
@ -215,7 +216,7 @@ namespace System.Web.Http
var result = controller.InternalServerError();
// Assert
Assert.Equal(500, Assert.IsType<InternalServerErrorResult>(result).StatusCode);
Assert.Equal(StatusCodes.Status500InternalServerError, Assert.IsType<InternalServerErrorResult>(result).StatusCode);
}
[Fact]
@ -419,7 +420,7 @@ namespace System.Web.Http
var result = controller.StatusCode(HttpStatusCode.ExpectationFailed);
// Assert
Assert.Equal(417, Assert.IsType<HttpStatusCodeResult>(result).StatusCode);
Assert.Equal(StatusCodes.Status417ExpectationFailed, Assert.IsType<HttpStatusCodeResult>(result).StatusCode);
}
private class Product

View File

@ -4,6 +4,7 @@
using System;
using System.Text;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace ActionResultsWebSite
{
@ -80,7 +81,7 @@ namespace ActionResultsWebSite
public IActionResult GetObjectResultWithNoContent()
{
var result = new ObjectResult(null);
result.StatusCode = 201;
result.StatusCode = StatusCodes.Status201Created;
return result;
}

View File

@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace BasicWebSite.Controllers
{
@ -37,14 +38,14 @@ namespace BasicWebSite.Controllers
public IActionResult NoContentResult()
{
return new HttpStatusCodeResult(204);
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
}
[AcceptVerbs("GET", "POST")]
[RequireHttps]
public IActionResult HttpsOnlyAction()
{
return new HttpStatusCodeResult(200);
return new HttpStatusCodeResult(StatusCodes.Status200OK);
}
public Task ActionReturningTask()

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
using Newtonsoft.Json;
namespace FormatterWebSite.Controllers
@ -33,7 +34,7 @@ namespace FormatterWebSite.Controllers
{
if (!ModelState.IsValid)
{
return new HttpStatusCodeResult(400);
return new HttpStatusCodeResult(StatusCodes.Status400BadRequest);
}
return Content(dummyObject.SampleInt.ToString());
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
namespace FormatterWebSite
{
@ -11,7 +12,10 @@ namespace FormatterWebSite
{
if (!context.ModelState.IsValid)
{
context.Result = new ObjectResult(context.ModelState) { StatusCode = 400 };
context.Result = new ObjectResult(context.ModelState)
{
StatusCode = StatusCodes.Status400BadRequest
};
}
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Elm;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.WebUtilities;
using Newtonsoft.Json;
namespace LoggingWebSite
@ -25,7 +26,7 @@ namespace LoggingWebSite
var logActivities = GetLogDetails(elmStore);
context.Response.StatusCode = 200;
context.Response.StatusCode = StatusCodes.Status200OK;
context.Response.ContentType = "application/json";
var serializer = JsonSerializer.Create();

View File

@ -5,8 +5,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
using ModelBindingWebSite.Services;
using ModelBindingWebSite.ViewModels;
@ -133,7 +133,7 @@ namespace ModelBindingWebSite
public IDictionary<string, IEnumerable<string>> SerializeModelState()
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
Response.StatusCode = StatusCodes.Status400BadRequest;
return ModelState.Where(item => item.Value.Errors.Count > 0)
.ToDictionary(item => item.Key, item => item.Value.Errors.Select(e => e.ErrorMessage));

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.WebUtilities;
using Newtonsoft.Json;
namespace WebApiCompatShimWebSite
@ -22,7 +23,7 @@ namespace WebApiCompatShimWebSite
})
});
context.Result = new HttpStatusCodeResult(200);
context.Result = new HttpStatusCodeResult(StatusCodes.Status200OK);
}
}
}