コード例 #1
0
        public void Endpoints_AreaSingleAction(string endpointInfoRoute, string[] finalEndpointTemplates)
        {
            // Arrange
            var actionDescriptorCollection = GetActionDescriptorCollection(
                new { controller = "TestController", action = "TestAction", area = "TestArea" });
            var dataSource = CreateMvcEndpointDataSource(actionDescriptorCollection);

            var services = new ServiceCollection();

            services.AddRouting();
            services.AddSingleton(actionDescriptorCollection);

            var routeOptionsSetup = new MvcCoreRouteOptionsSetup();

            services.Configure <RouteOptions>(routeOptionsSetup.Configure);

            dataSource.ConventionalEndpointInfos.Add(CreateEndpointInfo(string.Empty, endpointInfoRoute, serviceProvider: services.BuildServiceProvider()));

            // Act
            var endpoints = dataSource.Endpoints;

            // Assert
            var inspectors = finalEndpointTemplates
                             .Select(t => new Action <Endpoint>(e => Assert.Equal(t, Assert.IsType <RouteEndpoint>(e).RoutePattern.RawText)))
                             .ToArray();

            // Assert
            Assert.Collection(endpoints, inspectors);
        }
コード例 #2
0
        private MvcEndpointInfo CreateEndpointInfo(
            string name,
            string template,
            RouteValueDictionary defaults            = null,
            IDictionary <string, object> constraints = null,
            RouteValueDictionary dataTokens          = null)
        {
            var routeOptions      = new RouteOptions();
            var routeOptionsSetup = new MvcCoreRouteOptionsSetup();

            routeOptionsSetup.Configure(routeOptions);

            var constraintResolver = new DefaultInlineConstraintResolver(Options.Create <RouteOptions>(routeOptions));

            return(new MvcEndpointInfo(name, template, defaults, constraints, dataTokens, constraintResolver));
        }
コード例 #3
0
        private MvcEndpointInfo CreateEndpointInfo(
            string name,
            string template,
            RouteValueDictionary defaults            = null,
            IDictionary <string, object> constraints = null,
            RouteValueDictionary dataTokens          = null)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddRouting();

            var routeOptionsSetup = new MvcCoreRouteOptionsSetup();

            serviceCollection.Configure <RouteOptions>(routeOptionsSetup.Configure);

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var parameterPolicyFactory = serviceProvider.GetRequiredService <ParameterPolicyFactory>();

            return(new MvcEndpointInfo(name, template, defaults, constraints, dataTokens, parameterPolicyFactory));
        }