示例#1
0
        public void NonLiteralAttribute()
        {
            // The template
            const string templ    = "<p class=\"@Environment.Version\"/>";
            string       expected = "<p class=\"" + Environment.Version.ToString() + "\"/>";

            // Arrange
            MicroRazorCompiler compiler = MicroRazorCompiler.CreateCSharp();

            compiler.Host.NamespaceImports.Add("System");

            // Act
            var results = compiler.Compile(templ);

            Assert.True(results.Success);
            Assert.Equal(expected, results.Compiled.Run());
        }
示例#2
0
        public void ConditionalAttribute()
        {
            // The template
            const string templ    = "@{object f = null;}<p class=\"foo @f bar\" />";
            string       expected = "<p class=\"foo bar\" />";

            // Arrange
            MicroRazorCompiler compiler = MicroRazorCompiler.CreateCSharp();

            compiler.Host.NamespaceImports.Add("System");

            // Act
            var results = compiler.Compile(templ);

            Assert.True(results.Success);
            Assert.Equal(expected, results.Compiled.Run());
        }
示例#3
0
        public void HtmlEncoding()
        {
            // The template
            const string templ    = "<p>@(\"<p>\")</p>";
            string       expected = "<p>&lt;p&gt;</p>";

            // Arrange
            MicroRazorCompiler compiler = MicroRazorCompiler.CreateCSharp();

            compiler.Host.NamespaceImports.Add("System");

            // Act
            var results = compiler.Compile(templ);

            Assert.True(results.Success);
            Assert.Equal(expected, results.Compiled.Run());
        }