예제 #1
0
        public void TestDocumentRenderingWithConditionalReplacement()
        {
            var rendered = new DocumentRenderer().Render("{{if GoodMood}}Hi {{Name!}}!{{if}}", new { Name = "Adam", GoodMood = true });
            Assert.AreEqual("Hi Adam", rendered.ToString());

            rendered = new DocumentRenderer().Render("{{if GoodMood}}Hi {{Name!}}!{{if}}", new { Name = "Adam", GoodMood = false });
            Assert.AreEqual("", rendered.ToString());
        }
예제 #2
0
        public void TestDocumentRenderingNewLinesBehvior()
        {
            var template =
            @"
            {{ each foo in Foos }}

            !{{ each }}
            ".TrimStart().Replace("\r\n","\n");
            var rendered = new DocumentRenderer().Render(template, new { Foos = new int[] { 1, 2, 3 } }).ToString();
            Assert.AreEqual("\n\n\n", rendered);
        }
        private static void RenderEffectiveDoxyFile(string templateFilePath, string outputDirectory, string version, string sourceDirectory, string tempFilePath)
        {
            var renderer = new DocumentRenderer();
            var template = File.ReadAllText(templateFilePath);
            var effectiveDoxyFileContents = renderer.Render(template, new
            {
                OutputDirectory = outputDirectory.Replace("\\", "/"),
                Version = version,
                SourceDirectory = sourceDirectory.Replace("\\", "/"),
            }).ToString();

            File.WriteAllText(tempFilePath, effectiveDoxyFileContents);
        }
예제 #4
0
        public void TestDocumentRenderingSourcePropagation()
        {
            DocumentRenderer renderer = new DocumentRenderer();
            renderer.RegisterTemplate("TheOneAndOnlyTemplate", new DocumentTemplateInfo()
            {
                Value = "Hi {{!}}, {{FirstName!}}",
                SourceLocation = "The bad template",
            });

            try
            {
                var rendered = renderer.Render("[{{template TheOneAndOnlyTemplate DudeData!}}]", new { DudeData = new { FirstName = "John", LastName = "Smith" } });
                Assert.Fail("An exception should have been thrown");
            }
            catch(DocumentRenderException ex)
            {
                Assert.IsTrue(ex.Message.Contains("The bad template"));
            }
        }
예제 #5
0
        public void TestDocumentRenderingWithCustomExpressions()
        {
            DocumentRenderer renderer = new DocumentRenderer();
            renderer.ExpressionParser.RegisterDynamicReplacementExpressionProviders(Assembly.GetExecutingAssembly(), true);
            var rendered = renderer.Render("{{ date !}}", new { });
            Assert.AreEqual(DateTime.Today.ToString(), rendered.ToString());

            Assert.IsTrue(renderer.ExpressionParser.RegisteredReplacementExpressionProviderKeys.Contains("date"));
            renderer.ExpressionParser.UnregisterReplacementExpressionProvider("date");
            Assert.IsFalse(renderer.ExpressionParser.RegisteredReplacementExpressionProviderKeys.Contains("date"));
        }
예제 #6
0
 public void TestDocumentRenderingVarExpressionColors()
 {
     var rendered = new DocumentRenderer().Render("{{var ConsoleForegroundColor Red!}}Hi {{FirstName!}}{{clearvar ConsoleForegroundColor !}}.  How are you?", new { FirstName = "Adam" });
     Assert.AreEqual(new ConsoleString("Hi Adam",foregroundColor: ConsoleColor.Red) + new ConsoleString(".  How are you?"), rendered);
 }
예제 #7
0
 public void TestDocumentRenderingVarExpression()
 {
     var rendered = new DocumentRenderer().Render("{{var first FirstName!}}Hi {{first!}}{{clearvar first!}}", new { FirstName="Adam" });
     Assert.AreEqual("Hi Adam", rendered.ToString());
 }
예제 #8
0
 public void TestDocumentRenderingWithSimpleReplacement()
 {
     var rendered = new DocumentRenderer().Render("Hi {{Name Red!}}! Sup?", new { Name = "Adam" });
     Assert.AreEqual("Hi Adam! Sup?", rendered.ToString());
     Assert.AreEqual(new ConsoleCharacter('a').ForegroundColor, rendered[0].ForegroundColor);
     Assert.AreEqual(ConsoleColor.Red, rendered[3].ForegroundColor);
     Assert.AreEqual(new ConsoleCharacter('a').ForegroundColor, rendered[rendered.Length - 1].ForegroundColor);
 }
예제 #9
0
 public void TestUsagePrimitive()
 {
     CommandLineArgumentsDefinition def = new CommandLineArgumentsDefinition(typeof(TestArgs));
     var rendered = new DocumentRenderer().Render("Your program has {{Arguments.Count!}} arguments", def);
     Assert.AreEqual("Your program has 2 arguments", rendered.ToString());
 }
예제 #10
0
 public void TestDocumentRenderingWithNoReplacements()
 {
     var rendered = new DocumentRenderer().Render("Hi", 1);
     Assert.AreEqual("Hi", rendered.ToString());
 }
예제 #11
0
 public void TestDocumentRenderingWithNamedTemplates()
 {
     DocumentRenderer renderer = new DocumentRenderer();
     renderer.RegisterTemplate("TheOneAndOnlyTemplate", new DocumentTemplateInfo()
     {
         Value = "Hi {{LastName!}}, {{FirstName!}}",
     });
     var rendered = renderer.Render("[{{template TheOneAndOnlyTemplate DudeData!}}]", new { DudeData = new { FirstName = "John", LastName = "Smith" } });
     Assert.AreEqual("[Hi Smith, John]", rendered.ToString());
 }
예제 #12
0
 public void TestDocumentRenderingWithEachReplacement()
 {
     var rendered = new DocumentRenderer().Render("{{each number in Numbers}}{{number!}}!{{each}}", new { Numbers = new int[] { 1, 2, 3, 4 } });
     Assert.AreEqual("1234", rendered.ToString());
 }
예제 #13
0
 public void TestDocumentRenderingWithCustomOverrideExpressions()
 {
     DocumentRenderer renderer = new DocumentRenderer();
     renderer.ExpressionParser.RegisterDynamicReplacementExpressionProviders(Assembly.GetExecutingAssembly(), true);
     var rendered = renderer.Render("{{ if !}}", new { });
     Assert.AreEqual("if override", rendered.ToString());
 }
예제 #14
0
 public void TestDocumentRenderingWithCustomInvalidOverrideExpressions()
 {
     try
     {
         DocumentRenderer renderer = new DocumentRenderer();
         renderer.ExpressionParser.RegisterDynamicReplacementExpressionProviders(Assembly.GetExecutingAssembly(), false);
         Assert.Fail("An exception should have been thrown");
     }
     catch(ArgumentException ex)
     {
         Assert.IsTrue(ex.Message.ToLower().Contains("already exists"));
     }
 }