コード例 #1
0
        public void GetDescriptors_AddsDescriptorsForAreaPages()
        {
            // Arrange
            var model = new PageRouteModel("/Test.cshtml", "/Test")
            {
                RouteValues =
                {
                    { "custom-key", "custom-value" },
                },
                Selectors =
                {
                    new SelectorModel
                    {
                        AttributeRouteModel = new AttributeRouteModel
                        {
                            Template = "/Test/{id:int?}",
                        }
                    }
                }
            };
            var applicationModelProvider = new TestPageRouteModelProvider(model);
            var provider = new PageActionDescriptorProvider(
                new[] { applicationModelProvider },
                GetAccessor <MvcOptions>(),
                GetRazorPagesOptions());
            var context = new ActionDescriptorProviderContext();

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            var result     = Assert.Single(context.Results);
            var descriptor = Assert.IsType <PageActionDescriptor>(result);

            Assert.Equal(model.RelativePath, descriptor.RelativePath);
            Assert.Collection(
                descriptor.RouteValues.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("custom-key", kvp.Key);
                Assert.Equal("custom-value", kvp.Value);
            },
                kvp =>
            {
                Assert.Equal("page", kvp.Key);
                Assert.Equal("/Test", kvp.Value);
            });
        }
コード例 #2
0
        public void GetDescriptors_DoesNotAddDescriptorsIfNoApplicationModelsAreDiscovered()
        {
            // Arrange
            var applicationModelProvider = new TestPageRouteModelProvider();
            var provider = new PageActionDescriptorProvider(
                new[] { applicationModelProvider },
                GetAccessor <MvcOptions>(),
                GetRazorPagesOptions());
            var context = new ActionDescriptorProviderContext();

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            Assert.Empty(context.Results);
        }
コード例 #3
0
        public void GetDescriptors_AddsMultipleDescriptorsForPageWithMultipleSelectors()
        {
            // Arrange
            var applicationModelProvider = new TestPageRouteModelProvider(
                new PageRouteModel("/Catalog/Details/Index.cshtml", "/Catalog/Details/Index")
            {
                Selectors =
                {
                    CreateSelectorModel("/Catalog/Details/Index/{id:int?}"),
                    CreateSelectorModel("/Catalog/Details/{id:int?}"),
                },
            });

            var provider = new PageActionDescriptorProvider(
                new[] { applicationModelProvider },
                GetAccessor <MvcOptions>(),
                GetRazorPagesOptions());
            var context = new ActionDescriptorProviderContext();

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            Assert.Collection(context.Results,
                              result =>
            {
                var descriptor = Assert.IsType <PageActionDescriptor>(result);
                Assert.Equal("/Catalog/Details/Index.cshtml", descriptor.RelativePath);
                Assert.Equal("/Catalog/Details/Index", descriptor.RouteValues["page"]);
                Assert.Equal("/Catalog/Details/Index/{id:int?}", descriptor.AttributeRouteInfo.Template);
            },
                              result =>
            {
                var descriptor = Assert.IsType <PageActionDescriptor>(result);
                Assert.Equal("/Catalog/Details/Index.cshtml", descriptor.RelativePath);
                Assert.Equal("/Catalog/Details/Index", descriptor.RouteValues["page"]);
                Assert.Equal("/Catalog/Details/{id:int?}", descriptor.AttributeRouteInfo.Template);
            });
        }