public void GetItem_PhysicalPathDoesNotStartWithContentRoot_ReturnsNull()
        {
            var fileProvider = new TestFileProvider("BasePath2");
            var file1        = fileProvider.AddFile("/File1.cshtml", "content");
            var file2        = fileProvider.AddFile("/File2.js", "content");
            var file3        = fileProvider.AddFile("/File3.cshtml", "content");

            fileProvider.AddDirectoryContent("/", new IFileInfo[] { file1, file2, file3 });

            var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

            var fileSystem = new FileProviderRazorProjectFileSystem(accessor, Mock.Of <IHostingEnvironment>(e => e.ContentRootPath == "BasePath"));

            // Act
            var item = fileSystem.GetItem("/File3.cshtml");

            // Assert
            Assert.True(item.Exists);
            Assert.Equal("/File3.cshtml", item.FilePath);
            Assert.Equal(string.Empty, item.BasePath);
            Assert.Equal(Path.Combine("BasePath2", "File3.cshtml"), item.PhysicalPath);
            Assert.Null(item.RelativePhysicalPath);
        }
        public void EnumerateFiles_IteratesOverAllCshtmlUnderRoot()
        {
            // 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 accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

            var fileSystem = new FileProviderRazorProjectFileSystem(accessor, Mock.Of <IHostingEnvironment>(e => e.ContentRootPath == "BasePath"));

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

            // Assert
            Assert.Collection(razorFiles.OrderBy(f => f.FilePath),
                              file =>
            {
                Assert.Equal("/File1.cshtml", file.FilePath);
                Assert.Equal("/", file.BasePath);
                Assert.Equal(Path.Combine("BasePath", "File1.cshtml"), file.PhysicalPath);
                Assert.Equal("File1.cshtml", file.RelativePhysicalPath);
            },
                              file =>
            {
                Assert.Equal("/Level1-Dir1/File2.cshtml", file.FilePath);
                Assert.Equal("/", 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("/Level1-Dir1/File3.cshtml", file.FilePath);
                Assert.Equal("/", file.BasePath);
                Assert.Equal(Path.Combine("BasePath", "Level1-Dir1", "File3.cshtml"), file.PhysicalPath);
                Assert.Equal(Path.Combine("Level1-Dir1", "File3.cshtml"), file.RelativePhysicalPath);
            },
                              file =>
            {
                Assert.Equal("/Level1-Dir2/File5.cshtml", file.FilePath);
                Assert.Equal("/", file.BasePath);
                Assert.Equal(Path.Combine("BasePath", "Level1-Dir2", "File5.cshtml"), file.PhysicalPath);
                Assert.Equal(Path.Combine("Level1-Dir2", "File5.cshtml"), file.RelativePhysicalPath);
            });
        }