Пример #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"));
     }
 }