public void EnumerateFiles_IteratesOverAllCshtmlUnderPath() { // Arrange var fileProvider = new TestFileProvider("BasePath"); var directory1 = new TestDirectoryFileInfo { Name = "Level1-Dir1", }; var file1 = fileProvider.AddFile(Path.Combine("BasePath", "File1.cshtml"), "content"); var directory2 = new TestDirectoryFileInfo { Name = "Level1-Dir2", }; fileProvider.AddDirectoryContent("/", new IFileInfo[] { directory1, file1, directory2 }); var file2 = fileProvider.AddFile(Path.Combine("Level1-Dir1", "File2.cshtml"), "content"); var file3 = fileProvider.AddFile(Path.Combine("Level1-Dir1", "File3.cshtml"), "content"); var file4 = fileProvider.AddFile(Path.Combine("Level1-Dir1", "File4.txt"), "content"); var directory3 = new TestDirectoryFileInfo { Name = "Level2-Dir1" }; fileProvider.AddDirectoryContent("/Level1-Dir1", new IFileInfo[] { file2, directory3, file3, file4 }); var file5 = fileProvider.AddFile(Path.Combine("Level1-Dir2", "File5.cshtml"), "content"); fileProvider.AddDirectoryContent("/Level1-Dir2", new IFileInfo[] { file5 }); fileProvider.AddDirectoryContent("/Level1/Level2", new IFileInfo[0]); var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider); var razorProject = new FileProviderRazorProject(accessor, Mock.Of <IHostingEnvironment>(e => e.ContentRootPath == "BasePath")); // Act var razorFiles = razorProject.EnumerateItems("/Level1-Dir1"); // Assert Assert.Collection(razorFiles.OrderBy(f => f.FilePath), file => { Assert.Equal("/File2.cshtml", file.FilePath); Assert.Equal("/Level1-Dir1", file.BasePath); Assert.Equal(Path.Combine("BasePath", "Level1-Dir1", "File2.cshtml"), file.PhysicalPath); Assert.Equal(Path.Combine("Level1-Dir1", "File2.cshtml"), file.RelativePhysicalPath); }, file => { Assert.Equal("/File3.cshtml", file.FilePath); Assert.Equal("/Level1-Dir1", file.BasePath); Assert.Equal(Path.Combine("BasePath", "Level1-Dir1", "File3.cshtml"), file.PhysicalPath); Assert.Equal(Path.Combine("Level1-Dir1", "File3.cshtml"), file.RelativePhysicalPath); }); }
public void EnumerateFiles_IteratesOverAllCshtmlUnderPath() { // Arrange var fileProvider = new TestFileProvider("BasePath"); var directory1 = new TestDirectoryFileInfo { Name = "Level1-Dir1", }; var file1 = fileProvider.AddFile("/File1.cshtml", "content"); var directory2 = new TestDirectoryFileInfo { Name = "Level1-Dir2", }; fileProvider.AddDirectoryContent("/", new IFileInfo[] { directory1, file1, directory2 }); var file2 = fileProvider.AddFile("/Level1-Dir1/File2.cshtml", "content"); var file3 = fileProvider.AddFile("/Level1-Dir1/File3.cshtml", "content"); var file4 = fileProvider.AddFile("/Level1-Dir1/File4.txt", "content"); var directory3 = new TestDirectoryFileInfo { Name = "Level2-Dir1" }; fileProvider.AddDirectoryContent("/Level1-Dir1", new IFileInfo[] { file2, directory3, file3, file4 }); var file5 = fileProvider.AddFile(Path.Combine("Level1-Dir2", "File5.cshtml"), "content"); fileProvider.AddDirectoryContent("/Level1-Dir2", new IFileInfo[] { file5 }); fileProvider.AddDirectoryContent("/Level1/Level2", new IFileInfo[0]); var fileSystem = GetRazorProjectFileSystem(fileProvider); // Act var razorFiles = fileSystem.EnumerateItems("/Level1-Dir1"); // Assert Assert.Collection(razorFiles.OrderBy(f => f.FilePath), file => { Assert.Equal("/File2.cshtml", file.FilePath); Assert.Equal("/Level1-Dir1", file.BasePath); Assert.Equal(Path.Combine("BasePath", "Level1-Dir1", "File2.cshtml"), file.PhysicalPath); Assert.Equal(Path.Combine("Level1-Dir1", "File2.cshtml"), file.RelativePhysicalPath); }, file => { Assert.Equal("/File3.cshtml", file.FilePath); Assert.Equal("/Level1-Dir1", file.BasePath); Assert.Equal(Path.Combine("BasePath", "Level1-Dir1", "File3.cshtml"), file.PhysicalPath); Assert.Equal(Path.Combine("Level1-Dir1", "File3.cshtml"), file.RelativePhysicalPath); }); }
public void EnumerateFiles_IteratesOverAllCshtmlUnderRoot() { // Arrange var fileProvider = new TestFileProvider(); var directory1 = new TestDirectoryFileInfo { Name = "Level1-Dir1", }; var file1 = fileProvider.AddFile("File1.cshtml", "content"); var directory2 = new TestDirectoryFileInfo { Name = "Level1-Dir2", }; fileProvider.AddDirectoryContent("/", new IFileInfo[] { directory1, file1, directory2 }); var file2 = fileProvider.AddFile("Level1-Dir1/File2.cshtml", "content"); var file3 = fileProvider.AddFile("Level1-Dir1/File3.cshtml", "content"); var file4 = fileProvider.AddFile("Level1-Dir1/File4.txt", "content"); var directory3 = new TestDirectoryFileInfo { Name = "Level2-Dir1" }; fileProvider.AddDirectoryContent("/Level1-Dir1", new IFileInfo[] { file2, directory3, file3, file4 }); var file5 = fileProvider.AddFile("Level1-Dir2/File5.cshtml", "content"); fileProvider.AddDirectoryContent("/Level1-Dir2", new IFileInfo[] { file5 }); fileProvider.AddDirectoryContent("/Level1/Level2", new IFileInfo[0]); var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider); var razorProject = new FileProviderRazorProject(accessor); // Act var razorFiles = razorProject.EnumerateItems("/"); // Assert Assert.Collection(razorFiles.OrderBy(f => f.FilePath), file => Assert.Equal("/File1.cshtml", file.FilePath), file => Assert.Equal("/Level1-Dir1/File2.cshtml", file.FilePath), file => Assert.Equal("/Level1-Dir1/File3.cshtml", file.FilePath), file => Assert.Equal("/Level1-Dir2/File5.cshtml", file.FilePath)); }