Exemplo n.º 1
0
        private static IServiceProvider CreateServices(params ActionDescriptor[] actions)
        {
            var collection = new ActionDescriptorsCollection(actions, version: 0);

            var actionDescriptorProvider = new Mock <IActionDescriptorsCollectionProvider>();

            actionDescriptorProvider
            .Setup(a => a.ActionDescriptors)
            .Returns(collection);

            var services = new Mock <IServiceProvider>();

            services
            .Setup(s => s.GetService(typeof(IActionDescriptorsCollectionProvider)))
            .Returns(actionDescriptorProvider.Object);

            var routeOptions = new Mock <IOptions <RouteOptions> >();

            routeOptions
            .SetupGet(o => o.Value)
            .Returns(new RouteOptions());

            services
            .Setup(s => s.GetService(typeof(IInlineConstraintResolver)))
            .Returns(new DefaultInlineConstraintResolver(routeOptions.Object));

            services
            .Setup(s => s.GetService(typeof(ILoggerFactory)))
            .Returns(NullLoggerFactory.Instance);

            return(services.Object);
        }
        /// <summary>
        /// Creates a new <see cref="ActionSelectionDecisionTree"/>.
        /// </summary>
        /// <param name="actions">The <see cref="ActionDescriptorsCollection"/>.</param>
        public ActionSelectionDecisionTree(ActionDescriptorsCollection actions)
        {
            Version = actions.Version;

            _root = DecisionTreeBuilder <ActionDescriptor> .GenerateTree(
                actions.Items,
                new ActionDescriptorClassifier());
        }
Exemplo n.º 3
0
        private InnerAttributeRoute BuildRoute(ActionDescriptorsCollection actions)
        {
            var routeInfos = GetRouteInfos(_constraintResolver, actions.Items);

            // We're creating one AttributeRouteGenerationEntry per action. This allows us to match the intended
            // action by expected route values, and then use the TemplateBinder to generate the link.
            var generationEntries = new List <AttributeRouteLinkGenerationEntry>();

            foreach (var routeInfo in routeInfos)
            {
                generationEntries.Add(new AttributeRouteLinkGenerationEntry()
                {
                    Binder             = new TemplateBinder(routeInfo.ParsedTemplate, routeInfo.Defaults),
                    Defaults           = routeInfo.Defaults,
                    Constraints        = routeInfo.Constraints,
                    Order              = routeInfo.Order,
                    Precedence         = routeInfo.Precedence,
                    RequiredLinkValues = routeInfo.ActionDescriptor.RouteValueDefaults,
                    RouteGroup         = routeInfo.RouteGroup,
                    Template           = routeInfo.ParsedTemplate,
                    TemplateText       = routeInfo.RouteTemplate,
                    Name = routeInfo.Name,
                });
            }

            // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of
            // groups. It's guaranteed that all members of the group have the same template and precedence,
            // so we only need to hang on to a single instance of the RouteInfo for each group.
            var distinctRouteInfosByGroup = GroupRouteInfosByGroupId(routeInfos);
            var matchingEntries           = new List <AttributeRouteMatchingEntry>();

            foreach (var routeInfo in distinctRouteInfosByGroup)
            {
                matchingEntries.Add(new AttributeRouteMatchingEntry()
                {
                    Order           = routeInfo.Order,
                    Precedence      = routeInfo.Precedence,
                    Target          = _target,
                    RouteName       = routeInfo.Name,
                    RouteTemplate   = routeInfo.RouteTemplate,
                    TemplateMatcher = new TemplateMatcher(
                        routeInfo.ParsedTemplate,
                        new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
                    {
                        { AttributeRouting.RouteGroupKey, routeInfo.RouteGroup }
                    }),
                    Constraints = routeInfo.Constraints
                });
            }

            return(new InnerAttributeRoute(
                       _target,
                       matchingEntries,
                       generationEntries,
                       _routeLogger,
                       _constraintLogger,
                       actions.Version));
        }
