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:
commit
49be8d20a9
|
|
@ -50,6 +50,11 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
if (StatusCode.HasValue)
|
if (StatusCode.HasValue)
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.StatusCode = StatusCode.Value;
|
context.HttpContext.Response.StatusCode = StatusCode.Value;
|
||||||
|
|
||||||
|
if (Value is ProblemDetails details && !details.Status.HasValue)
|
||||||
|
{
|
||||||
|
details.Status = StatusCode.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
@ -61,6 +62,38 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
Assert.Equal(404, actionContext.HttpContext.Response.StatusCode);
|
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()
|
private static IServiceProvider CreateServices()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue