public void AddressScheme_NoMatch_CaseSensitive()
        {
            // Arrange
            var endpoint = EndpointFactory.CreateRouteEndpoint(
                "/a",
                metadata: new object[] { new EndpointNameMetadata("name1"), new SuppressLinkGenerationMetadata(), });

            var addressScheme = CreateAddressScheme(endpoint);

            // Act
            var endpoints = addressScheme.FindEndpoints("NAME1");

            // Assert
            Assert.Empty(endpoints);
        }
Exemple #2
0
        public void GetPathByRouteValues_UsesFirstTemplateThatSucceeds(string[] routeNames, string[] routeValues, string expectedPath)
        {
            // Arrange
            var endpointControllerAction = EndpointFactory.CreateRouteEndpoint(
                "Home/Index",
                order: 3,
                defaults: new { controller = "Home", action = "Index", },
                requiredValues: new { controller = "Home", action = "Index", });
            var endpointController = EndpointFactory.CreateRouteEndpoint(
                "Home",
                order: 2,
                defaults: new { controller = "Home", action = "Index", },
                requiredValues: new { controller = "Home", action = "Index", });
            var endpointEmpty = EndpointFactory.CreateRouteEndpoint(
                "",
                order: 1,
                defaults: new { controller = "Home", action = "Index", },
                requiredValues: new { controller = "Home", action = "Index", });

            // This endpoint should be used to generate the link when an id is present
            var endpointControllerActionParameter = EndpointFactory.CreateRouteEndpoint(
                "Home/Index/{id}",
                order: 0,
                defaults: new { controller = "Home", action = "Index", },
                requiredValues: new { controller = "Home", action = "Index", });

            var linkGenerator = CreateLinkGenerator(endpointControllerAction, endpointController, endpointEmpty, endpointControllerActionParameter);

            var httpContext = CreateHttpContext();

            httpContext.Request.RouteValues = new RouteValueDictionary(new { controller = "Home", action = "Index" });

            var values = new RouteValueDictionary();

            for (int i = 0; i < routeNames.Length; i++)
            {
                values[routeNames[i]] = routeValues[i];
            }

            // Act
            var generatedPath = linkGenerator.GetPathByRouteValues(
                httpContext,
                routeName: null,
                values: values);

            // Assert
            Assert.Equal(expectedPath, generatedPath);
        }
        public void GetTemplateBinder_CanCache()
        {
            // Arrange
            var endpoint1  = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var dataSource = new DynamicEndpointDataSource(endpoint1);

            var linkGenerator = CreateLinkGenerator(dataSources: new[] { dataSource });

            var expected = linkGenerator.GetTemplateBinder(endpoint1);

            // Act
            var actual = linkGenerator.GetTemplateBinder(endpoint1);

            // Assert
            Assert.Same(expected, actual);
        }
        public void GetRoutePatternMatcher_CanCache()
        {
            // Arrange
            var endpoint1  = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var dataSource = new DynamicEndpointDataSource(endpoint1);

            var parser = CreateLinkParser(dataSources: new[] { dataSource });

            var expected = parser.GetMatcherState(endpoint1);

            // Act
            var actual = parser.GetMatcherState(endpoint1);

            // Assert
            Assert.Same(expected.Matcher, actual.Matcher);
            Assert.Same(expected.Constraints, actual.Constraints);
        }
        public void GetPathByAddress_WithoutHttpContext_WithPathBaseAndFragment()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            // Act
            var path = linkGenerator.GetPathByAddress(
                1,
                values: new RouteValueDictionary(new { controller = "Home", action = "In?dex", query = "some?query" }),
                new PathString("/Foo/Bar?encodeme?"),
                new FragmentString("#Fragment?"));

            // Assert
            Assert.Equal("/Foo/Bar%3Fencodeme%3F/Home/In%3Fdex?query=some%3Fquery#Fragment?", path);
        }
        public void GetUriByAddress_WithoutHttpContext_HasMatches_ReturnsFirstSuccessfulTemplateResult()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            // Act
            var path = linkGenerator.GetUriByAddress(
                1,
                values: new RouteValueDictionary(new { controller = "Home", action = "Index", }),
                "http",
                new HostString("example.com"));

            // Assert
            Assert.Equal("http://example.com/Home/Index", path);
        }
        public void ParsePathByAddresss_NoMatchingEndpoint_ReturnsNull()
        {
            // Arrange
            var endpoint = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", displayName: "Test1", metadata: new object[] { new IntMetadata(1), });

            var sink          = new TestSink();
            var loggerFactory = new TestLoggerFactory(sink, enabled: true);
            var parser        = CreateLinkParser(services => { services.AddSingleton <ILoggerFactory>(loggerFactory); }, endpoint);

            // Act
            var values = parser.ParsePathByAddress(0, "/Home/Index/17");

            // Assert
            Assert.Null(values);

            Assert.Collection(
                sink.Writes,
                w => Assert.Equal("No endpoints found for address 0", w.Message));
        }
        public void GetPathByAddress_WithoutHttpContext_WithLinkOptions()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            // Act
            var path = linkGenerator.GetPathByAddress(
                1,
                values: new RouteValueDictionary(new { controller = "Home", action = "Index", }),
                options: new LinkOptions()
            {
                AppendTrailingSlash = true,
            });

            // Assert
            Assert.Equal("/Home/Index/", path);
        }
Exemple #9
0
        public void GetPathByAddress_WithParameterTransformer()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller:slugify}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller:slugify}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var routeOptions = new RouteOptions();

            routeOptions.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer);

            var linkGenerator = CreateLinkGenerator(routeOptions: routeOptions, configureServices: null, endpoint1, endpoint2);

            // Act
            var path = linkGenerator.GetPathByAddress(
                1,
                values: new RouteValueDictionary(new { controller = "TestController", action = "Index", }));

            // Assert
            Assert.Equal("/test-controller/Index", path);
        }
        public void GetLink_ParameterTransformer()
        {
            // Arrange
            var endpoint = EndpointFactory.CreateRouteEndpoint("{controller:upper-case}/{name}", requiredValues: new { controller = "Home", name = "Test" });

            Action <IServiceCollection> configure = (s) =>
            {
                s.Configure <RouteOptions>(o =>
                {
                    o.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform);
                });
            };

            var linkGenerator = CreateLinkGenerator(configure, endpoint);

            // Act
            var link = linkGenerator.GetPathByRouteValues(routeName: null, new { controller = "Home", name = "Test" });

            // Assert
            Assert.Equal("/HOME/Test", link);
        }
        public void AddressScheme_Match_ReturnsMatchingEndpoint()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint(
                "/a",
                metadata: new object[] { new EndpointNameMetadata("name1"), });

            var endpoint2 = EndpointFactory.CreateRouteEndpoint(
                "/b",
                metadata: new object[] { new EndpointNameMetadata("name2"), });

            var addressScheme = CreateAddressScheme(endpoint1, endpoint2);

            // Act
            var endpoints = addressScheme.FindEndpoints("name2");

            // Assert
            Assert.Collection(
                endpoints,
                e => Assert.Same(endpoint2, e));
        }
        public void ParsePathByAddresss_HasMatches_ReturnsNullWhenParsingFails()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", displayName: "Test1", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id2}", displayName: "Test2", metadata: new object[] { new IntMetadata(0), });

            var sink          = new TestSink();
            var loggerFactory = new TestLoggerFactory(sink, enabled: true);
            var parser        = CreateLinkParser(services => { services.AddSingleton <ILoggerFactory>(loggerFactory); }, endpoint1, endpoint2);

            // Act
            var values = parser.ParsePathByAddress(0, "/");

            // Assert
            Assert.Null(values);

            Assert.Collection(
                sink.Writes,
                w => Assert.Equal("Found the endpoints Test2 for address 0", w.Message),
                w => Assert.Equal("Path parsing failed for endpoints Test2 and URI path /", w.Message));
        }
        public void ParsePathByAddresss_HasMatches_ReturnsFirstSuccessfulParse()
        {
            // Arrange
            var endpoint0 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}", displayName: "Test1", metadata: new object[] { new IntMetadata(0), });
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", displayName: "Test2", metadata: new object[] { new IntMetadata(0), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id2}", displayName: "Test3", metadata: new object[] { new IntMetadata(0), });

            var sink          = new TestSink();
            var loggerFactory = new TestLoggerFactory(sink, enabled: true);
            var parser        = CreateLinkParser(services => { services.AddSingleton <ILoggerFactory>(loggerFactory); }, endpoint0, endpoint1, endpoint2);

            // Act
            var values = parser.ParsePathByAddress(0, "/Home/Index/17");

            // Assert
            MatcherAssert.AssertRouteValuesEqual(new { controller = "Home", action = "Index", id = "17" }, values);

            Assert.Collection(
                sink.Writes,
                w => Assert.Equal("Found the endpoints Test1, Test2, Test3 for address 0", w.Message),
                w => Assert.Equal("Path parsing succeeded for endpoint Test2 and URI path /Home/Index/17", w.Message));
        }
