Ejemplo n.º 1
0
            public void CopyFolderFromAboveInputPath()
            {
                // Given
                Engine engine = new Engine();
                engine.RootFolder = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder = @"TestFiles\Input\";
                engine.OutputFolder = @"TestFiles\Output\";
                engine.CleanOutputPath();

                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                CopyFiles copyFiles = new CopyFiles("../*.txt").FromTopDirectoryOnly();

                // When
                IEnumerable<IDocument> outputs = copyFiles.Execute(inputs, context).ToList();
                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable) document).Dispose();
                }

                // Then
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-a.txt")));
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-b.txt")));
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory,
                        @"TestFiles\Output\Subfolder\test-c.txt")));
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory,
                        @"TestFiles\Output\test-above-input.txt")));
            }
Ejemplo n.º 2
0
            public void ExtensionWithoutDotWritesFile()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs     = { context.GetDocument("Test") };
                WriteFiles  writeFiles = new WriteFiles("txt");

                // When
                IEnumerable <IDocument> outputs = writeFiles.Execute(inputs, context).ToList();

                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.IsTrue(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\write-test.txt")));
                Assert.AreEqual("Test", File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\write-test.txt")));
            }
Ejemplo n.º 3
0
            public void WriteFilesSetsMetadata(string key, string expectedEnding)
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs     = { context.GetDocument("Test") };
                WriteFiles  writeFiles = new WriteFiles("txt");

                // When
                IDocument output = writeFiles.Execute(inputs, context).First();

                foreach (IDocument document in inputs)
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.That(output.Metadata[key], Does.EndWith(expectedEnding));
                ((IDisposable)output).Dispose();
            }
Ejemplo n.º 4
0
            public void CopyWithSearchPatternTopDirectoryOnly()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder  = @"TestFiles\Input\";
                engine.OutputFolder = @"TestFiles\Output\";
                engine.CleanOutputPath();

                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs    = { context.GetDocument("Test") };
                CopyFiles   copyFiles = new CopyFiles("*.txt").FromTopDirectoryOnly();

                // When
                IEnumerable <IDocument> outputs = copyFiles.Execute(inputs, context).ToList();

                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-a.txt")));
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-b.txt")));
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory,
                                             @"TestFiles\Output\Subfolder\test-c.txt")));
            }
Ejemplo n.º 5
0
            public void CopyNonExistentFolder()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder  = @"TestFiles\Input\";
                engine.OutputFolder = @"TestFiles\Output\";
                engine.CleanOutputPath();

                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs    = { context.GetDocument("Test") };
                CopyFiles   copyFiles = new CopyFiles("NonExistent\\*.txt");

                // When
                IEnumerable <IDocument> outputs = copyFiles.Execute(inputs, context).ToList();

                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                // No exception should be thrown
            }
