public void PageBaseTypeIsCorrectlyLoadedFromConfig() { // Act RazorWebSectionGroup group = GetRazorGroup(); RazorPagesSection pages = (RazorPagesSection)group.Pages; // Assert Assert.NotNull(pages); Assert.Equal("System.Web.WebPages.Razor.Test.TestPageBase, System.Web.WebPages.Razor.Test", pages.PageBaseType); }
public static void ApplyConfigurationToHost(RazorPagesSection config, WebPageRazorHost host) { host.DefaultPageBaseClass = config.PageBaseType; // Add imports foreach (string import in config.Namespaces.OfType <NamespaceInfo>().Select(ns => ns.Namespace)) { host.NamespaceImports.Add(import); } }
public override void Initialize(RazorHost razorHost, IDictionary <string, string> directives) { string projectPath = GetProjectRoot(razorHost.ProjectRelativePath, razorHost.FullPath).TrimEnd(Path.DirectorySeparatorChar); string currentPath = razorHost.FullPath; string directoryVirtualPath = null; var configFileMap = new WebConfigurationFileMap(); var virtualDirectories = configFileMap.VirtualDirectories; while (!currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase)) { currentPath = Path.GetDirectoryName(currentPath); string relativePath = currentPath.Substring(projectPath.Length); bool isAppRoot = currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase); string virtualPath = relativePath.Replace('\\', '/'); if (virtualPath.Length == 0) { virtualPath = "/"; } directoryVirtualPath = directoryVirtualPath ?? virtualPath; virtualDirectories.Add(virtualPath, new VirtualDirectoryMapping(currentPath, isAppRoot: isAppRoot)); } try { var config = WebConfigurationManager.OpenMappedWebConfiguration(configFileMap, directoryVirtualPath); RazorPagesSection section = config.GetSection(RazorPagesSection.SectionName) as RazorPagesSection; if (section != null) { string baseType = section.PageBaseType; if (!DefaultBaseType.Equals(baseType, StringComparison.OrdinalIgnoreCase)) { _transformers.Add(new SetBaseType(baseType)); } if (section != null) { foreach (NamespaceInfo n in section.Namespaces) { razorHost.NamespaceImports.Add(n.Namespace); } } } } catch (IndexOutOfRangeException) { // Bug in Mono framework. // Configure namespaces using the RazorGenerator directives file instead. } base.Initialize(razorHost, directives); }
public void NamespacesAreCorrectlyLoadedFromConfig() { // Act RazorWebSectionGroup group = GetRazorGroup(); RazorPagesSection pages = (RazorPagesSection)group.Pages; // Assert Assert.NotNull(pages); Assert.Equal(1, pages.Namespaces.Count); Assert.Equal("System.Text.RegularExpressions", pages.Namespaces[0].Namespace); }
public void NamespacesAreCorrectlyLoadedFromConfig() { // Act RazorWebSectionGroup group = GetRazorGroup(); RazorPagesSection pages = (RazorPagesSection)group.Pages; // Assert Assert.NotNull(pages); NamespaceInfo namespaceInfo = Assert.IsType <NamespaceInfo>(Assert.Single(pages.Namespaces)); Assert.Equal("System.Text.RegularExpressions", namespaceInfo.Namespace); }