Exemple #14
0
        public void GetLink_ParameterTransformer_ForQueryString()
        {
            // Arrange
            var endpoint = EndpointFactory.CreateRouteEndpoint("{controller:upper-case}/{name}", policies: new { c = new UpperCaseParameterTransform(), });

            var routeOptions = new RouteOptions();

            routeOptions.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform);

            Action <IServiceCollection> configure = (s) =>
            {
                s.AddSingleton(typeof(UpperCaseParameterTransform), new UpperCaseParameterTransform());
            };

            var linkGenerator = CreateLinkGenerator(routeOptions, configure, endpoint);

            // Act
            var link = linkGenerator.GetPathByRouteValues(routeName: null, new { controller = "Home", name = "Test", c = "hithere", });

            // Assert
            Assert.Equal("/HOME/Test?c=HITHERE", link);
        }
        public void GetPathByAddress_WithHttpContext_CanOverrideUriParts()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            var httpContext = CreateHttpContext();

            httpContext.Request.PathBase = "/Foo";

            // Act
            var uri = linkGenerator.GetPathByAddress(
                httpContext,
                1,
                values: new RouteValueDictionary(new { action = "Index", controller = "Home", }),
                pathBase: "/");

            // Assert
            Assert.Equal("/Home/Index", uri);
        }
        public void GetPathByRouteValues_ParameterMatchesRequireValues_HasAmbientValues(string[] routeNames, string[] routeValues, string expectedPath)
        {
            // Arrange
            var homeIndex = EndpointFactory.CreateRouteEndpoint(
                "{controller}/{action}/{id?}",
                defaults: new { controller = "Home", action = "Index", },
                metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) });
            var homeLogin = EndpointFactory.CreateRouteEndpoint(
                "{controller}/{action}/{id?}",
                defaults: new { controller = "Home", action = "Index", },
                metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Login", })) });

            var linkGenerator = CreateLinkGenerator(homeIndex, homeLogin);

            var context = new EndpointSelectorContext()
            {
                RouteValues = new RouteValueDictionary(new { controller = "Home", action = "Index", })
            };
            var httpContext = CreateHttpContext();

            httpContext.Features.Set <IRouteValuesFeature>(context);

            var values = new RouteValueDictionary();

            for (int i = 0; i < routeNames.Length; i++)
            {
                values[routeNames[i]] = routeValues[i];
            }

            // Act
            var generatedPath = linkGenerator.GetPathByRouteValues(
                httpContext,
                routeName: null,
                values: values);

            // Assert
            Assert.Equal(expectedPath, generatedPath);
        }
        public void GetUriByAddress_WithHttpContext_IncludesAmbientValues()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            var httpContext = CreateHttpContext();

            httpContext.Request.Scheme = "http";
            httpContext.Request.Host   = new HostString("example.com");

            // Act
            var uri = linkGenerator.GetUriByAddress(
                httpContext,
                1,
                values: new RouteValueDictionary(new { action = "Index", }),
                ambientValues: new RouteValueDictionary(new { controller = "Home", }));

            // Assert
            Assert.Equal("http://example.com/Home/Index", uri);
        }
