public void DoesNotClearProxyRoutes() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoNSubstituteCustomization()); var constraintResolver = new Mock <IInlineConstraintResolver>(); var handler = new Mock <IWebJobsRouteHandler>(); IWebJobsRouter router = new WebJobsRouter(constraintResolver.Object); var builder = router.CreateBuilder(handler.Object, "api"); builder.MapFunctionRoute("testfunction1", "test/{token}", "testfunction1"); builder.MapFunctionRoute("testfunction2", "test/xxxxxxxxxx", "testfunction2"); var proxyBuilder = router.CreateBuilder(handler.Object, "proxy"); proxyBuilder.MapFunctionRoute("proxy1", "proxy/{id}", null); proxyBuilder.MapFunctionRoute("proxy2", "proxy/dummy", null); router.AddFunctionRoutes(builder.Build(), proxyBuilder.Build()); var services = new ServiceCollection(); services.AddSingleton(Substitute.For <IApplicationLifetime>()); services.AddSingleton(router); services.AddSingleton(new RoutePriorityOptions { Comparison = DefaultRouteComparison.LiteralsFirst }); var optionsMonitor = new Mock <IOptionsMonitor <RoutePriorityOptions> >(); optionsMonitor.SetupGet(x => x.CurrentValue).Returns(new RoutePriorityOptions { Comparison = DefaultRouteComparison.LiteralsFirst }); services.AddSingleton(optionsMonitor.Object); var mockBuilder = new Mock <IWebJobsBuilder>(); mockBuilder.SetupGet(x => x.Services).Returns(services).Verifiable(); // act var actual = mockBuilder.Object.AddRoutePriority( o => o.Comparison = (Route x, Route y) => x.RouteTemplate.Length.CompareTo(y.RouteTemplate.Length) ); var routePriorityExtension = actual.Services.BuildServiceProvider().GetService <IExtensionConfigProvider>() as RoutePriorityExtensionConfigProvider; routePriorityExtension.ReorderRoutes(); // assert var routes = router.GetProxyRoutes().ToEnumerable(); Assert.Equal("proxy2", routes.First().Name); }
public void GetFunctionRoutes() { // Arrange var constraintResolver = new Mock <IInlineConstraintResolver>(); var handler = new Mock <IWebJobsRouteHandler>(); IWebJobsRouter router = new WebJobsRouter(constraintResolver.Object); var builder = router.CreateBuilder(handler.Object, "api"); builder.MapFunctionRoute("testfunction", "test/{token}", "testfunction"); router.AddFunctionRoutes(builder.Build(), null); // Act string routeTemplate = router.GetFunctionRouteTemplate("testfunction"); // Assert Assert.Equal("api/test/{token}", routeTemplate); }
public void CanGetRoutes() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoNSubstituteCustomization()); var constraintResolver = new Mock <IInlineConstraintResolver>(); var handler = new Mock <IWebJobsRouteHandler>(); var router = new WebJobsRouter(constraintResolver.Object); var builder = router.CreateBuilder(handler.Object, "api"); builder.MapFunctionRoute("testfunction", "test/{token}", "testfunction"); router.AddFunctionRoutes(builder.Build(), null); // act var routes = router.GetFunctionRoutes().ToEnumerable(); // assert Assert.Single(routes); }
public void CanOrderRoutes() { // arrange var fixture = new Fixture(); fixture.Customize(new AutoNSubstituteCustomization()); var constraintResolver = new Mock <IInlineConstraintResolver>(); constraintResolver.Setup(x => x.ResolveConstraint("int")).Returns(Substitute.For <IRouteConstraint>()); var handler = new Mock <IWebJobsRouteHandler>(); IWebJobsRouter router = new WebJobsRouter(constraintResolver.Object); var builder = router.CreateBuilder(handler.Object, "api"); builder.MapFunctionRoute("testfunction1", "test/{token}", "testfunction1"); builder.MapFunctionRoute("testfunction2", "test/{token:int}", "testfunction2"); builder.MapFunctionRoute("testfunction3", "test/abc", "testfunction3"); router.AddFunctionRoutes(builder.Build(), null); var optionsMonitor = new Mock <IOptionsMonitor <RoutePriorityOptions> >(); optionsMonitor.SetupGet(x => x.CurrentValue).Returns(new RoutePriorityOptions { Comparison = DefaultRouteComparison.LiteralsFirst }); // act var provider = new RoutePriorityExtensionConfigProvider(Substitute.For <IApplicationLifetime>(), router, optionsMonitor.Object); provider.ReorderRoutes(); var routes = router.GetFunctionRoutes().ToEnumerable().ToArray(); // assert Assert.Equal("testfunction3", routes[0].Name); Assert.Equal("testfunction2", routes[1].Name); Assert.Equal("testfunction1", routes[2].Name); }
public void GetFunctionWithCustomRoute() { var constraintResolver = new Mock <IInlineConstraintResolver>(); var handler = new Mock <IWebJobsRouteHandler>(); IWebJobsRouter router = new WebJobsRouter(constraintResolver.Object); var builder = router.CreateBuilder(handler.Object, "api"); builder.MapFunctionRoute("warmuproute", "warmup", "warmuproute"); var customBuilder = router.CreateBuilder(handler.Object, "admin"); customBuilder.MapFunctionRoute("warmup", "warmup", "warmup"); router.AddFunctionRoutes(builder.Build(), null); router.AddFunctionRoutes(customBuilder.Build(), null); string routeTemplate = router.GetFunctionRouteTemplate("warmuproute"); Assert.Equal("api/warmup", routeTemplate); routeTemplate = router.GetFunctionRouteTemplate("warmup"); Assert.Equal("admin/warmup", routeTemplate); }