public void CompletedContentIsPopulatedAfterRun() { // Given Engine engine = new Engine(); int c = 0; engine.Pipelines.Add( new Execute((x, ctx) => new[] { x.Clone((c++).ToString()), x.Clone((c++).ToString()) }), new Execute((x, ctx) => new[] { x.Clone((c++).ToString()) }), new Meta("Content", (x, y) => x.Content)); // When engine.Execute(); // Then Assert.AreEqual(2, engine.Documents.FromPipeline("Pipeline 1").Count()); Assert.AreEqual("2", engine.Documents.FromPipeline("Pipeline 1").First().String("Content")); Assert.AreEqual("3", engine.Documents.FromPipeline("Pipeline 1").Skip(1).First().String("Content")); }
public void ExecuteAllExamples() { string path = Path.Combine(Assembly.GetExecutingAssembly().Location, "Examples"); while (!Directory.Exists(path)) { path = Directory.GetParent(path).Parent.FullName; path = Path.Combine(path, "Examples"); } int count = 0; foreach(string example in Directory.EnumerateDirectories(path)) { Console.WriteLine("Executing example " + example); Engine engine = new Engine { RootFolder = example }; string config = Path.Combine(example, "config.wyam"); if (File.Exists(config)) { Console.WriteLine("Loading configuration file"); engine.Configure(File.ReadAllText(config)); } engine.Execute(); count++; } Assert.AreEqual(4, count); }
public void CompletedContentIsPopulatedAfterRun() { // Given Engine engine = new Engine(); engine.CleanOutputPathOnExecute = false; int c = 0; engine.Pipelines.Add( new Execute((x, ctx) => new[] { ctx.GetDocument(x, (c++).ToString()), ctx.GetDocument(x, (c++).ToString()) }), new Execute((x, ctx) => new[] { ctx.GetDocument(x, (c++).ToString()) }), new Core.Modules.Metadata.Meta("Content", (x, y) => x.Content)); // When engine.Execute(); // Then Assert.AreEqual(2, engine.Documents.FromPipeline("Pipeline 1").Count()); Assert.AreEqual("2", engine.Documents.FromPipeline("Pipeline 1").First().String("Content")); Assert.AreEqual("3", engine.Documents.FromPipeline("Pipeline 1").Skip(1).First().String("Content")); }
public void ExecuteAllExamples(string example) { Engine engine = new Engine(); engine.Trace.AddListener(new TestTraceListener()); engine.RootFolder = example; engine.Config.Assemblies.LoadDirectory(TestContext.CurrentContext.TestDirectory); string config = Path.Combine(example, "config.wyam"); if (File.Exists(config)) { engine.Configure(File.ReadAllText(config)); } engine.Execute(); }
public void ExecuteAllExamples(string example) { Engine engine = new Engine { RootFolder = example }; engine.Trace.AddListener(new TestTraceListener()); string config = Path.Combine(example, "config.wyam"); if (File.Exists(config)) { engine.Configure(File.ReadAllText(config)); } engine.Execute(); }
public void IgnoresUnderscoresByDefault() { // Given Engine engine = new Engine(); engine.InputFolder = @"TestFiles\Input\"; ReadFiles readFiles = new ReadFiles(@"IgnoreUnderscores\*.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); }
public void AlternateViewStartPath() { // Given Engine engine = new Engine(); engine.InputFolder = @"TestFiles\Input\"; ReadFiles readFiles = new ReadFiles(@"AlternateViewStartPath\Test.cshtml"); Razor razor = new Razor().SetViewStart(@"AlternateViewStart\_ViewStart.cshtml"); engine.Pipelines.Add("Pipeline", readFiles, razor); // 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().Content); }
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); }
public void LoadSimpleTemplateFile() { // Given Engine engine = new Engine(); engine.InputFolder = @"TestFiles\Input\"; ReadFiles readFiles = new ReadFiles(@"SimpleTemplate\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(@"<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().Content); }
public void AlternateViewStartPath() { // Given Engine engine = new Engine(); engine.RootFolder = TestContext.CurrentContext.TestDirectory; 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")); }
public void CompletedMetadataIsPopulatedAfterRun() { // Given Engine engine = new Engine(); engine.CleanOutputPathOnExecute = false; int c = 0; engine.Pipelines.Add("Pipeline", new Execute((x, ctx) => new[] { ctx.GetDocument(x, (string)null, new Dictionary<string, object> { { c.ToString(), c++ } }), ctx.GetDocument(x, (string)null, new Dictionary<string, object> { { c.ToString(), c++ } }) }), new Execute((x, ctx) => new[] { ctx.GetDocument(x, (string)null, new Dictionary<string, object> { { c.ToString(), c++ } }) })); // When engine.Execute(); // Then Assert.AreEqual(2, engine.Documents.FromPipeline("Pipeline").Count()); Assert.IsTrue(engine.Documents.FromPipeline("Pipeline").First().Metadata.ContainsKey("0")); Assert.AreEqual(0, engine.Documents.FromPipeline("Pipeline").First().Metadata["0"]); Assert.IsTrue(engine.Documents.FromPipeline("Pipeline").First().Metadata.ContainsKey("2")); Assert.AreEqual(2, engine.Documents.FromPipeline("Pipeline").First().Metadata["2"]); Assert.IsFalse(engine.Documents.FromPipeline("Pipeline").First().Metadata.ContainsKey("1")); Assert.IsFalse(engine.Documents.FromPipeline("Pipeline").First().Metadata.ContainsKey("3")); Assert.IsTrue(engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata.ContainsKey("1")); Assert.AreEqual(1, engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata["1"]); Assert.IsTrue(engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata.ContainsKey("3")); Assert.AreEqual(3, engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata["3"]); Assert.IsFalse(engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata.ContainsKey("0")); Assert.IsFalse(engine.Documents.FromPipeline("Pipeline").Skip(1).First().Metadata.ContainsKey("2")); }
public void RenderLayoutSectionOnMultipleExecution() { // Given Engine engine = new Engine(); engine.RootFolder = TestContext.CurrentContext.TestDirectory; 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")); }
public void LoadSimpleTemplateFile() { // Given Engine engine = new Engine(); engine.RootFolder = TestContext.CurrentContext.TestDirectory; 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")); }
private bool Execute(Engine engine) { try { engine.Execute(); } catch (Exception) { return false; } return true; }
private bool Execute(Engine engine) { try { engine.Execute(); } catch (Exception ex) { engine.Trace.Critical("Error while executing: {0}", ex.Message); return false; } return true; }
public void LoadLayoutFile() { // Given Engine engine = new Engine(); engine.InputFolder = @"TestFiles\Input\"; ReadFiles readFiles = new ReadFiles(@"Layout\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("LAYOUT\r\n\r\n<p>This is a test</p>", engine.Documents.FromPipeline("Pipeline").First().String("Content")); }
private bool Execute(Engine engine) { if (!_noClean) { try { engine.Trace.Information("Cleaning output directory {0}", engine.OutputFolder); if (Directory.Exists(engine.OutputFolder)) { Directory.Delete(engine.OutputFolder, true); } engine.Trace.Information("Cleaned output directory."); } catch (Exception ex) { engine.Trace.Critical("Error while cleaning output directory: {0}", ex.Message); return false; } } try { engine.Execute(); } catch (Exception ex) { engine.Trace.Critical("Error while executing: {0}", ex.Message); return false; } return true; }
public void ExecuteResultsInCorrectCounts() { // Given Engine engine = new Engine(); CountModule a = new CountModule("A") { AdditionalOutputs = 1 }; CountModule b = new CountModule("B") { AdditionalOutputs = 2 }; CountModule c = new CountModule("C") { AdditionalOutputs = 3 }; engine.Pipelines.Add(a, b, c); // When engine.Execute(); // Then Assert.AreEqual(1, a.ExecuteCount); Assert.AreEqual(1, b.ExecuteCount); Assert.AreEqual(1, c.ExecuteCount); Assert.AreEqual(1, a.InputCount); Assert.AreEqual(2, b.InputCount); Assert.AreEqual(6, c.InputCount); Assert.AreEqual(2, a.OutputCount); Assert.AreEqual(6, b.OutputCount); Assert.AreEqual(24, c.OutputCount); }