Ejemplo n.º 6
0
            public void IgnoresEmptyDocuments()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.OutputFolder = @"TestFiles\Output\";
                Pipeline          pipeline    = new Pipeline("Pipeline", null);
                MemoryStream      emptyStream = new MemoryStream(new byte[] { });
                IExecutionContext context     = new ExecutionContext(engine, pipeline);

                IDocument[] inputs =
                {
                    context.GetDocument("Test",
                                        new MetadataItems {
                        new MetadataItem(Keys.RelativeFilePath,@"Subfolder/write-test")
                    }),
                    context.GetDocument(string.Empty,
                                        new MetadataItems {
                        new MetadataItem(Keys.RelativeFilePath,@"Subfolder/empty-test"),
                    }),
                    context.GetDocument((string)null,
                                        new MetadataItems {
                        new MetadataItem(Keys.RelativeFilePath,@"Subfolder/null-test")
                    }),
                    context.GetDocument(emptyStream,
                                        new MetadataItems {
                        new MetadataItem(Keys.RelativeFilePath,@"Subfolder/stream-test")
                    })
                };
                WriteFiles writeFiles = new WriteFiles();

                // When
                IEnumerable <IDocument> outputs = writeFiles.Execute(inputs, context).ToList();

                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(4, outputs.Count());
                Assert.IsTrue(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\write-test")));
                Assert.IsFalse(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\empty-test")));
                Assert.IsFalse(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\null-test")));
                Assert.IsFalse(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\Subfolder\stream-test")));
            }
Ejemplo n.º 7
0
            public void SitemapGeneratedWithSitemapItem(string hostname, string formatterString, string expected)
            {
                // Given
                Engine engine = new Engine();

                if (!string.IsNullOrWhiteSpace(hostname))
                {
                    engine.InitialMetadata[Keys.Hostname] = hostname;
                }
                Pipeline          contentPipeline = new Pipeline("Content", null);
                IExecutionContext context         = new ExecutionContext(engine, contentPipeline);

                IDocument doc = context.GetDocument("Test", new[]
                {
                    new KeyValuePair <string, object>(Keys.RelativeFilePath, "sub/testfile.html")
                });

                IDocument[] inputs = { doc };

                Core.Modules.Metadata.Meta m = new Core.Modules.Metadata.Meta(Keys.SitemapItem,
                                                                              (d, c) => new SitemapItem(d[Keys.RelativeFilePath].ToString()));
                var outputs = m.Execute(inputs, context);

                Func <string, string> formatter = null;

                if (!string.IsNullOrWhiteSpace(formatterString))
                {
                    formatter = f => string.Format(formatterString, f);
                }

                // When
                Sitemap          sitemap = new Sitemap(formatter);
                List <IDocument> results = sitemap.Execute(outputs.ToList(), context).ToList();

                foreach (IDocument document in inputs.Concat(outputs.ToList()))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(1, results.Count);
                Assert.That(results[0].Content, Does.Contain($"<loc>{expected}</loc>"));
            }
Ejemplo n.º 8
0
            public void ExecuteReturnsSameContent()
            {
                // Given
                Engine engine = new Engine();
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.SourceFileRoot] = @"TestFiles/Input";
                engine.InitialMetadata[Keys.SourceFileDir] = @"TestFiles/Input/Subfolder";
                engine.InitialMetadata[Keys.SourceFileBase] = @"write-test";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles((x, y) => null);

                // When
                IDocument output = writeFiles.Execute(inputs, context).First();

                // Then
                Assert.AreEqual("Test", output.Content);
                ((IDisposable)output).Dispose();
            }
Ejemplo n.º 9
0
            public void RelativePathsAreConsistentBeforeAndAfterWriteFiles()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder  = @"TestFiles\Input";
                engine.OutputFolder = @"TestFiles\Output\";
                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs     = { context.GetDocument() };
                ReadFiles   readFiles  = new ReadFiles(@"test-c.txt");
                WriteFiles  writeFiles = new WriteFiles("txt");

                // When
                IDocument readFilesDocument              = readFiles.Execute(inputs, context).First();
                object    readFilesRelativeFilePath      = readFilesDocument.Metadata[Keys.RelativeFilePath];
                object    readFilesRelativeFilePathBase  = readFilesDocument.Metadata[Keys.RelativeFilePathBase];
                object    readFilesRelativeFileDir       = readFilesDocument.Metadata[Keys.RelativeFileDir];
                IDocument writeFilesDocument             = writeFiles.Execute(new [] { readFilesDocument }, context).First();
                object    writeFilesRelativeFilePath     = writeFilesDocument.Metadata[Keys.RelativeFilePath];
                object    writeFilesRelativeFilePathBase = writeFilesDocument.Metadata[Keys.RelativeFilePathBase];
                object    writeFilesRelativeFileDir      = writeFilesDocument.Metadata[Keys.RelativeFileDir];

                foreach (IDocument document in inputs)
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(@"Subfolder\test-c.txt", readFilesRelativeFilePath);
                Assert.AreEqual(@"Subfolder\test-c", readFilesRelativeFilePathBase);
                Assert.AreEqual(@"Subfolder", readFilesRelativeFileDir);
                Assert.AreEqual(@"Subfolder\test-c.txt", writeFilesRelativeFilePath);
                Assert.AreEqual(@"Subfolder\test-c", writeFilesRelativeFilePathBase);
                Assert.AreEqual(@"Subfolder", writeFilesRelativeFileDir);
                ((IDisposable)readFilesDocument).Dispose();
                ((IDisposable)writeFilesDocument).Dispose();
            }
Ejemplo n.º 10
0
            public void ExecuteReturnsSameContent()
            {
                // Given
                Engine engine = new Engine();

                engine.RootFolder   = TestContext.CurrentContext.TestDirectory;
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.SourceFileRoot] = @"TestFiles/Input";
                engine.InitialMetadata[Keys.SourceFileDir]  = @"TestFiles/Input/Subfolder";
                engine.InitialMetadata[Keys.SourceFileBase] = @"write-test";
                Pipeline          pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context  = new ExecutionContext(engine, pipeline);

                IDocument[] inputs     = { context.GetDocument("Test") };
                WriteFiles  writeFiles = new WriteFiles((x, y) => null);

                // When
                IDocument output = writeFiles.Execute(inputs, context).First();

                // Then
                Assert.AreEqual("Test", output.Content);
                ((IDisposable)output).Dispose();
            }
Ejemplo n.º 11
0
            public void CopyWithSearchPatternRecursive()
            {
                // Given
                Engine engine = new Engine();
                engine.RootFolder = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder = @"TestFiles\Input\";
                engine.OutputFolder = @"TestFiles\Output\";

                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                CopyFiles copyFiles = new CopyFiles("*.txt");

                // When
                IEnumerable<IDocument> outputs = copyFiles.Execute(inputs, context).ToList();
                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable) document).Dispose();
                }

                // Then
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-a.txt")));
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\test-b.txt")));
                Assert.IsTrue(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory,
                        @"TestFiles\Output\Subfolder\test-c.txt")));
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Output\markdown-x.md")));
                Assert.IsFalse(
                    File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory,
                        @"TestFiles\Output\Subfolder\markdown-y.md")));
            }
