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(); }
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")); }
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"))); }
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(); }
public void OutputDocumentContainsSameContent() { // Given IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("Test")) }; WriteFiles writeFiles = new WriteFiles((x, y) => null); // When IDocument output = writeFiles.Execute(inputs, Context).ToList().First(); // Then Assert.AreEqual("Test", output.Content); }
public void ShouldReturnOriginalDocumentForFailedPredicate() { // Given IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("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); }
public void ShouldReturnNullBasePathsForDotFiles() { // Given IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("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]); }
public void ShouldWriteDotFile() { // Given IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("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()); }
public void ShouldSetDirectoryPathMetadata(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 <DirectoryPath>(result); Assert.AreEqual(expected, ((DirectoryPath)result).FullPath); }
public void ExtensionWithoutDotWritesFiles() { // Given Engine.Settings[Keys.RelativeFilePath] = new FilePath("Subfolder/write-test.abc"); IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("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()); }
public void ShouldSetStringMetadata(string key, string expected) { // Given Engine.Settings[Keys.RelativeFilePath] = new FilePath("Subfolder/write-test.abc"); IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("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); }
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")); }
public void IgnoresEmptyDocuments() { // Given MemoryStream emptyStream = new MemoryStream(new byte[] { }); IDocument[] inputs = { Context.GetDocument( Context.GetContentStream("Test"), new MetadataItems { new MetadataItem(Keys.RelativeFilePath,new FilePath("Subfolder/write-test")) }), Context.GetDocument( Context.GetContentStream(string.Empty), new MetadataItems { new MetadataItem(Keys.RelativeFilePath,new FilePath("Subfolder/empty-test")), }), Context.GetDocument( (Stream)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); }
public void DocumentsWithSameOutputGeneratesWarning() { // Given IDocument[] inputs = new[] { Context.GetDocument(new FilePath("/a.txt"), Context.GetContentStream("A")), Context.GetDocument(new FilePath("/b.txt"), Context.GetContentStream("B")), Context.GetDocument(new FilePath("/c.txt"), Context.GetContentStream("C")), Context.GetDocument(new FilePath("/d.txt"), Context.GetContentStream("D")), Context.GetDocument(new FilePath("/e.txt"), Context.GetContentStream("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"); }
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(); }
public void InputDocumentsAreEvaluatedInOrderWhenAppending() { // Given IDocument[] inputs = new[] { Context.GetDocument(Context.GetContentStream("A")), Context.GetDocument(Context.GetContentStream("B")), Context.GetDocument(Context.GetContentStream("C")), Context.GetDocument(Context.GetContentStream("D")), Context.GetDocument(Context.GetContentStream("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()); }
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(); }
public void ExecuteReturnsSameContent() { // Given Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.OutputFolder = @"TestFiles\Output\"; engine.Metadata[Keys.SourceFileRoot] = @"TestFiles/Input"; engine.Metadata[Keys.SourceFileDir] = @"TestFiles/Input/Subfolder"; engine.Metadata[Keys.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(); }
public void ShouldTruncateOldFileOnWrite() { // Given const string fileName = "test.txt"; const string oldContent = "TestTest"; const string newContent = "Test"; IFile fileMock = Engine.FileSystem.GetOutputFile(fileName); fileMock.WriteAllText(oldContent); WriteFiles writeFiles = new WriteFiles((x, y) => fileName); IDocument[] inputs = { Context.GetDocument(Context.GetContentStream(newContent)) }; // When writeFiles.Execute(inputs, Context).ToList(); // Then IFile outputFile = Engine.FileSystem.GetOutputFile(fileName); Assert.AreEqual(newContent, outputFile.ReadAllText()); }
public void InputDocumentsAreEvaluatedInOrderWhenOverwritting() { // Given ThrowOnTraceEventType(TraceEventType.Error); 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"); // When writeFiles.Execute(inputs, Context).ToList(); // Then IFile outputFile = Engine.FileSystem.GetOutputFile("output.txt"); Assert.IsTrue(outputFile.Exists); Assert.AreEqual("E", outputFile.ReadAllText()); }