public override RazorProjectEngine Build() { var engine = RazorEngine.CreateEmpty(ConfigureRazorEngine); var projectFeatures = Features.OfType <IRazorProjectEngineFeature>().ToArray(); var projectEngine = new DefaultRazorProjectEngine(Configuration, engine, FileSystem, projectFeatures); return(projectEngine); }
public override RazorProjectEngine Build() { #pragma warning disable CS0618 // Type or member is obsolete var engine = RazorEngine.CreateEmpty(ConfigureRazorEngine); #pragma warning restore CS0618 // Type or member is obsolete var projectFeatures = Features.OfType <IRazorProjectEngineFeature>().ToArray(); var projectEngine = new DefaultRazorProjectEngine(Configuration, engine, FileSystem, projectFeatures); return(projectEngine); }
public void ConvertToSourceDocument_ConvertsMarkerImports() { // Arrange var projectItem = Mock.Of <RazorProjectItem>(item => item.FilePath == "Index.cshtml" && item.Exists == false); // Act var sourceDocument = DefaultRazorProjectEngine.ConvertToSourceDocument(projectItem); // Assert Assert.NotNull(sourceDocument); }
public void ConvertToSourceDocument_ConvertsNormalImports() { // Arrange var projectItem = new TestRazorProjectItem("Index.cshtml"); // Act var sourceDocument = DefaultRazorProjectEngine.ConvertToSourceDocument(projectItem); // Assert Assert.NotNull(sourceDocument); }
public void GetImportSourceDocuments_DoesNotIncludeNonExistentItems() { // Arrange var existingItem = new TestRazorProjectItem("Index.cshtml"); var nonExistentItem = Mock.Of <RazorProjectItem>(item => item.Exists == false); var items = new[] { existingItem, nonExistentItem }; // Act var sourceDocuments = DefaultRazorProjectEngine.GetImportSourceDocuments(items); // Assert var sourceDocument = Assert.Single(sourceDocuments); Assert.Equal(existingItem.FilePath, sourceDocument.FilePath); }
public void GetImportSourceDocuments_UnreadableItem_Throws() { // Arrange var projectItem = new Mock <RazorProjectItem>(MockBehavior.Strict); projectItem.SetupGet(p => p.Exists).Returns(true); projectItem.SetupGet(p => p.PhysicalPath).Returns("path/to/file.cshtml"); projectItem.Setup(p => p.Read()).Throws(new IOException("Couldn't read file.")); var items = new[] { projectItem.Object }; // Act & Assert var exception = Assert.Throws <IOException>(() => DefaultRazorProjectEngine.GetImportSourceDocuments(items)); Assert.Equal("Couldn't read file.", exception.Message); }
public override RazorProjectEngine Build() { RazorEngine engine = null; if (Configuration.DesignTime) { engine = RazorEngine.CreateDesignTimeEmpty(ConfigureRazorEngine); } else { engine = RazorEngine.CreateEmpty(ConfigureRazorEngine); } var projectEngineFeatures = Features.OfType <IRazorProjectEngineFeature>().ToArray(); var projectEngine = new DefaultRazorProjectEngine(engine, FileSystem, projectEngineFeatures); return(projectEngine); }
public void GetImportSourceDocuments_WithSuppressExceptions_UnreadableItem_DoesNotThrow() { // Arrange var projectItem = new Mock <RazorProjectItem>(MockBehavior.Strict); projectItem.SetupGet(p => p.Exists).Returns(true); projectItem.SetupGet(p => p.PhysicalPath).Returns("path/to/file.cshtml"); projectItem.SetupGet(p => p.FilePath).Returns("path/to/file.cshtml"); projectItem.SetupGet(p => p.RelativePhysicalPath).Returns("path/to/file.cshtml"); projectItem.Setup(p => p.Read()).Throws(new IOException("Couldn't read file.")); var items = new[] { projectItem.Object }; // Act var sourceDocuments = DefaultRazorProjectEngine.GetImportSourceDocuments(items, suppressExceptions: true); // Assert - Does not throw Assert.Empty(sourceDocuments); }