Exemple #18
0
        public void GetPathByRouteValues_WithHttpContext_UsesAmbientValues()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint(
                "Home/Index/{id}",
                defaults: new { controller = "Home", action = "Index", },
                metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint(
                "Home/Index/{id?}",
                defaults: new { controller = "Home", action = "Index", },
                metadata: new[] { new RouteValuesAddressMetadata(new RouteValueDictionary(new { controller = "Home", action = "Index", })) });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            var context = new EndpointSelectorContext()
            {
                RouteValues = new RouteValueDictionary(new { action = "Index", })
            };
            var httpContext = CreateHttpContext();

            httpContext.Features.Set <IRouteValuesFeature>(context);
            httpContext.Request.PathBase = new PathString("/Foo/Bar?encodeme?");

            // Act
            var path = linkGenerator.GetPathByRouteValues(
                httpContext,
                routeName: null,
                values: new RouteValueDictionary(new { controller = "Home", query = "some?query" }),
                fragment: new FragmentString("#Fragment?"),
                options: new LinkOptions()
            {
                AppendTrailingSlash = true,
            });

            // Assert
            Assert.Equal("/Foo/Bar%3Fencodeme%3F/Home/Index/?query=some%3Fquery#Fragment?", path);
        }
        public void AddressScheme_UpdatesWhenDataSourceChanges()
        {
            var endpoint1 = EndpointFactory.CreateRouteEndpoint(
                "/a",
                metadata: new object[] { new EndpointNameMetadata("name1"), });
            var dynamicDataSource = new DynamicEndpointDataSource(new[] { endpoint1 });

            // Act 1
            var addressScheme = CreateAddressScheme(dynamicDataSource);

            // Assert 1
            var match = Assert.Single(addressScheme.Entries);

            Assert.Same(endpoint1, match.Value.Single());

            // Arrange 2
            var endpoint2 = EndpointFactory.CreateRouteEndpoint(
                "/b",
                metadata: new object[] { new EndpointNameMetadata("name2"), });

            // Act 2
            // Trigger change
            dynamicDataSource.AddEndpoint(endpoint2);

            // Assert 2
            Assert.Collection(
                addressScheme.Entries.OrderBy(kvp => kvp.Key),
                (m) =>
            {
                Assert.Same(endpoint1, m.Value.Single());
            },
                (m) =>
            {
                Assert.Same(endpoint2, m.Value.Single());
            });
        }
        public void GetUriByAddress_WithHttpContext_WithPathBaseAndFragment()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id}", metadata: new object[] { new IntMetadata(1), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            var httpContext = CreateHttpContext();

            httpContext.Request.Scheme   = "http";
            httpContext.Request.Host     = new HostString("example.com");
            httpContext.Request.PathBase = new PathString("/Foo/Bar?encodeme?");

            // Act
            var uri = linkGenerator.GetUriByAddress(
                httpContext,
                1,
                values: new RouteValueDictionary(new { controller = "Home", action = "In?dex", query = "some?query" }),
                fragment: new FragmentString("#Fragment?"));

            // Assert
            Assert.Equal("http://example.com/Foo/Bar%3Fencodeme%3F/Home/In%3Fdex?query=some%3Fquery#Fragment?", uri);
        }
        public void GetPathByName_WithoutHttpContext_WithPathBaseAndFragment()
        {
            // Arrange
            var endpoint1 = EndpointFactory.CreateRouteEndpoint("some-endpoint/{p}", metadata: new[] { new EndpointNameMetadata("name1"), });
            var endpoint2 = EndpointFactory.CreateRouteEndpoint("some#-other-endpoint/{p}", metadata: new[] { new EndpointNameMetadata("name2"), });

            var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);

            var values = new { p = "In?dex", query = "some?query", };

            // Act
            var path = linkGenerator.GetPathByName(
                endpointName: "name2",
                values,
                new PathString("/Foo/Bar?encodeme?"),
                new FragmentString("#Fragment?"),
                new LinkOptions()
            {
                AppendTrailingSlash = true,
            });

            // Assert
            Assert.Equal("/Foo/Bar%3Fencodeme%3F/some%23-other-endpoint/In%3Fdex/?query=some%3Fquery#Fragment?", path);
        }
