public void DefaultCtorIgnoresDelimiterOnFirstLine()
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs =
                {
                    context.GetDocument(@"---
                FM1
                FM2
                ---
                Content1
                Content2")
                };
                string frontMatterContent = null;
                FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
                {
                    frontMatterContent = x.Content;
                    return new[] {x};
                }));

                // When
                IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

                // Then
                Assert.AreEqual(1, documents.Count());
                Assert.AreEqual(@"FM1
                FM2
                ", frontMatterContent);
                Assert.AreEqual(@"Content1
                Content2", documents.First().Content);
            }
Exemple #2
0
        public void DefaultCtorSplitsAtDashes()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(@"FM1
            FM2
            ---
            Content1
            Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
            {
                frontMatterContent = x.Content;
                return new [] {x};
            }));

            // When
            IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

            // Then
            Assert.AreEqual(1, documents.Count());
            Assert.AreEqual(@"FM1
            FM2
            ", frontMatterContent);
            Assert.AreEqual(@"Content1
            Content2", documents.First().Content);
        }
Exemple #3
0
        public void CopyWithSearchPatternRecursive()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.RootFolder = TestContext.CurrentContext.TestDirectory;
            engine.InputFolder= @"TestFiles\Input\";
            engine.OutputFolder = @"TestFiles\Output\";

            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline).Clone("Test") };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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")));
        }
Exemple #4
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")));
            }
Exemple #5
0
        public void DashStringDoesNotSplitAtNonmatchingDashes()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(@"FM1
            FM2
            ---
            Content1
            Content2") };
            bool executed = false;
            FrontMatter frontMatter = new FrontMatter("-", new Execute((x, ctx) =>
            {
                executed = true;
                return new[] { x };
            }));

            // When
            IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

            // Then
            Assert.AreEqual(1, documents.Count());
            Assert.IsFalse(executed);
            Assert.AreEqual(@"FM1
            FM2
            ---
            Content1
            Content2", documents.First().Content);
        }
Exemple #6
0
        public void SitemapGeneratedWithSitemapItem(string hostname, string formatterString, string expected)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());

            if (!string.IsNullOrWhiteSpace(hostname))
                engine.Metadata[Keys.Hostname] = hostname;

            Pipeline contentPipeline = new Pipeline("Content", engine, null);
            var doc = new Document(engine, contentPipeline).Clone("Test", new[] { new KeyValuePair<string, object>(Keys.RelativeFilePath, "sub/testfile.html") });
            IDocument[] inputs = { doc };

            IExecutionContext context = new ExecutionContext(engine, contentPipeline);
            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>"));
        }
 public IPipeline Add(string name, bool processDocumentsOnce, params IModule[] modules)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         name = "Pipeline " + (_pipelines.Count + 1);
     }
     if (_pipelines.ContainsKey(name))
     {
         throw new ArgumentException("Pipelines must have a unique name.");
     }
     Pipeline pipeline = new Pipeline(name, processDocumentsOnce, _engine, modules);
     _pipelines.Add(name, pipeline);
     return pipeline;
 }
Exemple #8
0
            public void ExecuteGetsCorrectContent()
            {
                // Given
                Engine engine = new Engine();
                engine.RootFolder = TestContext.CurrentContext.TestDirectory;
                engine.InputFolder = @"TestFiles\Input";
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument() };
                ReadFiles readFiles = new ReadFiles(@"test-a.txt");

                // When
                IDocument document = readFiles.Execute(inputs, context).First();

                // Then
                Assert.AreEqual("aaa", document.Content);
            }
Exemple #9
0
        public void ExecuteGetsCorrectContent()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles(@"test-a.txt");

            // When
            IDocument document = readFiles.Execute(inputs, context).First();

            // Then
            Assert.AreEqual("aaa", document.Content);
        }
Exemple #10
0
        public void ReadFilesSetsMetadata(string key, string expectedEnding)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles(@"test-c.txt");

            // When
            IDocument document = readFiles.Execute(inputs, context).First();

            // Then
            Assert.That(document.Metadata[key], Is.StringEnding(expectedEnding));
        }
Exemple #11
0
            public void FileNameIsConvertedCorrectly(string input, string output)
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                IDocument[] inputs = { context.GetDocument(new MetadataItems
                {
                    new MetadataItem(Keys.SourceFileName, input)
                }) };
                FileName fileName = new FileName();

                // When
                IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

                // Then
                Assert.AreEqual(output, documents.First()[Keys.WriteFileName]);
            }
