Exemplo n.º 1
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);
            }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
            public void ReadFilesSetsMetadata(string key, string expectedEnding)
            {
                // 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-c.txt");

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

                // Then
                Assert.That(output.Metadata[key], Does.EndWith(expectedEnding));
                ((IDisposable) output).Dispose();
            }
Exemplo n.º 5
0
            public void WithExtensionsWorksWithoutDotPrefix()
            {
                // 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("*.*").WithExtensions("txt", "md");

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

                // Then
                Assert.AreEqual(5, count);
            }
Exemplo n.º 6
0
            public void WhereGetsCorrectFiles()
            {
                // 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("*.*").Where(x => x.Contains("test"));

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

                // Then
                Assert.AreEqual(3, count);
            }
Exemplo n.º 7
0
            public void PatternWorksWithSubpath()
            {
                // Given
                ReadFiles readFiles = new ReadFiles("Subfolder/*.txt");

                // When
                IEnumerable<IDocument> documents = readFiles.Execute(Inputs, Context);

                // Then
                Assert.AreEqual(1, documents.Count());
            }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
            public void PredicateShouldReturnMatchingFiles()
            {
                // Given
                ReadFiles readFiles = new ReadFiles("**/*").Where(x => x.Path.FullPath.Contains("test"));

                // When
                IEnumerable<IDocument> documents = readFiles.Execute(Inputs, Context).ToList();

                // Then
                Assert.AreEqual(3, documents.Count());
            }
Exemplo n.º 10
0
            public void WorksWithMultipleExtensions()
            {
                // Given
                ReadFiles readFiles = new ReadFiles("**/*.{txt,md}");

                // When
                IEnumerable<IDocument> documents = readFiles.Execute(Inputs, Context).ToList();

                // Then
                Assert.AreEqual(5, documents.Count());
            }
Exemplo n.º 11
0
            public void ShouldSetStringMetadata(string key, string expected)
            {
                // Given
                ReadFiles readFiles = new ReadFiles("**/test-c.txt");

                // When
                IDocument output = readFiles.Execute(Inputs, Context).ToList().First();

                // Then
                object result = output[key];
                Assert.IsInstanceOf<string>(result);
                Assert.AreEqual(expected, result);
            }
Exemplo n.º 12
0
            public void GetsCorrectContent()
            {
                // Given
                ReadFiles readFiles = new ReadFiles("test-a.txt");

                // When
                IDocument document = readFiles.Execute(Inputs, Context).ToList().First();

                // Then
                Assert.AreEqual("aaa", document.Content);
            }
Exemplo n.º 13
0
            public void ShouldReturnNullBasePathsForDotFiles()
            {
                // Given
                ReadFiles readFiles = new ReadFiles(".dotfile");

                // When
                IDocument document = readFiles.Execute(Inputs, Context).ToList().First();

                // Then
                Assert.IsNull(document[Keys.SourceFileBase]);
                Assert.IsNull(document[Keys.SourceFilePathBase]);
                Assert.IsNull(document[Keys.RelativeFilePathBase]);
            }
Exemplo n.º 14
0
            public void PatternWorksWithSingleFile()
            {
                // Given
                ReadFiles readFiles = new ReadFiles("test-a.txt");

                // When
                IEnumerable<IDocument> documents = readFiles.Execute(Inputs, Context).ToList();

                // Then
                Assert.AreEqual(1, documents.Count());
            }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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 output = readFiles.Execute(inputs, context).First();
            foreach (IDocument document in inputs)
            {
                ((IDisposable)document).Dispose();
            }

            // Then
            Assert.That(output.Metadata[key], Is.StringEnding(expectedEnding));
            ((IDisposable)output).Dispose();
        }
Exemplo n.º 17
0
            public void PatternFindsCorrectFiles(string pattern, int expectedCount)
            {
                // Given
                ReadFiles readFiles = new ReadFiles(pattern);

                // When
                IEnumerable<IDocument> documents = readFiles.Execute(Inputs, Context).ToList();

                // Then
                Assert.AreEqual(expectedCount, documents.Count());
            }
Exemplo n.º 18
0
            public void SearchPatternFindsCorrectFiles(string searchPattern, SearchOption searchOption,
                int expectedCount)
            {
                // 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(searchPattern).WithSearchOption(searchOption);

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

                // Then
                Assert.AreEqual(expectedCount, count);
            }
Exemplo n.º 19
0
            public void SearchPatternWorksWithSubpath()
            {
                // 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(@"Subfolder\*.txt");

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

                // Then
                Assert.AreEqual(1, count);
            }
Exemplo n.º 20
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();
        }
Exemplo n.º 21
0
        public void SearchPatternWorksWithSingleFile()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.RootFolder = TestContext.CurrentContext.TestDirectory;
            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
            IEnumerable<IDocument> documents = readFiles.Execute(inputs, context);
            int count = documents.Count();
            
            // Then
            Assert.AreEqual(1, count);
        }