Ejemplo n.º 1
0
        /// <summary>
        /// Runs the <see cref="TemplateRouteFetcher"/> with the specified route configuration.
        /// </summary>
        /// <param name="configure">Function to configure routes</param>
        /// <returns>List of routes returned from the route fetcher</returns>
        private static IList <RouteInfo> RunFetcher(Action <RouteBuilder> configure)
        {
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider.Setup(x => x.GetService(typeof(RoutingMarkerService)))
            .Returns(new Mock <RoutingMarkerService>().Object);
            serviceProvider.Setup(x => x.GetService(typeof(IInlineConstraintResolver)))
            .Returns(new Mock <IInlineConstraintResolver>().Object);

            var appBuilder = new Mock <IApplicationBuilder>();

            appBuilder.Setup(x => x.ApplicationServices).Returns(serviceProvider.Object);
            var routes = new RouteBuilder(appBuilder.Object)
            {
                DefaultHandler = new Mock <IRouter>().Object
            };

            configure(routes);

            var router    = routes.Build();
            var routeData = new RouteData();

            routeData.Routers.Add(router);

            var fetcher = new TemplateRouteFetcher(new Mock <IConstraintsProcessor>().Object, new RouteTemplateParser());

            return(fetcher.GetRoutes(routeData).ToList());
        }
		/// <summary>
		/// Runs the <see cref="TemplateRouteFetcher"/> with the specified route configuration.
		/// </summary>
		/// <param name="configure">Function to configure routes</param>
		/// <returns>List of routes returned from the route fetcher</returns>
		private static IList<RouteInfo> RunFetcher(Action<RouteBuilder> configure)
	    {
			var routes = new RouteBuilder();
			var serviceProvider = new Mock<IServiceProvider>();
			serviceProvider.Setup(x => x.GetService(typeof(IInlineConstraintResolver))).Returns(
				new Mock<IInlineConstraintResolver>().Object
			);
			routes.ServiceProvider = serviceProvider.Object;
			routes.DefaultHandler = new Mock<IRouter>().Object;
		    configure(routes);

			var router = routes.Build();
			var routeData = new RouteData();
			routeData.Routers.Add(router);

			var fetcher = new TemplateRouteFetcher(new Mock<IConstraintsProcessor>().Object, new RouteTemplateParser());
			return fetcher.GetRoutes(routeData).ToList();
		}