Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Http/Http.Results/test/CreatedAtRouteResultTests.cs')
-rw-r--r--src/Http/Http.Results/test/CreatedAtRouteResultTests.cs115
1 files changed, 57 insertions, 58 deletions
diff --git a/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs b/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs
index 7f4cd28dd9..7fdedb717f 100644
--- a/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs
+++ b/src/Http/Http.Results/test/CreatedAtRouteResultTests.cs
@@ -12,82 +12,81 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
-namespace Microsoft.AspNetCore.Http.Result
+namespace Microsoft.AspNetCore.Http.Result;
+
+public partial class CreatedAtRouteResultTests
{
- public partial class CreatedAtRouteResultTests
+ public static IEnumerable<object[]> CreatedAtRouteData
{
- public static IEnumerable<object[]> CreatedAtRouteData
+ get
{
- get
- {
- yield return new object[] { null };
- yield return
- new object[] {
+ yield return new object[] { null };
+ yield return
+ new object[] {
new Dictionary<string, string>() { { "hello", "world" } }
- };
- yield return
- new object[] {
+ };
+ yield return
+ new object[] {
new RouteValueDictionary(new Dictionary<string, string>() {
{ "test", "case" },
{ "sample", "route" }
})
- };
- }
+ };
}
+ }
- [Theory]
- [MemberData(nameof(CreatedAtRouteData))]
- public async Task CreatedAtRouteResult_ReturnsStatusCode_SetsLocationHeader(object values)
- {
- // Arrange
- var expectedUrl = "testAction";
- var httpContext = GetHttpContext(expectedUrl);
+ [Theory]
+ [MemberData(nameof(CreatedAtRouteData))]
+ public async Task CreatedAtRouteResult_ReturnsStatusCode_SetsLocationHeader(object values)
+ {
+ // Arrange
+ var expectedUrl = "testAction";
+ var httpContext = GetHttpContext(expectedUrl);
- // Act
- var result = new CreatedAtRouteResult(routeName: null, routeValues: values, value: null);
- await result.ExecuteAsync(httpContext);
+ // Act
+ var result = new CreatedAtRouteResult(routeName: null, routeValues: values, value: null);
+ await result.ExecuteAsync(httpContext);
- // Assert
- Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
- Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
- }
+ // Assert
+ Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
+ Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
+ }
- [Fact]
- public async Task CreatedAtRouteResult_ThrowsOnNullUrl()
- {
- // Arrange
- var httpContext = GetHttpContext(expectedUrl: null);
+ [Fact]
+ public async Task CreatedAtRouteResult_ThrowsOnNullUrl()
+ {
+ // Arrange
+ var httpContext = GetHttpContext(expectedUrl: null);
- var result = new CreatedAtRouteResult(
- routeName: null,
- routeValues: new Dictionary<string, object>(),
- value: null);
+ var result = new CreatedAtRouteResult(
+ routeName: null,
+ routeValues: new Dictionary<string, object>(),
+ value: null);
- // Act & Assert
- await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
- async () => await result.ExecuteAsync(httpContext),
- "No route matches the supplied values.");
- }
+ // Act & Assert
+ await ExceptionAssert.ThrowsAsync<InvalidOperationException>(
+ async () => await result.ExecuteAsync(httpContext),
+ "No route matches the supplied values.");
+ }
- private static HttpContext GetHttpContext(string expectedUrl)
- {
- var httpContext = new DefaultHttpContext();
- httpContext.Request.PathBase = new PathString("");
- httpContext.Response.Body = new MemoryStream();
- httpContext.RequestServices = CreateServices(expectedUrl);
- return httpContext;
- }
+ private static HttpContext GetHttpContext(string expectedUrl)
+ {
+ var httpContext = new DefaultHttpContext();
+ httpContext.Request.PathBase = new PathString("");
+ httpContext.Response.Body = new MemoryStream();
+ httpContext.RequestServices = CreateServices(expectedUrl);
+ return httpContext;
+ }
- private static IServiceProvider CreateServices(string expectedUrl)
+ private static IServiceProvider CreateServices(string expectedUrl)
+ {
+ var services = new ServiceCollection();
+ services.AddSingleton<ILoggerFactory, NullLoggerFactory>();
+ services.AddSingleton<LinkGenerator>(new TestLinkGenerator
{
- var services = new ServiceCollection();
- services.AddSingleton<ILoggerFactory, NullLoggerFactory>();
- services.AddSingleton<LinkGenerator>(new TestLinkGenerator
- {
- Url = expectedUrl
- });
+ Url = expectedUrl
+ });
- return services.BuildServiceProvider();
- }
+ return services.BuildServiceProvider();
}
}