コード例 #1
0
        public void MapHttpAttributeRoutes_AddsMultipleRoutesFromAttributesAndPrefixes()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();
            var routePrefixes        = new Collection <RoutePrefixAttribute>()
            {
                new RoutePrefixAttribute("prefix1"), new RoutePrefixAttribute("prefix2")
            };
            var routeProviders = new Collection <IHttpRouteInfoProvider>()
            {
                new HttpGetAttribute("controller/get1"), new HttpGetAttribute("controller/get2")
            };

            SetUpConfiguration(config, routePrefixes, routeProviders);

            // Act
            config.MapHttpAttributeRoutes();

            // Assert
            HttpRouteCollection routes = config.Routes;

            Assert.Equal(4, routes.Count);
            Assert.Single(routes.Where(route => route.RouteTemplate == "prefix1/controller/get1"));
            Assert.Single(routes.Where(route => route.RouteTemplate == "prefix1/controller/get2"));
            Assert.Single(routes.Where(route => route.RouteTemplate == "prefix2/controller/get1"));
            Assert.Single(routes.Where(route => route.RouteTemplate == "prefix2/controller/get2"));
        }
コード例 #2
0
 public IEnumerable <IHttpRoute> GetAllRoutes() => _httpRouteCollection.Where(r => r.IsOpenApiMetadataRoute());