Exemple #1
0
        public void GetItem_ReturnsNotFoundResult()
        {
            // Arrange
            var fileProvider = new TestFileProvider("BasePath");
            var file         = fileProvider.AddFile("SomeFile.cshtml", "content");

            fileProvider.AddDirectoryContent("/", new IFileInfo[] { file });
            var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

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

            // Act
            var item = razorProject.GetItem("/NotFound.cshtml");

            // Assert
            Assert.False(item.Exists);
        }
Exemple #2
0
        public void GetItem_ReturnsFileFromDisk()
        {
            var fileProvider = new TestFileProvider("BasePath");
            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 razorProject = new FileProviderRazorProject(accessor, Mock.Of <IHostingEnvironment>(e => e.ContentRootPath == "BasePath"));

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

            // Assert
            Assert.True(item.Exists);
            Assert.Equal("/File3.cshtml", item.FilePath);
            Assert.Equal(string.Empty, item.BasePath);
            Assert.Equal(Path.Combine("BasePath", "File3.cshtml"), item.PhysicalPath);
            Assert.Equal("File3.cshtml", item.RelativePhysicalPath);
        }