Exemplo n.º 4
0
        private InnerAttributeRoute BuildRoute(ActionDescriptorsCollection actions)
        {
            var routeInfos = GetRouteInfos(_constraintResolver, actions.Items);

            // We're creating one AttributeRouteGenerationEntry per action. This allows us to match the intended
            // action by expected route values, and then use the TemplateBinder to generate the link.
            var generationEntries = new List<AttributeRouteLinkGenerationEntry>();
            foreach (var routeInfo in routeInfos)
            {
                generationEntries.Add(new AttributeRouteLinkGenerationEntry()
                {
                    Binder = new TemplateBinder(routeInfo.ParsedTemplate, routeInfo.Defaults),
                    Defaults = routeInfo.Defaults,
                    Constraints = routeInfo.Constraints,
                    Order = routeInfo.Order,
                    Precedence = routeInfo.Precedence,
                    RequiredLinkValues = routeInfo.ActionDescriptor.RouteValueDefaults,
                    RouteGroup = routeInfo.RouteGroup,
                    Template = routeInfo.ParsedTemplate,
                    TemplateText = routeInfo.RouteTemplate,
                    Name = routeInfo.Name,
                });
            }

            // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of
            // groups. It's guaranteed that all members of the group have the same template and precedence,
            // so we only need to hang on to a single instance of the RouteInfo for each group.
            var distinctRouteInfosByGroup = GroupRouteInfosByGroupId(routeInfos);
            var matchingEntries = new List<AttributeRouteMatchingEntry>();
            foreach (var routeInfo in distinctRouteInfosByGroup)
            {
                matchingEntries.Add(new AttributeRouteMatchingEntry()
                {
                    Order = routeInfo.Order,
                    Precedence = routeInfo.Precedence,
                    Target = _target,
                    RouteName = routeInfo.Name,
                    RouteTemplate = routeInfo.RouteTemplate,
                    TemplateMatcher = new TemplateMatcher(
                        routeInfo.ParsedTemplate,
                        new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
                        {
                            { AttributeRouting.RouteGroupKey, routeInfo.RouteGroup }
                        }),
                    Constraints = routeInfo.Constraints
                });
            }

            return new InnerAttributeRoute(
                _target,
                matchingEntries,
                generationEntries,
                _routeLogger,
                _constraintLogger,
                actions.Version);
        }
Exemplo n.º 5
0
        private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors)
        {
            var context = new ApiDescriptionProviderContext(actionDescriptors.Items);

            _apiDescriptionProvider.Invoke(context);

            var groups = context.Results
                         .GroupBy(d => d.GroupName)
                         .Select(g => new ApiDescriptionGroup(g.Key, g.ToArray()))
                         .ToArray();

            return(new ApiDescriptionGroupCollection(groups, actionDescriptors.Version));
        }
        private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors)
        {
            var context = new ApiDescriptionProviderContext(actionDescriptors.Items);

            foreach (var provider in _apiDescriptionProviders)
            {
                provider.OnProvidersExecuting(context);
            }

            for (var i = _apiDescriptionProviders.Length - 1; i >= 0; i--)
            {
                _apiDescriptionProviders[i].OnProvidersExecuted(context);
            }

            var groups = context.Results
                         .GroupBy(d => d.GroupName)
                         .Select(g => new ApiDescriptionGroup(g.Key, g.ToArray()))
                         .ToArray();

            return(new ApiDescriptionGroupCollection(groups, actionDescriptors.Version));
        }
        private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors)
        {
            var context = new ApiDescriptionProviderContext(actionDescriptors.Items);

            foreach (var provider in _apiDescriptionProviders)
            {
                provider.OnProvidersExecuting(context);
            }

            for (var i = _apiDescriptionProviders.Length - 1; i >= 0; i--)
            {
                _apiDescriptionProviders[i].OnProvidersExecuted(context);
            }

            var groups = context.Results
                .GroupBy(d => d.GroupName)
                .Select(g => new ApiDescriptionGroup(g.Key, g.ToArray()))
                .ToArray();

            return new ApiDescriptionGroupCollection(groups, actionDescriptors.Version);
        }
Exemplo n.º 8
0
        private static IServiceProvider CreateServices(params ActionDescriptor[] actions)
        {
            var collection = new ActionDescriptorsCollection(actions, version: 0);

            var actionDescriptorProvider = new Mock<IActionDescriptorsCollectionProvider>();
            actionDescriptorProvider
                .Setup(a => a.ActionDescriptors)
                .Returns(collection);

            var services = new Mock<IServiceProvider>();
            services
                .Setup(s => s.GetService(typeof(IActionDescriptorsCollectionProvider)))
                .Returns(actionDescriptorProvider.Object);

            var routeOptions = new Mock<IOptions<RouteOptions>>();
            routeOptions
                .SetupGet(o => o.Options)
                .Returns(new RouteOptions());

            services
                .Setup(s => s.GetService(typeof(IInlineConstraintResolver)))
                .Returns(new DefaultInlineConstraintResolver(routeOptions.Object));

            services
                .Setup(s => s.GetService(typeof(ILoggerFactory)))
                .Returns(NullLoggerFactory.Instance);

            return services.Object;
        }