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\");")); }
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 + "//;")); }
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(), '\\\"')")); }
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));")); }
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(" />")); }
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\"")); }
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\"));")); }
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")); }
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\"")); }
private object BuildEmptyClass() { var classBuilder = new CodeDomClassBuilder(); return classBuilder.Build(ClassName, typeof(Template), new List<string> { "System", "System.IO" }); }
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 + "\"));")); }
public void AppendSelfClosingTagSuffix_AppendsCorrectOutput() { var classBuilder = new CodeDomClassBuilder(); classBuilder.AppendSelfClosingTagSuffix(); string result = classBuilder.Build(ClassName); Assert.That(result, Is.StringContaining("base.AppendSelfClosingTagSuffix()")); }
public void AppendNewLine_NormalUse_GeneratesWriteStatement() { var classBuilder = new CodeDomClassBuilder(); classBuilder.AppendNewLine(); string result = classBuilder.Build(ClassName); Assert.That(result, Is.StringContaining("textWriter.WriteLine(\"\");")); }
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)); }
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 + ";")); }
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));")); }
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 + "\");")); }