Пример #1
0
        private static ControllerActionInvokerCache CreateCache(params IFilterProvider[] providers)
        {
            var services           = CreateServices();
            var descriptorProvider = new ActionDescriptorCollectionProvider(services);

            return(new ControllerActionInvokerCache(descriptorProvider, providers));
        }
Пример #2
0
        private static ActionConstraintCache CreateCache(params IActionConstraintProvider[] providers)
        {
            var services           = CreateServices();
            var descriptorProvider = new ActionDescriptorCollectionProvider(services);

            return(new ActionConstraintCache(descriptorProvider, providers));
        }
        public void ActionDescriptors_ReadsDescriptorsFromActionDescriptorProviders()
        {
            // Arrange
            var expected1 = new ActionDescriptor();
            var actionDescriptorProvider1 = GetActionDescriptorProvider(expected1);

            var expected2 = new ActionDescriptor();
            var expected3 = new ActionDescriptor();
            var actionDescriptorProvider2 = GetActionDescriptorProvider(expected2, expected3);

            var actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(
                new[] { actionDescriptorProvider1, actionDescriptorProvider2 },
                Enumerable.Empty <IActionDescriptorChangeProvider>());

            // Act
            var collection = actionDescriptorCollectionProvider.ActionDescriptors;

            // Assert
            Assert.Equal(0, collection.Version);
            Assert.Collection(
                collection.Items,
                descriptor => Assert.Same(expected1, descriptor),
                descriptor => Assert.Same(expected2, descriptor),
                descriptor => Assert.Same(expected3, descriptor));
        }
Пример #4
0
        private static ActionConstraintCache CreateCache(params IActionConstraintProvider[] providers)
        {
            var descriptorProvider = new ActionDescriptorCollectionProvider(
                Enumerable.Empty <IActionDescriptorProvider>(),
                Enumerable.Empty <IActionDescriptorChangeProvider>());

            return(new ActionConstraintCache(descriptorProvider, providers));
        }
Пример #5
0
        private static ControllerActionInvokerCache CreateFilterCache(IFilterProvider[] filterProviders = null)
        {
            var services           = new ServiceCollection().BuildServiceProvider();
            var descriptorProvider = new ActionDescriptorCollectionProvider(services);

            return(new ControllerActionInvokerCache(
                       descriptorProvider,
                       filterProviders.AsEnumerable() ?? new List <IFilterProvider>()));
        }
        public void ActionDescriptors_UpdateWhenChangeTokenProviderChanges()
        {
            // Arrange
            var actionDescriptorProvider = new Mock <IActionDescriptorProvider>();
            var expected1 = new ActionDescriptor();
            var expected2 = new ActionDescriptor();

            var invocations = 0;

            actionDescriptorProvider
            .Setup(p => p.OnProvidersExecuting(It.IsAny <ActionDescriptorProviderContext>()))
            .Callback((ActionDescriptorProviderContext context) =>
            {
                if (invocations == 0)
                {
                    context.Results.Add(expected1);
                }
                else
                {
                    context.Results.Add(expected2);
                }

                invocations++;
            });
            var changeProvider = new TestChangeProvider();
            var actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(
                new[] { actionDescriptorProvider.Object },
                new[] { changeProvider });

            // Act - 1
            var collection1 = actionDescriptorCollectionProvider.ActionDescriptors;

            // Assert - 1
            Assert.Equal(0, collection1.Version);
            Assert.Collection(collection1.Items,
                              item => Assert.Same(expected1, item));

            // Act - 2
            changeProvider.TokenSource.Cancel();
            var collection2 = actionDescriptorCollectionProvider.ActionDescriptors;

            // Assert - 2
            Assert.NotSame(collection1, collection2);
            Assert.Equal(1, collection2.Version);
            Assert.Collection(collection2.Items,
                              item => Assert.Same(expected2, item));
        }
        public void ActionDescriptors_CachesValuesByDefault()
        {
            // Arrange
            var actionDescriptorProvider = GetActionDescriptorProvider(new ActionDescriptor());

            var actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(
                new[] { actionDescriptorProvider },
                Enumerable.Empty <IActionDescriptorChangeProvider>());

            // Act - 1
            var collection1 = actionDescriptorCollectionProvider.ActionDescriptors;

            // Assert - 1
            Assert.Equal(0, collection1.Version);

            // Act - 2
            var collection2 = actionDescriptorCollectionProvider.ActionDescriptors;

            // Assert - 2
            Assert.Same(collection1, collection2);
            Mock.Get(actionDescriptorProvider)
            .Verify(v => v.OnProvidersExecuting(It.IsAny <ActionDescriptorProviderContext>()), Times.Once());
        }
Пример #8
0
        private ControllerActionDescriptor InvokeActionSelector(RouteContext context)
        {
            var actionDescriptorProvider = GetActionDescriptorProvider();

            var serviceContainer = new ServiceCollection();
            var list = new List<IActionDescriptorProvider>()
            {
                actionDescriptorProvider,
            };

            serviceContainer.AddSingleton(typeof(IEnumerable<IActionDescriptorProvider>), list);

            var actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(
                serviceContainer.BuildServiceProvider());
            var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionDescriptorCollectionProvider);

            var actionConstraintProviders = new[]
            {
                new DefaultActionConstraintProvider(),
            };

            var actionSelector = new ActionSelector(
                decisionTreeProvider,
                GetActionConstraintCache(actionConstraintProviders),
                NullLoggerFactory.Instance);

            var candidates = actionSelector.SelectCandidates(context);
            return (ControllerActionDescriptor)actionSelector.SelectBestCandidate(context, candidates);
        }
Пример #9
0
 private static ActionConstraintCache GetActionConstraintCache(IActionConstraintProvider[] actionConstraintProviders = null)
 {
     var services = new ServiceCollection().BuildServiceProvider();
     var descriptorProvider = new ActionDescriptorCollectionProvider(services);
     return new ActionConstraintCache(descriptorProvider, actionConstraintProviders.AsEnumerable() ?? new List<IActionConstraintProvider>());
 }
 private static ControllerActionInvokerCache CreateFilterCache(IFilterProvider[] filterProviders = null)
 {
     var services = new ServiceCollection().BuildServiceProvider();
     var descriptorProvider = new ActionDescriptorCollectionProvider(services);
     return new ControllerActionInvokerCache(descriptorProvider, filterProviders.AsEnumerable() ?? new List<IFilterProvider>());
 }