diff options
Diffstat (limited to 'src/Http/Http.Results/test/CreatedResultTest.cs')
-rw-r--r-- | src/Http/Http.Results/test/CreatedResultTest.cs | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/src/Http/Http.Results/test/CreatedResultTest.cs b/src/Http/Http.Results/test/CreatedResultTest.cs index 28f4868e8f..06bc459d36 100644 --- a/src/Http/Http.Results/test/CreatedResultTest.cs +++ b/src/Http/Http.Results/test/CreatedResultTest.cs @@ -9,71 +9,70 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Xunit; -namespace Microsoft.AspNetCore.Http.Result +namespace Microsoft.AspNetCore.Http.Result; + +public class CreatedResultTests { - public class CreatedResultTests + [Fact] + public void CreatedResult_SetsLocation() { - [Fact] - public void CreatedResult_SetsLocation() - { - // Arrange - var location = "http://test/location"; + // Arrange + var location = "http://test/location"; - // Act - var result = new CreatedResult(location, "testInput"); + // Act + var result = new CreatedResult(location, "testInput"); - // Assert - Assert.Same(location, result.Location); - } + // Assert + Assert.Same(location, result.Location); + } - [Fact] - public async Task CreatedResult_ReturnsStatusCode_SetsLocationHeader() - { - // Arrange - var location = "/test/"; - var httpContext = GetHttpContext(); - var result = new CreatedResult(location, "testInput"); + [Fact] + public async Task CreatedResult_ReturnsStatusCode_SetsLocationHeader() + { + // Arrange + var location = "/test/"; + var httpContext = GetHttpContext(); + var result = new CreatedResult(location, "testInput"); - // Act - await result.ExecuteAsync(httpContext); + // Act + await result.ExecuteAsync(httpContext); - // Assert - Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); - Assert.Equal(location, httpContext.Response.Headers["Location"]); - } + // Assert + Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); + Assert.Equal(location, httpContext.Response.Headers["Location"]); + } - [Fact] - public async Task CreatedResult_OverwritesLocationHeader() - { - // Arrange - var location = "/test/"; - var httpContext = GetHttpContext(); - httpContext.Response.Headers["Location"] = "/different/location/"; - var result = new CreatedResult(location, "testInput"); + [Fact] + public async Task CreatedResult_OverwritesLocationHeader() + { + // Arrange + var location = "/test/"; + var httpContext = GetHttpContext(); + httpContext.Response.Headers["Location"] = "/different/location/"; + var result = new CreatedResult(location, "testInput"); - // Act - await result.ExecuteAsync(httpContext); + // Act + await result.ExecuteAsync(httpContext); - // Assert - Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); - Assert.Equal(location, httpContext.Response.Headers["Location"]); - } + // Assert + Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); + Assert.Equal(location, httpContext.Response.Headers["Location"]); + } - private static HttpContext GetHttpContext() - { - var httpContext = new DefaultHttpContext(); - httpContext.Request.PathBase = new PathString(""); - httpContext.Response.Body = new MemoryStream(); - httpContext.RequestServices = CreateServices(); - return httpContext; - } + private static HttpContext GetHttpContext() + { + var httpContext = new DefaultHttpContext(); + httpContext.Request.PathBase = new PathString(""); + httpContext.Response.Body = new MemoryStream(); + httpContext.RequestServices = CreateServices(); + return httpContext; + } - private static IServiceProvider CreateServices() - { - var services = new ServiceCollection(); - services.AddSingleton<ILoggerFactory, NullLoggerFactory>(); + private static IServiceProvider CreateServices() + { + var services = new ServiceCollection(); + services.AddSingleton<ILoggerFactory, NullLoggerFactory>(); - return services.BuildServiceProvider(); - } + return services.BuildServiceProvider(); } } |