Esempio n. 1
0
        public void FindHierarchicalItems_FindsItemsWithMatchingNames()
        {
            // Arrange
            var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);

            // Act
            var items = fileSystem.FindHierarchicalItems("/Views/Home/Index.cshtml", "_ViewImports.cshtml");

            // Assert
            Assert.Collection(
                items,
                item =>
            {
                Assert.Equal("/Views/Home/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "Home", "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "Home", "_ViewImports.cshtml"), item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Views/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "_ViewImports.cshtml"), item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal("_ViewImports.cshtml", item.RelativePhysicalPath);
            });
        }
Esempio n. 2
0
        public void EnumerateItems_DiscoversAllCshtmlFiles()
        {
            // Arrange
            var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);

            // Act
            var items = fileSystem.EnumerateItems("/");

            // Assert
            Assert.Collection(
                items.OrderBy(f => f.FilePath),
                item =>
            {
                Assert.Equal("/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal("_ViewImports.cshtml", item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Home.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Home.cshtml"), item.PhysicalPath);
                Assert.Equal("Home.cshtml", item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Views/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "_ViewImports.cshtml"), item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Views/About/About.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "About", "About.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Views/Home/_ViewImports.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "Home", "_ViewImports.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "Home", "_ViewImports.cshtml"), item.RelativePhysicalPath);
            },
                item =>
            {
                Assert.Equal("/Views/Home/Index.cshtml", item.FilePath);
                Assert.Equal("/", item.BasePath);
                Assert.Equal(Path.Combine(TestFolder, "Views", "Home", "Index.cshtml"), item.PhysicalPath);
                Assert.Equal(Path.Combine("Views", "Home", "Index.cshtml"), item.RelativePhysicalPath);
            });
        }
Esempio n. 3
0
        public void EnumerateItems_ReturnsEmptySequence_WhenBasePathDoesNotExist()
        {
            // Arrange
            var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);

            // Act
            var items = fileSystem.EnumerateItems("/Does-Not-Exist");

            // Assert
            Assert.Empty(items);
        }
Esempio n. 4
0
        public void GetItem_ReturnsNotFoundResult()
        {
            // Arrange
            var path       = "/NotFound.cshtml";
            var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);

            // Act
            var item = fileSystem.GetItem(path);

            // Assert
            Assert.False(item.Exists);
        }
Esempio n. 5
0
        public void GetItem_ReturnsFileFromDisk()
        {
            // Arrange
            var filePath   = "/Views/About/About.cshtml";
            var fileSystem = new DefaultRazorProjectFileSystem(TestFolder);

            // Act
            var item = fileSystem.GetItem(filePath);

            // Assert
            Assert.True(item.Exists);
            Assert.Equal(filePath, item.FilePath);
            Assert.Equal("/", item.BasePath);
            Assert.Equal(Path.Combine(TestFolder, "Views", "About", "About.cshtml"), item.PhysicalPath);
            Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
        }
Esempio n. 6
0
        public void GetItem_MismatchedCase_ReturnsFileFromDisk()
        {
            // Arrange
            var filePath            = "/Views/About/About.cshtml";
            var lowerCaseTestFolder = TestFolder.ToLowerInvariant();
            var fileSystem          = new DefaultRazorProjectFileSystem(lowerCaseTestFolder);

            // Act
            var item = fileSystem.GetItem(filePath, fileKind: null);

            // Assert
            Assert.True(item.Exists);
            Assert.Equal(filePath, item.FilePath);
            Assert.Equal("/", item.BasePath);
            Assert.Equal(Path.Combine(lowerCaseTestFolder, "Views", "About", "About.cshtml"), item.PhysicalPath);
            Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
        }
        public void CreateCodeDocument_WithFileSystemProject_ReturnsCorrectItems()
        {
            // Arrange
            var testFolder = Path.Combine(
                TestProject.GetProjectDirectory(typeof(DefaultRazorProjectFileSystemTest)),
                "TestFiles",
                "DefaultRazorProjectFileSystem");

            var project        = new DefaultRazorProjectFileSystem(testFolder);
            var razorEngine    = CreateProjectEngine().Engine;
            var templateEngine = new RazorTemplateEngine(razorEngine, project)
            {
                Options =
                {
                    ImportsFileName = "_ViewImports.cshtml"
                }
            };

            // Act
            var codeDocument = templateEngine.CreateCodeDocument("/Views/Home/Index.cshtml");

            // Assert
            Assert.Collection(
                codeDocument.Imports,
                item =>
            {
                Assert.Equal(Path.Combine(testFolder, "_ViewImports.cshtml"), item.FilePath);
                Assert.Equal("_ViewImports.cshtml", item.RelativePath);
            },
                item =>
            {
                Assert.Equal(Path.Combine(testFolder, "Views", "_ViewImports.cshtml"), item.FilePath);
                Assert.Equal(Path.Combine("Views", "_ViewImports.cshtml"), item.RelativePath);
            },
                item =>
            {
                Assert.Equal(Path.Combine(testFolder, "Views", "Home", "_ViewImports.cshtml"), item.FilePath);
                Assert.Equal(Path.Combine("Views", "Home", "_ViewImports.cshtml"), item.RelativePath);
            });
        }