Example #1
0
        public void AppendAttributeNameValuePair_XHtml4_CompilesValidTemplate()
        {
            var classBuilder   = new CodeDomClassBuilder();
            var valueFragments = new List <HamlNode>
            {
                new HamlNodeTextLiteral(-1, "value"),
                new HamlNodeTextVariable(-1, "#{Variable}"),
                new HamlNodeTextLiteral(-1, "value")
            };

            classBuilder.AppendAttributeNameValuePair("name",
                                                      valueFragments, '\"');
            string templateSource = classBuilder.Build(ClassName);
            var    result         = GenerateTemplateFromSource(templateSource);

            var dictionary = new Dictionary <string, object>
            {
                { "Variable", "Result" }
            };

            var writer = new StringWriter();

            result.Render(writer, HtmlVersion.XHtml, dictionary);
            Assert.That(writer.ToString(), Is.EqualTo(" name=\"valueResultvalue\""));
        }
Example #2
0
        public void AppendMultipleAttributeNameValuePairs_XHtml4_CompilesValidTemplate()
        {
            var classBuilder = new CodeDomClassBuilder();

            classBuilder.AppendAttributeNameValuePair("name", new List <HamlNode> {
                new HamlNodeTextLiteral(-1, "value")
            }, '\"');
            classBuilder.AppendAttributeNameValuePair("name", new List <HamlNode> {
                new HamlNodeTextLiteral(-1, "value")
            }, '\"');
            string templateSource = classBuilder.Build(ClassName);
            var    result         = GenerateTemplateFromSource(templateSource);

            var writer = new StringWriter();

            result.Render(writer, HtmlVersion.XHtml);
            Assert.That(writer.ToString(), Is.EqualTo(" name=\"value\" name=\"value\""));
        }
Example #3
0
        public void AppendAttributeNameValuePair_NoValueNode_AppendsRenderAttributeNameValuePair()
        {
            var classBuilder = new CodeDomClassBuilder();
            var valueNodes   = new List <HamlNode>();

            classBuilder.AppendAttributeNameValuePair("Name", valueNodes, '\"');
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("textWriter.Write(\" Name\");"));
        }
Example #4
0
        public void AppendAttributeNameValuePair_ObjectReferenceHamlNode_BuildsValueCorrectly()
        {
            var classBuilder   = new CodeDomClassBuilder();
            var valueFragments = new List <HamlNode>
            {
                new HamlNodeTextVariable(-1, "#{Model.Property}")
            };

            classBuilder.AppendAttributeNameValuePair("Name", valueFragments, '\"');
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining(".Append(Convert.ToString(Model.Property));"));
        }
Example #5
0
        public void AppendAttributeNameValuePair_TextLiteralHamlNode_AppendsRenderAttributeNameValuePair()
        {
            var classBuilder = new CodeDomClassBuilder();
            var valueNodes   = new List <HamlNode> {
                new HamlNodeTextLiteral(-1, "value")
            };

            classBuilder.AppendAttributeNameValuePair("Name", valueNodes, '\"');
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("= new System.Text.StringBuilder();"));
            Assert.That(result, Is.StringContaining("base.RenderAttributeNameValuePair(\"Name\", value_0.ToString(), '\\\"')"));
        }
Example #6
0
        public void AppendAttributeNameValuePair_LiteralAndVariableHamlNode_BuildsValueCorrectly()
        {
            var classBuilder   = new CodeDomClassBuilder();
            var valueFragments = new List <HamlNode>
            {
                new HamlNodeTextLiteral(-1, "value1"),
                new HamlNodeTextVariable(-1, "#{variable}")
            };

            classBuilder.AppendAttributeNameValuePair("Name", valueFragments, '\"');
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining(".Append(\"value1\");"));
            Assert.That(result, Is.StringContaining(".Append(base.RenderValueOrKeyAsString(\"variable\"));"));
        }