Exemple #12
0
        public void SearchPatternWorksWithoutInputPathTrailingSlash()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles("*.txt");

            // When
            IEnumerable<IDocument> documents = readFiles.Execute(inputs, context);
            int count = documents.Count();
            
            // Then
            Assert.AreEqual(3, count);
        }
Exemple #13
0
        public void SearchPatternFindsCorrectFiles(string searchPattern, SearchOption searchOption, int expectedCount)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input\";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles(searchPattern).WithSearchOption(searchOption);

            // When
            IEnumerable<IDocument> documents = readFiles.Execute(inputs, context);
            int count = documents.Count();
            
            // Then
            Assert.AreEqual(expectedCount, count);
        }
Exemple #14
0
        public void FileNameIsConvertedCorrectly(string input, string output)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(new []
            {
                Common.Documents.Metadata.Create("SourceFileName", input)
            }) };
            FileName fileName = new FileName();

            // When
            IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

            // Then
            Assert.AreEqual(output, documents.First()["WriteFileName"]);
        }
Exemple #15
0
        public void StreamIsDisposedCorrectlyAfterClone()
        {
            // Given
            Engine engine = new Engine();
            Pipeline pipeline = new Pipeline("Test", engine, Array.Empty<IModule>());
            DisposeCheckStream stream = new DisposeCheckStream();
            Document originalDoc = new Document(engine, pipeline, "Test", stream, null, Array.Empty<KeyValuePair<string, object>>(), true);
            Document clonedDoc = (Document)originalDoc.Clone(Array.Empty<KeyValuePair<string, object>>());

            // When
            originalDoc.Dispose();
            bool originalDocDisposedStream = stream.Disposed;
            clonedDoc.Dispose();
            bool clonedDocDisposedStream = stream.Disposed;

            // Then
            Assert.AreEqual(false, originalDocDisposedStream);
            Assert.AreEqual(true, clonedDocDisposedStream);
        }
Exemple #16
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();
            }
Exemple #17
0
            public void FileNameIsConvertedCorrectlyWithReservedChar(string character)
            {
                // Given
                Engine engine = new Engine();
                Pipeline pipeline = new Pipeline("Pipeline", null);
                IExecutionContext context = new ExecutionContext(engine, pipeline);
                string manyCharactersWow = new String(character[0], 10);
                IDocument[] inputs = { context.GetDocument(new MetadataItems
                {
                    new MetadataItem(Keys.SourceFileName,
                        string.Format("testing {0} some of {0} these {0}", manyCharactersWow))
                }) };
                FileName fileName = new FileName();

                // When
                IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

                // Then
                Assert.AreEqual("testing-some-of-these-", documents.First()[Keys.WriteFileName]);
            }
Exemple #18
0
        public void ExecuteReturnsSameContent()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.OutputFolder = @"TestFiles\Output\";
            engine.Metadata["SourceFileRoot"] = @"TestFiles/Input";
            engine.Metadata["SourceFileDir"] = @"TestFiles/Input/Subfolder";
            engine.Metadata["SourceFileBase"] = @"write-test";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline).Clone("Test") };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            WriteFiles writeFiles = new WriteFiles((x, y) => null);

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

            // Then
            Assert.AreEqual("Test", output.Content);
            ((IDisposable)output).Dispose();
        }
Exemple #19
0
        public void FileNameIsConvertedCorrectlyWithReservedChar(string character)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            string manyCharactersWow = new String(character[0], 10);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(new []
            {
                Common.Documents.Metadata.Create("SourceFileName",
                    string.Format("testing {0} some of {0} these {0}", manyCharactersWow))
            }) };
            FileName fileName = new FileName();

            // When
            IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

            // Then
            Assert.AreEqual("testing-some-of-these-", documents.First()["WriteFileName"]);
        }
Exemple #20
0
		public void FileNameShouldBeLowercase()
		{
			// Given
			string input = "FileName With MiXeD CapS";
			string output = "filename-with-mixed-caps";

            Engine engine = new Engine();
			engine.Trace.AddListener(new TestTraceListener());
			Pipeline pipeline = new Pipeline("Pipeline", engine, null);
			IExecutionContext context = new ExecutionContext(engine, pipeline);
			IDocument[] inputs = { new Document(engine, pipeline).Clone(new []
			{
                new MetadataItem(Keys.SourceFileName, input)
			}) };
			FileName fileName = new FileName();

			// When
			IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

			// Then
			Assert.AreEqual(output, documents.First()[Keys.WriteFileName]);
		}
