Пример #1
0
        public void HostSpecificStringParameter()
        {
            string template =
                @"<#@ template language=""C#"" hostspecific=""true"" #>
<#@ parameter name=""TestParam"" type=""string"" #>
Hello <#=TestParam#>!";

            var gen = new TemplateGenerator();

            gen.AddParameter(null, null, "TestParam", "World");
            var outFilename = "test.txt";
            var success     = gen.ProcessTemplate("test.tt", template, ref outFilename, out var outContent);

            Assert.True(success);
            Assert.AreEqual("Hello World!", outContent);
        }
Пример #2
0
        public async Task HostSpecificStringParameter()
        {
            string template =
                @"<#@ template language=""C#"" hostspecific=""true"" #>
<#@ parameter name=""TestParam"" type=""string"" #>
Hello <#=TestParam#>!";

            var gen = new TemplateGenerator();

            gen.AddParameter(null, null, "TestParam", "World");
            var outFilename = "test.txt";
            var result      = await gen.ProcessTemplateAsync("test.tt", template, outFilename);

            Assert.True(result.success);
            Assert.Equal("Hello World!", result.content);
        }
Пример #3
0
        public void HostSpecificNonStringParameter()
        {
            string template =
                @"<#@ template language=""C#"" hostspecific=""true"" #>
<#@ parameter name=""TestParam"" type=""System.Int32"" #>
<#=TestParam + 3#>";

            var gen = new TemplateGenerator();

            gen.AddParameter(null, null, "TestParam", "5");
            var outFilename = "test.txt";
            var success     = gen.ProcessTemplate("test.tt", template, ref outFilename, out var outContent);

            Assert.True(success);
            Assert.AreEqual("8", outContent);
        }