aspnetcore/test/Microsoft.AspNetCore.Mvc.We.../InternalServerErrorResultTe...

52 lines
1.6 KiB
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
namespace System.Web.Http
{
public class InternalServerErrorResultTest
{
[Fact]
public async Task InternalServerErrorResult_SetsStatusCode()
{
// Arrange
var context = new ActionContext(GetHttpContext(), new RouteData(), new ActionDescriptor());
var result = new InternalServerErrorResult();
// Act
await result.ExecuteResultAsync(context);
// Assert
Assert.Equal(StatusCodes.Status500InternalServerError, context.HttpContext.Response.StatusCode);
}
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}
private static HttpContext GetHttpContext()
{
var services = CreateServices();
var httpContext = new DefaultHttpContext();
httpContext.RequestServices = services.BuildServiceProvider();
return httpContext;
}
}
}