Exemple #21
0
        public void ExtensionWithoutDotWritesFile()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.OutputFolder = @"TestFiles\Output\";
            engine.Metadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline).Clone("Test") };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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"));
        }
Exemple #22
0
		public void WithAllowedCharactersDoesNotReplaceProvidedCharacters()
		{
			// Given
			string input = "this-is-a-.net-tag";
			string output = "this-is-a-.net-tag";

			Engine engine = new Engine();
			engine.Trace.AddListener(new TestTraceListener());
			Pipeline pipeline = new Pipeline("Pipeline", engine, null);
			IExecutionContext context = new ExecutionContext(engine, pipeline);
			IDocument[] inputs = { new Document(engine, pipeline).Clone(new []
			{
                new MetadataItem(Keys.SourceFileName, input)
			}) };
			FileName fileName = new FileName();

			// When
			fileName = fileName.WithAllowedCharacters(new string[] { "-" });
			IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

			// Then
			Assert.AreEqual(output, documents.First()[Keys.WriteFileName]);
        }
Exemple #23
0
        public void SingleCharWithRepeatedDelimiterWithTrailingSpacesSplitsAtCorrectLocation()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(@"FM1
            FM2
            !!!!
            Content1
            Content2") };
            string frontMatterContent = null;
            FrontMatter frontMatter = new FrontMatter('!', new Execute((x, ctx) =>
            {
                frontMatterContent = x.Content;
                return new[] { x };
            }));

            // When
            IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);

            // Then
            Assert.AreEqual(1, documents.Count());
            Assert.AreEqual(@"FM1
            FM2
            ", frontMatterContent);
            Assert.AreEqual(@"Content1
            Content2", documents.First().Content);
        }
Exemple #24
0
        public void IgnoresEmptyDocuments()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.OutputFolder = @"TestFiles\Output\";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            MemoryStream emptyStream = new MemoryStream(new byte[] { });
            IDocument[] inputs =
            {
                new Document(engine, pipeline).Clone("Test", 
                    new [] {
                        new MetadataItem(Keys.RelativeFilePath, @"Subfolder/write-test")
                    }),
                new Document(engine, pipeline).Clone(string.Empty,
                    new [] {
                        new MetadataItem(Keys.RelativeFilePath, @"Subfolder/empty-test"), 
                    }),
                new Document(engine, pipeline).Clone(null,
                    new [] {
                        new MetadataItem(Keys.RelativeFilePath, @"Subfolder/null-test")
                    }),
                new Document(engine, pipeline).Clone(emptyStream,
                    new [] {
                        new MetadataItem(Keys.RelativeFilePath, @"Subfolder/stream-test")
                    })
            };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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"));
        }
Exemple #25
0
        public void RelativePathsAreConsistentBeforeAndAfterWriteFiles()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            engine.OutputFolder = @"TestFiles\Output\";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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();
        }
Exemple #26
0
        public void WriteFilesSetsMetadata(string key, string expectedEnding)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.OutputFolder = @"TestFiles\Output\";
            engine.Metadata[Keys.RelativeFilePath] = @"Subfolder/write-test.abc";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline).Clone("Test") };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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], Is.StringEnding(expectedEnding));
            ((IDisposable)output).Dispose();
        }
Exemple #27
0
        public void TrimWhitespace()
        {
            // Given
            string input = "   myfile.html   ";
            string output = "myfile.html";

            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs =
            {
                new Document(engine, pipeline).Clone(new []
                {
                    new MetadataItem("MyKey", input)
                })
            };
            FileName fileName = new FileName("MyKey");

            // When
            IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

            // Then
            Assert.AreEqual(output, documents.First()[Keys.WriteFileName]);
        }
Exemple #28
0
        public void IgnoresNullOrWhiteSpaceStrings(string input)
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            IDocument[] inputs = { new Document(engine, pipeline).Clone(new []
            {
                new MetadataItem(Keys.SourceFileName, input)
            }) };
            FileName fileName = new FileName();

            // When
            IEnumerable<IDocument> documents = fileName.Execute(inputs, context);

            // Then
            Assert.IsFalse(documents.First().ContainsKey(Keys.WriteFileName));
        }
Exemple #29
0
        public void WhereAndWithExtensionsGetsCorrectFiles()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(engine, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles("*.*").Where(x => x.Contains("-c")).WithExtensions("txt");

            // When
            IEnumerable<IDocument> documents = readFiles.Execute(inputs, context);
            int count = documents.Count();

            // Then
            Assert.AreEqual(1, count);
        }
Exemple #30
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
            }