public async Task ComposeSite_MultiLevelAsset() { var src = new FileMock[] { new FileMock(Location.FromPath(@"index.md"), ""), new FileMock(Location.FromPath(@"asset.txt"), "a1"), new FileMock(Location.FromPath(@"page1\index.md"), ""), new FileMock(Location.FromPath(@"page1\asset1.txt"), "a2"), new FileMock(Location.FromPath(@"page2\index.md"), ""), new FileMock(Location.FromPath(@"page2\asset.txt"), "a3"), new FileMock(Location.FromPath(@"page2\page3\index.md"), ""), new FileMock(Location.FromPath(@"page2\page3\asset2.txt"), "a4") }.ToAsyncEnumerable(); var site = await m_Composer.ComposeSite(src, "", ""); Assert.AreEqual(1, site.MainPage.Assets.Count); Assert.AreEqual("a1", site.MainPage.Assets[0].AsTextContent()); Assert.AreEqual("asset.txt", site.MainPage.Assets[0].FileName); Assert.AreEqual(1, site.MainPage.SubPages.Find(p => p.Name == "page1").Assets.Count); Assert.AreEqual("a2", site.MainPage.SubPages.Find(p => p.Name == "page1").Assets[0].AsTextContent()); Assert.AreEqual("asset1.txt", site.MainPage.SubPages.Find(p => p.Name == "page1").Assets[0].FileName); Assert.AreEqual(1, site.MainPage.SubPages.Find(p => p.Name == "page2").Assets.Count); Assert.AreEqual("a3", site.MainPage.SubPages.Find(p => p.Name == "page2").Assets[0].AsTextContent()); Assert.AreEqual("asset.txt", site.MainPage.SubPages.Find(p => p.Name == "page2").Assets[0].FileName); Assert.AreEqual(1, site.MainPage.SubPages.Find(p => p.Name == "page2").SubPages[0].Assets.Count); Assert.AreEqual("a4", site.MainPage.SubPages.Find(p => p.Name == "page2").SubPages[0].Assets[0].AsTextContent()); Assert.AreEqual("asset2.txt", site.MainPage.SubPages.Find(p => p.Name == "page2").SubPages[0].Assets[0].FileName); }
public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel() { var fileMock = new FileMock(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); fileMock.OpenFileWithRightParamsCalled.Should().BeTrue(); }
public async Task ComposeSite_SubFolderAsset() { var src = new FileMock[] { new FileMock(Location.FromPath(@"index.md"), ""), new FileMock(Location.FromPath(@"page1\index.md"), ""), new FileMock(Location.FromPath(@"page1\sub-folder\asset1.txt"), "a1"), new FileMock(Location.FromPath(@"page1\sub-folder\sub-folder2\asset2.txt"), "a2"), new FileMock(Location.FromPath(@"page1\asset3.txt"), "a3") }.ToAsyncEnumerable(); var site = await m_Composer.ComposeSite(src, "", ""); var p1 = site.MainPage.SubPages.First(p => p.Name == "page1"); var f1 = p1.Folders.First(f => f.Name == "sub-folder"); var f2 = f1.Folders.First(f => f.Name == "sub-folder2"); var a1 = f1.Assets.FirstOrDefault(a => a.FileName == "asset1.txt"); var a2 = f2.Assets.FirstOrDefault(a => a.FileName == "asset2.txt"); var a3 = p1.Assets.FirstOrDefault(a => a.FileName == "asset3.txt"); Assert.AreEqual(1, p1.Assets.Count); Assert.AreEqual(1, f1.Assets.Count); Assert.AreEqual(1, f2.Assets.Count); Assert.AreEqual(1, p1.Folders.Count); Assert.AreEqual(1, f1.Folders.Count); Assert.AreEqual(0, f2.Folders.Count); Assert.IsNotNull(a1); Assert.IsNotNull(a2); Assert.IsNotNull(a3); Assert.AreEqual("a1", a1.AsTextContent()); Assert.AreEqual("a2", a2.AsTextContent()); Assert.AreEqual("a3", a3.AsTextContent()); }
public async Task ComposeSite_DifferentPageTypesTest() { var src = new FileMock[] { new FileMock(Location.FromPath(@"index.html"), "i"), new FileMock(Location.FromPath(@"page1\page2\index.cshtml"), "p2"), new FileMock(Location.FromPath(@"page1\index.md"), "p1"), new FileMock(Location.FromPath(@"page1\page3\index.html"), "p3"), }.ToAsyncEnumerable(); var site = await m_Composer.ComposeSite(src, "", ""); var p1 = site.MainPage.SubPages.First(p => p.Name.Equals("page1", StringComparison.CurrentCultureIgnoreCase)); var p2 = p1?.SubPages.First(p => p.Name.Equals("page2", StringComparison.CurrentCultureIgnoreCase)); var p3 = p1?.SubPages.First(p => p.Name.Equals("page3", StringComparison.CurrentCultureIgnoreCase)); Assert.AreEqual(1, site.MainPage.SubPages.Count); Assert.AreEqual("i", site.MainPage.RawContent); Assert.IsNotNull(p1); Assert.AreEqual("p1", p1.RawContent); Assert.AreEqual(2, p1.SubPages.Count); Assert.IsNotNull(p2); Assert.AreEqual("p2", p2.RawContent); Assert.IsNotNull(p3); Assert.AreEqual("p3", p3.RawContent); }
public async Task ComposeSite_PhantomPageAsset() { var src = new FileMock[] { new FileMock(Location.FromPath(@"index.md"), ""), new FileMock(Location.FromPath(@"page1\index.md"), ""), new FileMock(Location.FromPath(@"page1\page2\asset1.txt"), "a1"), new FileMock(Location.FromPath(@"page1\page2\Page3\asset2.txt"), "a2"), new FileMock(Location.FromPath(@"page1\page2\Page3\index.md"), ""), }.ToAsyncEnumerable(); var site = await m_Composer.ComposeSite(src, "", ""); var p1 = site.MainPage.SubPages.First(p => p.Name == "page1"); var p2 = p1.SubPages.First(p => p.Name == "page2"); var p3 = p2.SubPages.First(p => p.Name == "Page3"); var a1 = p1.Folders.FirstOrDefault(f => f.Name == "page2").Assets.FirstOrDefault(a => a.FileName == "asset1.txt"); var a2 = p3.Assets.FirstOrDefault(a => a.FileName == "asset2.txt"); Assert.AreEqual(0, p1.Assets.Count); Assert.AreEqual(1, p1.Folders.Count); Assert.AreEqual(1, p1.Folders[0].Assets.Count); Assert.AreEqual(0, p2.Assets.Count); Assert.AreEqual(1, p3.Assets.Count); Assert.IsNotNull(a1); Assert.IsNotNull(a2); Assert.AreEqual("a1", a1.AsTextContent()); Assert.AreEqual("a2", a2.AsTextContent()); }
public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel() { var fileMock = new FileMock(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); fileMock.OpenFileWithRightParamsCalled.Should().BeTrue(); }
public FileMock AddFile(string name, string text) { var file = new FileMock(this, name, text); _files.Add(file); return(file); }
public async Task ComposeSite_LayoutNested() { var composer = new BaseSiteComposer(new Mock <ILayoutParser>().Object, null, new Mock <IComposerExtension>().Object); var src = new FileMock[] { new FileMock(Location.FromPath(@"_layouts\\l1.md"), "L1 _C_"), new FileMock(Location.FromPath(@"_layouts\\l2.md"), "---\r\nlayout: l1\r\n---\r\nL2 _C_"), new FileMock(Location.FromPath(@"_layouts\\l4.md"), "---\r\nlayout: l3\r\n---\r\nL4 _C_"), new FileMock(Location.FromPath(@"_layouts\\l3.md"), "L3 _C_"), new FileMock(Location.FromPath(@"index.md"), "---\r\nprp1: A\r\n---\r\nText Line1\r\nText Line2"), new FileMock(Location.FromPath(@"p2.md"), "---\r\nlayout: l2\r\n---\r\nP1"), new FileMock(Location.FromPath(@"p4.md"), "---\r\nlayout: l4\r\n---\r\nP4") }.ToAsyncEnumerable(); var site = await composer.ComposeSite(src, "", ""); Assert.AreEqual("Text Line1\r\nText Line2", site.MainPage.RawContent); Assert.IsNull(site.MainPage.Layout); Assert.IsNotNull(site.MainPage.SubPages[0].Layout); Assert.AreEqual("l2", site.MainPage.SubPages.Find(p => p.Name == "p2").Layout.Name); Assert.AreEqual("l4", site.MainPage.SubPages.Find(p => p.Name == "p4").Layout.Name); Assert.IsNotNull(site.MainPage.SubPages.Find(p => p.Name == "p2").Layout.Layout); Assert.AreEqual("l1", site.MainPage.SubPages.Find(p => p.Name == "p2").Layout.Layout.Name); Assert.IsNotNull(site.MainPage.SubPages.Find(p => p.Name == "p4").Layout.Layout); Assert.AreEqual("l3", site.MainPage.SubPages.Find(p => p.Name == "p4").Layout.Layout.Name); }
public async Task WriteTextTest() { var fs = new MockFileSystem(); var publisher = new LocalFileSystemPublisher(fs, new Mock <IPublisherExtension>().Object, new Mock <ILogger>().Object, new Mock <ITargetDirectoryCleaner>().Object); var pages = new FileMock[] { new FileMock(Location.FromPath("page1.html"), "abc"), new FileMock(Location.FromPath("dir1\\page2.html"), "def"), new FileMock(Location.FromPath("C:\\external\\page3.html"), "xyz"), }; await publisher.Write(Location.FromPath("C:\\site"), pages.ToAsyncEnumerable()); Assert.AreEqual(2, fs.Directory.GetFiles("C:\\site", "*.*", System.IO.SearchOption.AllDirectories).Length); Assert.IsTrue(fs.File.Exists("C:\\site\\page1.html")); Assert.IsTrue(fs.File.Exists("C:\\site\\dir1\\page2.html")); Assert.IsTrue(fs.File.Exists("C:\\external\\page3.html")); Assert.AreEqual("abc", await fs.File.ReadAllTextAsync("C:\\site\\page1.html")); Assert.AreEqual("def", await fs.File.ReadAllTextAsync("C:\\site\\dir1\\page2.html")); Assert.AreEqual("xyz", await fs.File.ReadAllTextAsync("C:\\external\\page3.html")); }
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it() { var fileMock = new FileMock(); fileMock.InProgressSentinel = null; var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue(); }
public void NeedToCopy_Filenew() { FileMock file = new FileMock(null); FileSystemMock fileSystem = new FileSystemMock(file); NeedToCopyWithConfirmation needToCopyUpdatedOnlyChecker = new NeedToCopyWithConfirmation(fileSystem, null); Assert.True(needToCopyUpdatedOnlyChecker.NeedToCopy(null, "dummy", "dummy")); }
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it() { var fileMock = new FileMock(); fileMock.InProgressSentinel = new MemoryStream(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse(); }
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it() { var fileMock = new FileMock(); fileMock.InProgressSentinel = new MemoryStream(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse(); }
public void Should_throw_if_file_throws() { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Throws <FileNotFoundException>(); CreateLoader(FilePath) .Invoking(l => l.Load()) .ShouldThrow <FileNotFoundException>(); }
public void ComposeSite_EmptySiteTest() { var src = new FileMock[] { new FileMock(Location.FromPath(@"page1\index.txt"), ""), }.ToAsyncEnumerable(); Assert.ThrowsAsync <EmptySiteException>(() => m_Composer.ComposeSite(src, "", "")); }
public void It_sets_UnauthorizedAccess_to_true_when_an_UnauthorizedAccessException_happens() { var fileMock = new FileMock(); var directoryMock = new DirectoryMock(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, directoryMock); nugetCacheSentinel.UnauthorizedAccess.Should().BeTrue(); }
public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it() { var fileMock = new FileMock(); fileMock.InProgressSentinel = null; var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock); nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue(); }
public void It_sets_UnauthorizedAccess_to_false_when_no_UnauthorizedAccessException_happens() { var fileSystemMock = _fileSystemMockBuilder.Build(); var fileMock = new FileMock(); var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, fileSystemMock.Directory); nugetCacheSentinel.UnauthorizedAccess.Should().BeFalse(); }
public void ComposeSite_NoMainPageTest() { var src = new FileMock[] { new FileMock(Location.FromPath(@"page1\index.md"), ""), new FileMock(Location.FromPath(@"page1.md"), "") }.ToAsyncEnumerable(); Assert.ThrowsAsync <SiteMainPageMissingException>(() => m_Composer.ComposeSite(src, "", "")); }
public async Task ComposeSite_NotClosedFrontMatter() { var src = new FileMock[] { new FileMock(Location.FromPath(@"index.md"), "---\r\nText Line1\r\nText Line2"), }.ToAsyncEnumerable(); await AssertException.ThrowsInnerAsync <FrontMatterErrorException>(() => m_Composer.ComposeSite(src, "", "")); }
public FileSystemMock(MockFileSystemModel files) { if (files == null) { throw new ArgumentNullException(nameof(files)); } File = new FileMock(files); Directory = new DirectoryMock(files); }
public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed() { var mockStream = new MockStream(); var fileMock = new FileMock(); fileMock.InProgressSentinel = mockStream; using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock)) {} mockStream.IsDisposed.Should().BeTrue(); }
public void Should_return_provider_returned_by_factory() { using (var stream = GetStream(String.Empty)) { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Returns(stream); CreateLoader(FilePath).Load().Should().Be(_providerMock.Object); } }
public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it_but_it_failed_because_it_was_unauthorized() { var fileMock = new FileMock(); var directoryMock = new DirectoryMock(); fileMock.InProgressSentinel = null; var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock, directoryMock); nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse(); }
public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed() { var mockStream = new MockStream(); var fileMock = new FileMock(); fileMock.InProgressSentinel = mockStream; using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock)) {} mockStream.IsDisposed.Should().BeTrue(); }
public void CopyTo_OverwritesTargetFileContents_IfTargetFileExistsAndOverwriteIsTrue() { var source = new FileMock("test1", "Source"); var target = new FileMock("test2", "Target"); new FileSystemMock(source, target); source.CopyTo(target.FullName, true); Assert.Equal(target.ReadAllText(), source.ReadAllText()); }
public void ComposeSite_DuplicateIncludes() { var src = new FileMock[] { new FileMock(Location.FromPath(@"_includes\\i1.md"), ""), new FileMock(Location.FromPath(@"_includes\\i1.txt"), ""), new FileMock(Location.FromPath(@"index.md"), ""), }.ToAsyncEnumerable(); Assert.ThrowsAsync <DuplicateTemplateException>(() => m_Composer.ComposeSite(src, "", "")); }
public void ReadAll_Fails_IfExistsIsFalse(MethodInfo method) { var mock = new FileMock("test", "") { Exists = false }; var exception = Assert.Throws <TargetInvocationException>(() => method.Invoke(mock, new object[method.GetParameters().Length])); Assert.IsType <FileNotFoundException>(exception.InnerException); }
public void Should_create_token_of_type_string() { using (var stream = GetStream("\"content\"")) { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Returns(stream); CreateLoader(FilePath).Load(); _tokens.First().Value <string>().Should().Be("content"); } }
public void Should_create_provider_with_token_of_type_null() { using (var stream = GetStream("null")) { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Returns(stream); CreateLoader(FilePath).Load(); _tokens.Should().HaveCount(1) .And.Subject.First().Type.Should().Be(JTokenType.Null); } }
public void Should_create_provider_with_null_as_jtoken_if_stream_is_empty() { using (var stream = GetStream(String.Empty)) { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Returns(stream); CreateLoader(FilePath).Load(); _tokens.Should().HaveCount(1) .And.Contain((JToken)null); } }
public void Should_throw_if_json_is_invalid() { using (var stream = GetStream("invalid")) { FileMock.Setup(f => f.Open(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>(), It.IsAny <FileShare>())) .Returns(stream); CreateLoader(FilePath) .Invoking(l => l.Load()) .ShouldThrow <JsonReaderException>(); } }
public void TransformToInfFile_WithInvalidFile_ReturnsEmptyString() { var filename = @"X:\My Test\file.pdf"; FileMock.Exists(filename).Returns(true); ConfigureInvalidFileOpenRead(FileMock, filename); var directConversion = Fixture.Create <DirectConversionBase>(); var infFile = directConversion.TransformToInfFile(filename); Assert.AreEqual("", infFile); }
public void ComposeSite_InheritLayoutMissing() { var composer = new BaseSiteComposer(new Mock <ILayoutParser>().Object, null, new Mock <IComposerExtension>().Object); var src = new FileMock[] { new FileMock(Location.FromPath(@"index.md"), ""), new FileMock(Location.FromPath(@"page1\\index.md"), "---\r\nlayout: $\r\n---") }.ToAsyncEnumerable(); Assert.ThrowsAsync <MissingInheritLayoutException>(() => composer.ComposeSite(src, "", "")); }
public FileSystemMock(Dictionary<string, string> files) { File = new FileMock(files); Directory = new DirectoryMock(files); }
public FileSystemMock(Dictionary<string, string> files, string temporaryFolder) { File = new FileMock(files); Directory = new DirectoryMock(files, temporaryFolder); }
public FileMock AddFile(string name, string text) { var file = new FileMock(this, name, text); _files.Add(file); return file; }