Esempio n. 1
0
        public async Task Write_ClearFolder()
        {
            ILocation clearLoc = null;

            var targDirCleanerMock = new Mock <ITargetDirectoryCleaner>();

            targDirCleanerMock.Setup(m => m.ClearDirectory(It.IsAny <ILocation>()))
            .Returns((ILocation loc) =>
            {
                clearLoc = loc;
                return(Task.CompletedTask);
            });

            var publisher = new LocalFileSystemPublisher(
                new MockFileSystem(), new Mock <IPublisherExtension>().Object,
                new Mock <ILogger>().Object,
                targDirCleanerMock.Object);

            var pages = new IFile[]
            {
                new FileMock(Location.FromPath("page1.html"), "abc")
            };

            await publisher.Write(Location.FromPath("C:\\site"), pages.ToAsyncEnumerable());

            Assert.AreEqual("C:\\site", clearLoc.ToPath());
        }
Esempio n. 2
0
        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"));
        }
Esempio n. 3
0
        public void ExistingFileOverrideTest()
        {
            var fs = new MockFileSystem();

            fs.AddFile("C:\\site\\page1.html", new MockFileData("xyz"));

            var publisher = new LocalFileSystemPublisher(fs, new Mock <IPublisherExtension>().Object,
                                                         new Mock <ILogger>().Object,
                                                         new Mock <ITargetDirectoryCleaner>().Object);

            var files = new IFile[]
            {
                new FileMock(Location.FromPath("C:\\site\\page1.html"), "abc")
            };

            Assert.ThrowsAsync <FilePublishOverwriteForbiddenException>(() => publisher.Write(Location.FromPath("C:\\site"), files.ToAsyncEnumerable()));
        }
Esempio n. 4
0
        public async Task WriteBinaryTest()
        {
            var fs = new MockFileSystem();

            var publisher = new LocalFileSystemPublisher(fs, new Mock <IPublisherExtension>().Object,
                                                         new Mock <ILogger>().Object,
                                                         new Mock <ITargetDirectoryCleaner>().Object);

            var assets = new IFile[]
            {
                new FileMock(Location.FromPath("file.bin"), new byte[] { 1, 2, 3 })
            };

            await publisher.Write(Location.FromPath("C:\\site"), assets.ToAsyncEnumerable());

            Assert.AreEqual(1, fs.Directory.GetFiles("C:\\site", "*.*", System.IO.SearchOption.AllDirectories).Length);
            Assert.IsTrue(fs.File.Exists("C:\\site\\file.bin"));
            Assert.IsTrue(new byte[] { 1, 2, 3 }.SequenceEqual(await fs.File.ReadAllBytesAsync("C:\\site\\file.bin")));
        }