Exemple #22
0
        public void GetPathByAddress_WithHttpContext_ContextPassedToConstraint()
        {
            // Arrange
            var constraint = new TestRouteConstraint();

            var endpoint1 = EndpointFactory.CreateRouteEndpoint("{controller}/{action}/{id?}", policies: new { controller = constraint }, metadata: new object[] { new IntMetadata(1), });

            var linkGenerator = CreateLinkGenerator(endpoint1);

            var httpContext = CreateHttpContext();

            httpContext.Request.PathBase = "/Foo";

            // Act
            var uri = linkGenerator.GetPathByAddress(
                httpContext,
                1,
                values: new RouteValueDictionary(new { action = "Index", controller = "Home", }),
                pathBase: "/");

            // Assert
            Assert.Equal("/Home/Index", uri);
            Assert.True(constraint.HasHttpContext);
        }
Exemple #23
0
        public LinkGeneratorIntegrationTest()
        {
            var endpoints = new List <Endpoint>()
            {
                // Attribute routed endpoint 1
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/Pets/{id}",
                        defaults: new { controller = "Pets", action = "GetById", },
                        parameterPolicies: null,
                        requiredValues: new { controller = "Pets", action = "GetById", area = (string)null, page = (string)null, }),
                    order: 0),

                // Attribute routed endpoint 2
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/Pets",
                        defaults: new { controller = "Pets", action = "GetAll", },
                        parameterPolicies: null,
                        requiredValues: new { controller = "Pets", action = "GetAll", area = (string)null, page = (string)null, }),
                    order: 0),

                // Attribute routed endpoint 2
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/Pets/{id}",
                        defaults: new { controller = "Pets", action = "Update", },
                        parameterPolicies: null,
                        requiredValues: new { controller = "Pets", action = "Update", area = (string)null, page = (string)null, }),
                    order: 0),

                // Attribute routed endpoint 4
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/Inventory/{searchTerm}/{page}",
                        defaults: new { controller = "Inventory", action = "Search", },
                        parameterPolicies: null,
                        requiredValues: new { controller = "Inventory", action = "Search", area = (string)null, page = (string)null, }),
                    order: 0),

                // Conventional routed endpoint 1
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "{controller=Home}/{action=Index}/{id?}",
                        defaults: null,
                        parameterPolicies: null,
                        requiredValues: new { controller = "Home", action = "Index", area = (string)null, page = (string)null, }),
                    order: 2000,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Conventional routed endpoint 2
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "{controller=Home}/{action=Index}/{id?}",
                        defaults: null,
                        parameterPolicies: null,
                        requiredValues: new { controller = "Home", action = "About", area = (string)null, page = (string)null, }),
                    order: 2000,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Conventional routed endpoint 3
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "{controller=Home}/{action=Index}/{id?}",
                        defaults: null,
                        parameterPolicies: null,
                        requiredValues: new { controller = "Store", action = "Browse", area = (string)null, page = (string)null, }),
                    order: 2000,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Conventional routed link generation route 1
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "{controller=Home}/{action=Index}/{id?}",
                        defaults: null,
                        parameterPolicies: null,
                        requiredValues: new { controller = RoutePattern.RequiredValueAny, action = RoutePattern.RequiredValueAny, area = (string)null, page = (string)null, }),
                    order: 2000,
                    metadata: new object[] { new SuppressMatchingMetadata(), }),

                // Conventional routed endpoint 4 (with area)
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Admin/{controller=Home}/{action=Index}/{id?}",
                        defaults: new { area = "Admin", },
                        parameterPolicies: new { controller = "Admin", },
                        requiredValues: new { area = "Admin", controller = "Users", action = "Add", page = (string)null, }),
                    order: 1000,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Conventional routed endpoint 5 (with area)
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Admin/{controller=Home}/{action=Index}/{id?}",
                        defaults: new { area = "Admin", },
                        parameterPolicies: new { controller = "Admin", },
                        requiredValues: new { area = "Admin", controller = "Users", action = "Remove", page = (string)null, }),
                    order: 1000,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Conventional routed link generation route 2
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Admin/{controller=Home}/{action=Index}/{id?}",
                        defaults: new { area = "Admin", },
                        parameterPolicies: new { area = "Admin", },
                        requiredValues: new { controller = RoutePattern.RequiredValueAny, action = RoutePattern.RequiredValueAny, area = "Admin", page = (string)null, }),
                    order: 1000,
                    metadata: new object[] { new SuppressMatchingMetadata(), }),

                // Conventional routed link generation route 3 - this doesn't match any actions.
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/{controller}/{id?}",
                        defaults: new { },
                        parameterPolicies: new { },
                        requiredValues: new { controller = RoutePattern.RequiredValueAny, action = (string)null, area = (string)null, page = (string)null, }),
                    order: 3000,
                    metadata: new object[] { new SuppressMatchingMetadata(), new RouteNameMetadata("custom"), }),

                // Conventional routed link generation route 3 - this doesn't match any actions.
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "api/Foo/{custom2}",
                        defaults: new { },
                        parameterPolicies: new { },
                        requiredValues: new { controller = (string)null, action = (string)null, area = (string)null, page = (string)null, }),
                    order: 3000,
                    metadata: new object[] { new SuppressMatchingMetadata(), new RouteNameMetadata("custom2"), }),

                // Razor Page 1 primary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Pages",
                        defaults: new { page = "/Pages/Index", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = (string)null, page = "/Pages/Index", }),
                    order: 0),

                // Razor Page 1 secondary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Pages/Index",
                        defaults: new { page = "/Pages/Index", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = (string)null, page = "/Pages/Index", }),
                    order: 0,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),

                // Razor Page 2 primary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Pages/Help/{id?}",
                        defaults: new { page = "/Pages/Help", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = (string)null, page = "/Pages/Help", }),
                    order: 0),

                // Razor Page 3 primary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Pages/About/{id?}",
                        defaults: new { page = "/Pages/About", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = (string)null, page = "/Pages/About", }),
                    order: 0),

                // Razor Page 4 with area primary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Admin/Pages",
                        defaults: new { page = "/Pages/Index", area = "Admin", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = "Admin", page = "/Pages/Index", }),
                    order: 0),

                // Razor Page 4 with area secondary endpoint
                EndpointFactory.CreateRouteEndpoint(
                    RoutePatternFactory.Parse(
                        "Admin/Pages/Index",
                        defaults: new { page = "/Pages/Index", area = "Admin", },
                        parameterPolicies: null,
                        requiredValues: new { controller = (string)null, action = (string)null, area = "Admin", page = "/Pages/Index", }),
                    order: 0,
                    metadata: new object[] { new SuppressLinkGenerationMetadata(), }),
            };

            Endpoints     = endpoints;
            LinkGenerator = CreateLinkGenerator(endpoints.ToArray());
        }