コード例 #1
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\");"));
 }
コード例 #2
0
        public void AppendCodeSnippet_ChildNode_OpensCodeBlockCorrectly()
        {
            string codeStatement = "for (int c = 0; c < 10; c++)";

            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendCodeSnippet(codeStatement, true);
            string result = classBuilder.Build(ClassName);
            Assert.That(result, Is.StringContaining(codeStatement + "//;"));
        }
コード例 #3
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(), '\\\"')"));
 }
コード例 #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));"));
 }
コード例 #5
0
        public void AppendSelfClosingTagSuffix_XHtml4_CompilesValidTemplate()
        {
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendSelfClosingTagSuffix();
            string templateSource = classBuilder.Build(ClassName);
            var result = GenerateTemplateFromSource(templateSource);

            var writer = new StringWriter();
            result.Render(writer);
            Assert.That(writer.ToString(), Is.EqualTo(" />"));
        }
コード例 #6
0
        public void AppendMultipleAttributeNameValuePairs_XHtml4_CompilesValidTemplate()
        {
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendAttributeNameValuePair("name", new List<HamlNode> { new HamlNodeTextLiteral(new HamlSourceFileMetrics(0, 0, 0, 0), "value") }, '\"');
            classBuilder.AppendAttributeNameValuePair("name", new List<HamlNode> { new HamlNodeTextLiteral(new HamlSourceFileMetrics(0, 0, 0, 0), "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\""));
        }
コード例 #7
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\"));"));
 }
コード例 #8
0
        public void WriteNewLineIfRepeated_RepeatedCode_AppendsNewline()
        {
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendCodeSnippet("for (int c = 0; c < 3; c++)", true);
            classBuilder.Append("Test");
            classBuilder.RenderEndBlock();
            string templateSource = classBuilder.Build(ClassName);
            var result = GenerateTemplateFromSource(templateSource);

            var writer = new StringWriter();
            result.Render(writer, HtmlVersion.XHtml);
            Assert.That(writer.ToString(), Is.EqualTo("Test\r\nTest\r\nTest"));
        }
コード例 #9
0
        public void AppendAttributeNameValuePair_XHtml4_CompilesValidTemplate()
        {
            var classBuilder = new CodeDomClassBuilder();
            var valueFragments = new List<HamlNode>
                                     {
                                         new HamlNodeTextLiteral(new HamlSourceFileMetrics(0, 0, 0, 0), "value"),
                                         new HamlNodeTextVariable(new HamlSourceFileMetrics(0, 0, 0, 0), "#{Variable}"),
                                         new HamlNodeTextLiteral(new HamlSourceFileMetrics(0, 0, 0, 0), "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\""));
        }
コード例 #10
0
 private object BuildEmptyClass()
 {
     var classBuilder = new CodeDomClassBuilder();
     return classBuilder.Build(ClassName, typeof(Template),
         new List<string> { "System", "System.IO" });
 }
コード例 #11
0
        public void AppendVariable_ValidVariableName_AppendsRenderValueOrKeyAsString()
        {
            const string variableName = "key";
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendVariable(variableName);

            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("textWriter.Write(RenderValueOrKeyAsString(\"" + variableName + "\"));"));
        }
コード例 #12
0
 public void AppendSelfClosingTagSuffix_AppendsCorrectOutput()
 {
     var classBuilder = new CodeDomClassBuilder();
     classBuilder.AppendSelfClosingTagSuffix();
     string result = classBuilder.Build(ClassName);
     Assert.That(result, Is.StringContaining("base.AppendSelfClosingTagSuffix()"));
 }
コード例 #13
0
        public void AppendNewLine_NormalUse_GeneratesWriteStatement()
        {
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendNewLine();
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("textWriter.WriteLine(\"\");"));
        }
コード例 #14
0
        public void AppendDocType_CallsTemplateMethodCorrectly()
        {
            const string docTypeId = "Transitional";

            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendDocType(docTypeId);
            string result = classBuilder.Build(ClassName);

            const string expectedCodeStatement = "Write(GetDocType(\"" + docTypeId + "\"))";
            Assert.That(result, Is.StringContaining(expectedCodeStatement));
        }
コード例 #15
0
        public void AppendCodeSnippet_NoChildNodes_BuildsValueCorrectly()
        {
            string codeStatement = "int c = 1";

            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendCodeSnippet(codeStatement, false);
            string result = classBuilder.Build(ClassName);
            Assert.That(result, Is.StringContaining(codeStatement + ";"));
        }
コード例 #16
0
        public void AppendCode_ValidCodeFragment_AppendsFragment()
        {
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.AppendCodeToString("1+1");
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("textWriter.Write(Convert.ToString(1+1));"));
        }
コード例 #17
0
        public void Append_SingleLine_GeneratesWriteStatement()
        {
            string lineToWrite = "Test";
            var classBuilder = new CodeDomClassBuilder();
            classBuilder.Append(lineToWrite);
            string result = classBuilder.Build(ClassName);

            Assert.That(result, Is.StringContaining("textWriter.Write(\"" + lineToWrite + "\");"));
        }