public async Task UseRouter_Action_CallsRoute() { // Arrange var services = CreateServices(); var app = new ApplicationBuilder(services); var router = new Mock <IRouter>(MockBehavior.Strict); router .Setup(r => r.RouteAsync(It.IsAny <RouteContext>())) .Returns(Task.CompletedTask) .Verifiable(); app.UseRouter(b => { b.Routes.Add(router.Object); }); var appFunc = app.Build(); // Act await appFunc(new DefaultHttpContext()); // Assert router.Verify(); }
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); }