コード例 #1
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void ExtensionWithoutDotWritesFiles()
            {
                // Given
                Engine.InitialMetadata[Keys.RelativeFilePath] = new FilePath("Subfolder/write-test.abc");
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles("txt");

                // When
                writeFiles.Execute(inputs, Context).ToList();

                // Then
                IFile outputFile = Engine.FileSystem.GetOutputFile("Subfolder/write-test.txt");
                Assert.IsTrue(outputFile.Exists);
                Assert.AreEqual("Test", outputFile.ReadAllText());
            }
コード例 #2
0
ファイル: WriteFilesTests.cs プロジェクト: ryanrousseau/Wyam
            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();
            }
コード例 #3
0
ファイル: WriteFilesFixture.cs プロジェクト: martinvobr/Wyam
        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"));
        }
コード例 #4
0
ファイル: WriteFilesFixture.cs プロジェクト: martinvobr/Wyam
        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"));
        }
コード例 #5
0
ファイル: WriteFilesFixture.cs プロジェクト: martinvobr/Wyam
        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();
        }
コード例 #6
0
ファイル: WriteFilesFixture.cs プロジェクト: martinvobr/Wyam
        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();
        }
コード例 #7
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void ShouldWriteDotFile()
            {
                // Given
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles((x, y) => ".dotfile");

                // When
                writeFiles.Execute(inputs, Context).ToList();

                // Then
                IFile outputFile = Engine.FileSystem.GetOutputFile(".dotfile");
                Assert.IsTrue(outputFile.Exists);
                Assert.AreEqual("Test", outputFile.ReadAllText());
            }
コード例 #8
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void IgnoresEmptyDocuments()
            {
                // Given
                MemoryStream emptyStream = new MemoryStream(new byte[] { });
                IDocument[] inputs =
                {
                    Context.GetDocument("Test",
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, new FilePath("Subfolder/write-test"))
                        }),
                    Context.GetDocument(string.Empty,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, new FilePath("Subfolder/empty-test")),
                        }),
                    Context.GetDocument((string)null,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, new FilePath("Subfolder/null-test"))
                        }),
                    Context.GetDocument(emptyStream,
                        new MetadataItems {
                            new MetadataItem(Keys.RelativeFilePath, new FilePath(@"Subfolder/stream-test"))
                        })
                    };
                WriteFiles writeFiles = new WriteFiles();

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

                // Then
                Assert.AreEqual(4, outputs.Count());
                Assert.IsTrue(Context.FileSystem.GetOutputFile("Subfolder/write-test").Exists);
                Assert.IsFalse(Context.FileSystem.GetOutputFile("output/Subfolder/empty-test").Exists);
                Assert.IsFalse(Context.FileSystem.GetOutputFile("output/Subfolder/null-test").Exists);
                Assert.IsFalse(Context.FileSystem.GetOutputFile("output/Subfolder/stream-test").Exists);
            }
コード例 #9
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void ShouldSetStringMetadata(string key, string expected)
            {
                // Given
                Engine.InitialMetadata[Keys.RelativeFilePath] = new FilePath("Subfolder/write-test.abc");
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles(".txt");

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

                // Then
                object result = output[key];
                Assert.IsInstanceOf<string>(result);
                Assert.AreEqual(expected, result);
            }
コード例 #10
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void InputDocumentsAreEvaluatedInOrderWhenAppending()
            {
                // Given
                IDocument[] inputs = new[]
                {
                    Context.GetDocument("A"),
                    Context.GetDocument("B"),
                    Context.GetDocument("C"),
                    Context.GetDocument("D"),
                    Context.GetDocument("E"),
                };
                WriteFiles writeFiles = new WriteFiles((x, y) => "output.txt").Append();

                // When
                writeFiles.Execute(inputs, Context).ToList();

                // Then
                IFile outputFile = Engine.FileSystem.GetOutputFile("output.txt");
                Assert.IsTrue(outputFile.Exists);
                Assert.AreEqual("ABCDE", outputFile.ReadAllText());
            }
コード例 #11
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void DocumentsWithSameOutputGeneratesWarning()
            {
                // Given
                IDocument[] inputs = new[]
                {
                    Context.GetDocument(new FilePath("/a.txt"), "A"),
                    Context.GetDocument(new FilePath("/b.txt"), "B"),
                    Context.GetDocument(new FilePath("/c.txt"), "C"),
                    Context.GetDocument(new FilePath("/d.txt"), "D"),
                    Context.GetDocument(new FilePath("/e.txt"), "E"),
                };
                WriteFiles writeFiles = new WriteFiles((x, y) => "output.txt");

                // When, Then
                Assert.Throws<Exception>(() => writeFiles.Execute(inputs, Context).ToList(), @"Multiple documents output to output.txt (this probably wasn't intended):
  /a.txt
  /b.txt
  /c.txt
  /d.txt
  /e.txt");
            }
コード例 #12
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void ShouldReturnOriginalDocumentForFailedPredicate()
            {
                // Given
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles((x, y) => null).Where((x, y) => false);

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

                // Then
                Assert.AreEqual("Test", output.Content);
            }
コード例 #13
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void OutputDocumentContainsSameContent()
            {
                // Given
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles((x, y) => null);

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

                // Then
                Assert.AreEqual("Test", output.Content);
            }
コード例 #14
0
ファイル: WriteFilesTests.cs プロジェクト: ibebbs/Wyam
            public void ShouldReturnNullBasePathsForDotFiles()
            {
                // Given
                IDocument[] inputs = new[] { Context.GetDocument("Test") };
                WriteFiles writeFiles = new WriteFiles((x, y) => ".dotfile");

                // When
                IDocument document = writeFiles.Execute(inputs, Context).ToList().First();

                // Then
                Assert.IsNull(document[Keys.DestinationFileBase]);
                Assert.IsNull(document[Keys.DestinationFilePathBase]);
                Assert.IsNull(document[Keys.RelativeFilePathBase]);
            }