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/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs')
-rw-r--r--src/Http/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs209
1 files changed, 104 insertions, 105 deletions
diff --git a/src/Http/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs b/src/Http/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs
index 5d8299a442..e6f2b9673b 100644
--- a/src/Http/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs
+++ b/src/Http/Routing/test/UnitTests/Builder/RoutingBuilderExtensionsTest.cs
@@ -9,128 +9,127 @@ using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;
-namespace Microsoft.AspNetCore.Builder
+namespace Microsoft.AspNetCore.Builder;
+
+public class RoutingBuilderExtensionsTest
{
- public class RoutingBuilderExtensionsTest
+ [Fact]
+ public void UseRouter_ThrowsInvalidOperationException_IfRoutingMarkerServiceIsNotRegistered()
{
- [Fact]
- public void UseRouter_ThrowsInvalidOperationException_IfRoutingMarkerServiceIsNotRegistered()
- {
- // Arrange
- var applicationBuilderMock = new Mock<IApplicationBuilder>();
- applicationBuilderMock
- .Setup(s => s.ApplicationServices)
- .Returns(Mock.Of<IServiceProvider>());
-
- var router = Mock.Of<IRouter>();
-
- // Act & Assert
- var exception = Assert.Throws<InvalidOperationException>(
- () => applicationBuilderMock.Object.UseRouter(router));
-
- Assert.Equal(
- "Unable to find the required services. Please add all the required services by calling " +
- "'IServiceCollection.AddRouting' inside the call to 'ConfigureServices(...)'" +
- " in the application startup code.",
- exception.Message);
- }
-
- [Fact]
- public void UseRouter_IRouter_ThrowsWithoutCallingAddRouting()
- {
- // Arrange
- var app = new ApplicationBuilder(Mock.Of<IServiceProvider>());
-
- // Act
- var ex = Assert.Throws<InvalidOperationException>(() => app.UseRouter(Mock.Of<IRouter>()));
-
- // Assert
- Assert.Equal(
- "Unable to find the required services. " +
- "Please add all the required services by calling 'IServiceCollection.AddRouting' " +
- "inside the call to 'ConfigureServices(...)' in the application startup code.",
- ex.Message);
- }
-
- [Fact]
- public void UseRouter_Action_ThrowsWithoutCallingAddRouting()
- {
- // Arrange
- var app = new ApplicationBuilder(Mock.Of<IServiceProvider>());
-
- // Act
- var ex = Assert.Throws<InvalidOperationException>(() => app.UseRouter(b => { }));
-
- // Assert
- Assert.Equal(
- "Unable to find the required services. " +
- "Please add all the required services by calling 'IServiceCollection.AddRouting' " +
- "inside the call to 'ConfigureServices(...)' in the application startup code.",
- ex.Message);
- }
-
- [Fact]
- public async Task UseRouter_IRouter_CallsRoute()
- {
- // Arrange
- var services = CreateServices();
-
- var app = new ApplicationBuilder(services);
+ // Arrange
+ var applicationBuilderMock = new Mock<IApplicationBuilder>();
+ applicationBuilderMock
+ .Setup(s => s.ApplicationServices)
+ .Returns(Mock.Of<IServiceProvider>());
+
+ var router = Mock.Of<IRouter>();
+
+ // Act & Assert
+ var exception = Assert.Throws<InvalidOperationException>(
+ () => applicationBuilderMock.Object.UseRouter(router));
+
+ Assert.Equal(
+ "Unable to find the required services. Please add all the required services by calling " +
+ "'IServiceCollection.AddRouting' inside the call to 'ConfigureServices(...)'" +
+ " in the application startup code.",
+ exception.Message);
+ }
- var router = new Mock<IRouter>(MockBehavior.Strict);
- router
- .Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
- .Returns(Task.CompletedTask)
- .Verifiable();
+ [Fact]
+ public void UseRouter_IRouter_ThrowsWithoutCallingAddRouting()
+ {
+ // Arrange
+ var app = new ApplicationBuilder(Mock.Of<IServiceProvider>());
+
+ // Act
+ var ex = Assert.Throws<InvalidOperationException>(() => app.UseRouter(Mock.Of<IRouter>()));
+
+ // Assert
+ Assert.Equal(
+ "Unable to find the required services. " +
+ "Please add all the required services by calling 'IServiceCollection.AddRouting' " +
+ "inside the call to 'ConfigureServices(...)' in the application startup code.",
+ ex.Message);
+ }
- app.UseRouter(router.Object);
+ [Fact]
+ public void UseRouter_Action_ThrowsWithoutCallingAddRouting()
+ {
+ // Arrange
+ var app = new ApplicationBuilder(Mock.Of<IServiceProvider>());
+
+ // Act
+ var ex = Assert.Throws<InvalidOperationException>(() => app.UseRouter(b => { }));
+
+ // Assert
+ Assert.Equal(
+ "Unable to find the required services. " +
+ "Please add all the required services by calling 'IServiceCollection.AddRouting' " +
+ "inside the call to 'ConfigureServices(...)' in the application startup code.",
+ ex.Message);
+ }
- var appFunc = app.Build();
+ [Fact]
+ public async Task UseRouter_IRouter_CallsRoute()
+ {
+ // Arrange
+ var services = CreateServices();
- // Act
- await appFunc(new DefaultHttpContext());
+ var app = new ApplicationBuilder(services);
- // Assert
- router.Verify();
- }
+ var router = new Mock<IRouter>(MockBehavior.Strict);
+ router
+ .Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
- [Fact]
- public async Task UseRouter_Action_CallsRoute()
- {
- // Arrange
- var services = CreateServices();
+ app.UseRouter(router.Object);
- var app = new ApplicationBuilder(services);
+ var appFunc = app.Build();
- var router = new Mock<IRouter>(MockBehavior.Strict);
- router
- .Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
- .Returns(Task.CompletedTask)
- .Verifiable();
+ // Act
+ await appFunc(new DefaultHttpContext());
- app.UseRouter(b =>
- {
- b.Routes.Add(router.Object);
- });
+ // Assert
+ router.Verify();
+ }
- var appFunc = app.Build();
+ [Fact]
+ public async Task UseRouter_Action_CallsRoute()
+ {
+ // Arrange
+ var services = CreateServices();
- // Act
- await appFunc(new DefaultHttpContext());
+ var app = new ApplicationBuilder(services);
- // Assert
- router.Verify();
- }
+ var router = new Mock<IRouter>(MockBehavior.Strict);
+ router
+ .Setup(r => r.RouteAsync(It.IsAny<RouteContext>()))
+ .Returns(Task.CompletedTask)
+ .Verifiable();
- private IServiceProvider CreateServices()
+ app.UseRouter(b =>
{
- var services = new ServiceCollection();
+ b.Routes.Add(router.Object);
+ });
+
+ var appFunc = app.Build();
+
+ // Act
+ await appFunc(new DefaultHttpContext());
+
+ // Assert
+ router.Verify();
+ }
+
+ private IServiceProvider CreateServices()
+ {
+ var services = new ServiceCollection();
- services.AddLogging();
- services.AddOptions();
- services.AddRouting();
+ services.AddLogging();
+ services.AddOptions();
+ services.AddRouting();
- return services.BuildServiceProvider();
- }
+ return services.BuildServiceProvider();
}
}