Ejemplo n.º 12
0
            public void CopyNonExistentFolder()
            {
                // Given
                Engine engine = new Engine();
                engine.RootFolder = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder = @"TestFiles\Input\";
                engine.OutputFolder = @"TestFiles\Output\";
                engine.CleanOutputPath();

                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                CopyFiles copyFiles = new CopyFiles("NonExistent\\*.txt");

                // When
                IEnumerable<IDocument> outputs = copyFiles.Execute(inputs, context).ToList();
                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable) document).Dispose();
                }

                // Then
                // No exception should be thrown
            }
Ejemplo n.º 13
0
            public void ExtensionWithDotWritesFile()
            {
                // Given
                Engine engine = new Engine();
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles(".txt");

                // When
                IEnumerable<IDocument> outputs = writeFiles.Execute(inputs, context).ToList();
                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.IsTrue(File.Exists(@"TestFiles\Output\Subfolder\write-test.txt"));
                Assert.AreEqual("Test", File.ReadAllText(@"TestFiles\Output\Subfolder\write-test.txt"));
            }
Ejemplo n.º 14
0
            public void WriteFilesSetsMetadata(string key, string expectedEnding)
            {
                // Given
                Engine engine = new Engine();
                engine.OutputFolder = @"TestFiles\Output\";
                engine.InitialMetadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles("txt");

                // When
                IDocument output = writeFiles.Execute(inputs, context).First();
                foreach (IDocument document in inputs)
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.That(output.Metadata[key], Does.EndWith(expectedEnding));
                ((IDisposable)output).Dispose();
            }
Ejemplo n.º 15
0
            public void RelativePathsAreConsistentBeforeAndAfterWriteFiles()
            {
                // Given
                Engine engine = new Engine();
                engine.RootFolder = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder = @"TestFiles\Input";
                engine.OutputFolder = @"TestFiles\Output\";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument() };
                ReadFiles readFiles = new ReadFiles(@"test-c.txt");
                WriteFiles writeFiles = new WriteFiles("txt");

                // When
                IDocument readFilesDocument = readFiles.Execute(inputs, context).First();
                object readFilesRelativeFilePath = readFilesDocument.Metadata[Keys.RelativeFilePath];
                object readFilesRelativeFilePathBase = readFilesDocument.Metadata[Keys.RelativeFilePathBase];
                object readFilesRelativeFileDir = readFilesDocument.Metadata[Keys.RelativeFileDir];
                IDocument writeFilesDocument = writeFiles.Execute(new [] { readFilesDocument }, context).First();
                object writeFilesRelativeFilePath = writeFilesDocument.Metadata[Keys.RelativeFilePath];
                object writeFilesRelativeFilePathBase = writeFilesDocument.Metadata[Keys.RelativeFilePathBase];
                object writeFilesRelativeFileDir = writeFilesDocument.Metadata[Keys.RelativeFileDir];
                foreach (IDocument document in inputs)
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(@"Subfolder\test-c.txt", readFilesRelativeFilePath);
                Assert.AreEqual(@"Subfolder\test-c", readFilesRelativeFilePathBase);
                Assert.AreEqual(@"Subfolder", readFilesRelativeFileDir);
                Assert.AreEqual(@"Subfolder\test-c.txt", writeFilesRelativeFilePath);
                Assert.AreEqual(@"Subfolder\test-c", writeFilesRelativeFilePathBase);
                Assert.AreEqual(@"Subfolder", writeFilesRelativeFileDir);
                ((IDisposable)readFilesDocument).Dispose();
                ((IDisposable)writeFilesDocument).Dispose();
            }
Ejemplo n.º 16
0
            public void IgnoresEmptyDocuments()
            {
                // Given
                Engine engine = new Engine();
                engine.OutputFolder = @"TestFiles\Output\";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                MemoryStream emptyStream = new MemoryStream(new byte[] { });
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument("Test",
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, @"Subfolder/write-test")
                        }),
                    context.GetDocument(string.Empty,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, @"Subfolder/empty-test"),
                        }),
                    context.GetDocument((string)null,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, @"Subfolder/null-test")
                        }),
                    context.GetDocument(emptyStream,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, @"Subfolder/stream-test")
                        })
                };
                WriteFiles writeFiles = new WriteFiles();

                // When
                IEnumerable<IDocument> outputs = writeFiles.Execute(inputs, context).ToList();
                foreach (IDocument document in inputs.Concat(outputs))
                {
                    ((IDisposable)document).Dispose();
                }

                // Then
                Assert.AreEqual(4, outputs.Count());
                Assert.IsTrue(File.Exists(@"TestFiles\Output\Subfolder\write-test"));
                Assert.IsFalse(File.Exists(@"TestFiles\Output\Subfolder\empty-test"));
                Assert.IsFalse(File.Exists(@"TestFiles\Output\Subfolder\null-test"));
                Assert.IsFalse(File.Exists(@"TestFiles\Output\Subfolder\stream-test"));
            }