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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }