Ejemplo n.º 1
0
        public void LoadLayoutFile()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"Layout\Test.cshtml");
            Razor razor = new Razor();
            engine.Pipelines.Add("Pipeline", readFiles, razor);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual("LAYOUT\r\n\r\n<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().Content);
        }
Ejemplo n.º 2
0
        public void AlternateIgnorePrefix()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"AlternateIgnorePrefix\*.cshtml");
            Razor razor = new Razor().IgnorePrefix("Ignore");
            engine.Pipelines.Add("Pipeline", readFiles, razor);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual(@"<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().Content);
        }
Ejemplo n.º 3
0
        public void IgnoresUnderscoresByDefault()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"IgnoreUnderscores\*.cshtml");
            Razor razor = new Razor();
            Meta meta = new Meta("Content", (x, y) => x.Content);
            engine.Pipelines.Add("Pipeline", readFiles, razor, meta);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual("LAYOUT\r\n\r\n<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().String("Content"));
        }
Ejemplo n.º 4
0
        public void AlternateViewStartPath()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"AlternateViewStartPath\Test.cshtml");
            Razor razor = new Razor().WithViewStart(@"AlternateViewStart\_ViewStart.cshtml");
            Meta meta = new Meta("Content", (x, y) => x.Content);
            engine.Pipelines.Add("Pipeline", readFiles, razor, meta);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual("LAYOUT\r\n<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().String("Content"));
        }
Ejemplo n.º 5
0
        public void PrepareSetsMetadata(string key, string expectedEnding)
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            IDocument[] inputs = { new Document(metadata) };
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            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));
        }
Ejemplo n.º 6
0
        public void ExecuteGetsCorrectContent()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            IDocument[] inputs = { new Document(metadata) };
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            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);
        }
Ejemplo n.º 7
0
        public void SearchPatternFindsCorrectFiles(string searchPattern, SearchOption searchOption, int expectedCount)
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            Metadata metadata = new Metadata(engine);
            IDocument[] inputs = { new Document(metadata) };
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles(searchPattern).SearchOption(searchOption);

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

            // Then
            Assert.AreEqual(expectedCount, count);
        }
Ejemplo n.º 8
0
        public void SearchPatternWorksWithInputPathTrailingSlash()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(metadata, 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);
        }
Ejemplo n.º 9
0
        public void RenderLayoutSectionOnMultipleExecution()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"LayoutWithSection\Test.cshtml");
            Razor razor = new Razor();
            Meta meta = new Meta("Content", (x, y) => x.Content);
            engine.Pipelines.Add("Pipeline", readFiles, razor, meta);

            // When
            engine.Execute();
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual("LAYOUT\r\n\r\n<p>Section Content</p>\r\n\r\n\r\n<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().String("Content"));
        }
Ejemplo n.º 10
0
        public void LoadSimpleTemplateFile()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input\";
            ReadFiles readFiles = new ReadFiles(@"SimpleTemplate\Test.cshtml");
            Razor razor = new Razor();
            Meta meta = new Meta("Content", (x, y) => x.Content);
            engine.Pipelines.Add("Pipeline", readFiles, razor, meta);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Count());
            Assert.AreEqual(@"<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().String("Content"));
        }
Ejemplo n.º 11
0
        public void SearchPatternWorksWithSubpath()
        {
            // Given
            Engine engine = new Engine();
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            IDocument[] inputs = { new Document(metadata) };
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles(@"Subfolder\*.txt");

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

            // Then
            Assert.AreEqual(1, count);
        }
Ejemplo n.º 12
0
        public void WithExtensionsWorksWithoutDotPrefix()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(metadata, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            ReadFiles readFiles = new ReadFiles("*.*").WithExtensions("txt", "md");

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

            // Then
            Assert.AreEqual(5, count);
        }
Ejemplo n.º 13
0
        public void WhereGetsCorrectFiles()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            engine.InputFolder = @"TestFiles\Input";
            Metadata metadata = new Metadata(engine);
            Pipeline pipeline = new Pipeline("Pipeline", engine, null);
            IDocument[] inputs = { new Document(metadata, pipeline) };
            IExecutionContext context = new ExecutionContext(engine, pipeline);
            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);
        }