예제 #1
0
        public void CreateAreaRouteModel_AddsSelector()
        {
            // Arrange
            var relativePath      = "/Areas/TestArea/Pages/Users/Profile.cshtml";
            var options           = new RazorPagesOptions();
            var routeModelFactory = new PageRouteModelFactory(options, NullLogger.Instance);

            // Act
            var routeModel = routeModelFactory.CreateAreaRouteModel(relativePath, "{id?}");

            // Assert
            Assert.Equal(relativePath, routeModel.RelativePath);
            Assert.Equal("/Users/Profile", routeModel.ViewEnginePath);
            Assert.Equal("TestArea", routeModel.AreaName);

            Assert.Collection(
                routeModel.Selectors,
                selector => Assert.Equal("TestArea/Users/Profile/{id?}", selector.AttributeRouteModel.Template));

            Assert.Collection(
                routeModel.RouteValues.OrderBy(kvp => kvp.Key),
                kvp =>
            {
                Assert.Equal("area", kvp.Key);
                Assert.Equal("TestArea", kvp.Value);
            },
                kvp =>
            {
                Assert.Equal("page", kvp.Key);
                Assert.Equal("/Users/Profile", kvp.Value);
            });
        }
예제 #2
0
        public void CreateRouteModel_DoesNotAddMultipleSelectorsWhenRouteTemplateIsAbsolute()
        {
            // Arrange
            var relativePath      = "/Pages/Users/Profile/Index.cshtml";
            var options           = new RazorPagesOptions();
            var routeModelFactory = new PageRouteModelFactory(options, NullLogger.Instance);

            // Act
            var routeModel = routeModelFactory.CreateRouteModel(relativePath, "/my-override");

            // Assert
            Assert.Equal(relativePath, routeModel.RelativePath);
            Assert.Equal("/Users/Profile/Index", routeModel.ViewEnginePath);

            Assert.Collection(
                routeModel.Selectors,
                selector => Assert.Equal("my-override", selector.AttributeRouteModel.Template));

            Assert.Collection(
                routeModel.RouteValues,
                kvp =>
            {
                Assert.Equal("page", kvp.Key);
                Assert.Equal("/Users/Profile/Index", kvp.Value);
            });
        }
예제 #3
0
 public CompiledPageRouteModelProvider(
     ApplicationPartManager applicationManager,
     IOptions <RazorPagesOptions> pagesOptionsAccessor,
     ILogger <CompiledPageRouteModelProvider> logger)
 {
     _applicationManager = applicationManager ?? throw new ArgumentNullException(nameof(applicationManager));
     _pagesOptions       = pagesOptionsAccessor?.Value ?? throw new ArgumentNullException(nameof(pagesOptionsAccessor));
     _routeModelFactory  = new PageRouteModelFactory(_pagesOptions, logger);
 }
 public RazorProjectPageRouteModelProvider(
     RazorProjectFileSystem razorFileSystem,
     IOptions <RazorPagesOptions> pagesOptionsAccessor,
     ILoggerFactory loggerFactory)
 {
     _razorFileSystem   = razorFileSystem;
     _pagesOptions      = pagesOptionsAccessor.Value;
     _logger            = loggerFactory.CreateLogger <RazorProjectPageRouteModelProvider>();
     _routeModelFactory = new PageRouteModelFactory(_pagesOptions, _logger);
 }
예제 #5
0
        public void TryParseAreaPath_ReturnsFalse_IfPathDoesNotBelongToRootDirectory(string path)
        {
            // Arrange
            var options           = new RazorPagesOptions();
            var routeModelFactory = new PageRouteModelFactory(options, NullLogger.Instance);

            // Act
            var success = routeModelFactory.TryParseAreaPath(path, out _);

            // Assert
            Assert.False(success);
        }
예제 #6
0
        public void TryParseAreaPath_ParsesAreaPath(
            string path,
            string expectedArea,
            string expectedViewEnginePath)
        {
            // Arrange
            var options           = new RazorPagesOptions();
            var routeModelFactory = new PageRouteModelFactory(options, NullLogger.Instance);

            // Act
            var success = routeModelFactory.TryParseAreaPath(path, out var result);

            // Assert
            Assert.True(success);
            Assert.Equal(expectedArea, result.areaName);
            Assert.Equal(expectedViewEnginePath, result.viewEnginePath);
        }