Merge pull request #8119 from dotnet-maestro-bot/merge/release/2.2-to-master

[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
Pranav K 2018-07-19 18:41:06 -07:00 committed by GitHub
commit 49be8d20a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -50,6 +50,11 @@ namespace Microsoft.AspNetCore.Mvc
if (StatusCode.HasValue)
{
context.HttpContext.Response.StatusCode = StatusCode.Value;
if (Value is ProblemDetails details && !details.Status.HasValue)
{
details.Status = StatusCode.Value;
}
}
}
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@ -61,6 +62,38 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal(404, actionContext.HttpContext.Response.StatusCode);
}
[Fact]
public async Task ObjectResult_ExecuteResultAsync_SetsProblemDetailsStatus()
{
// Arrange
var modelState = new ModelStateDictionary();
var details = new ValidationProblemDetails(modelState);
var result = new ObjectResult(details)
{
StatusCode = StatusCodes.Status422UnprocessableEntity,
Formatters = new FormatterCollection<IOutputFormatter>()
{
new NoOpOutputFormatter(),
},
};
var actionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext()
{
RequestServices = CreateServices(),
}
};
// Act
await result.ExecuteResultAsync(actionContext);
// Assert
Assert.Equal(StatusCodes.Status422UnprocessableEntity, details.Status.Value);
}
private static IServiceProvider CreateServices()
{
var services = new ServiceCollection();