public void TryParseAreaPath_ReturnsFalse_IfPathDoesNotBelongToRootDirectory(string path) { // Arrange var options = new RazorPagesOptions(); // Act var success = PageSelectorModel.TryParseAreaPath(options, path, NullLogger.Instance, out _); // Assert Assert.False(success); }
public void TryParseAreaPath_ParsesAreaPath( string path, string expectedArea, string expectedViewEnginePath, string expectedRoute) { // Arrange var options = new RazorPagesOptions(); // Act var success = PageSelectorModel.TryParseAreaPath(options, path, NullLogger.Instance, out var result); // Assert Assert.True(success); Assert.Equal(expectedArea, result.areaName); Assert.Equal(expectedViewEnginePath, result.viewEnginePath); Assert.Equal(expectedRoute, result.pageRoute); }
private PageRouteModel GetAreaPageRouteModel(string areaRootDirectory, CompiledViewDescriptor viewDescriptor) { var rootTrimmedPath = GetRootTrimmedPath(areaRootDirectory, viewDescriptor.RelativePath); if (PageSelectorModel.TryParseAreaPath(_pagesOptions, rootTrimmedPath, _logger, out var result)) { var model = new PageRouteModel(viewDescriptor.RelativePath, result.viewEnginePath) { RouteValues = { ["area"] = result.areaName }, }; var pageAttribute = (RazorPageAttribute)viewDescriptor.ViewAttribute; PageSelectorModel.PopulateDefaults(model, result.pageRoute, pageAttribute.RouteTemplate); return(model); } // We were unable to parse the path to match the format we expect /Areas/AreaName/Pages/PagePath.cshtml return(null); }
private void AddAreaPageModels(PageRouteModelProviderContext context) { foreach (var item in _project.EnumerateItems(_pagesOptions.AreaRootDirectory)) { if (!IsRouteable(item)) { continue; } if (!PageDirectiveFeature.TryGetPageDirective(_logger, item, out var routeTemplate)) { // .cshtml pages without @page are not RazorPages. continue; } if (!PageSelectorModel.TryParseAreaPath(_pagesOptions, item.FilePath, _logger, out var areaResult)) { continue; } var routeModel = new PageRouteModel( relativePath: item.CombinedPath, viewEnginePath: areaResult.viewEnginePath) { RouteValues = { ["area"] = areaResult.areaName, }, }; if (IsAlreadyRegistered(context, routeModel)) { // The CompiledPageRouteModelProvider (or another provider) already registered a PageRoute for this path. // Don't register a duplicate entry for this route. continue; } PageSelectorModel.PopulateDefaults(routeModel, areaResult.pageRoute, routeTemplate); context.RouteModels.Add(routeModel); } }