public void InterfaceIndent() { var c = new Interface("IPerson"); var cs = new CSharpSourceCodeGenerator(); cs.CurrentIndentLevel = 2; cs.Write(c); //static prefer Assert.AreEqual(" public interface IPerson" + SourceCodeGenerator.NewLine + " {" + SourceCodeGenerator.NewLine + " }" + SourceCodeGenerator.NewLine, cs.ToString()); }
public void TestPropertyBasicFeature() { var p = new PropertyBody(PropertyBodyType.Get); p.Body.Add(new CodeBlock(SourceCodeLanguage.CSharp, "return _Age;")); var cs = new CSharpSourceCodeGenerator(); cs.CurrentIndentLevel = 1; cs.Write(p); Assert.AreEqual(" get" + SourceCodeGenerator.NewLine + " {" + SourceCodeGenerator.NewLine + " return _Age;" + SourceCodeGenerator.NewLine + " }" + SourceCodeGenerator.NewLine , cs.ToString()); }
public void ClassIndent() { var c = new Class(AccessModifier.Public, "StringUtility"); c.Modifier.Static = true; c.Modifier.Abstract = true; CSharpSourceCodeGenerator sc = new CSharpSourceCodeGenerator(); sc.CurrentIndentLevel = 2; sc.Write(c); Assert.AreEqual(" public static class StringUtility" + SourceCodeGenerator.NewLine + " {" + SourceCodeGenerator.NewLine + " }" + SourceCodeGenerator.NewLine , sc.ToString()); }
public void CodeBlockIndentIsTwoWhitespace() { var cb = new CodeBlock(SourceCodeLanguage.CSharp, "if (bl == true)"); cb.CurlyBracket = true; cb.CodeBlocks.Add(new CodeBlock(SourceCodeLanguage.CSharp, "MessageBox.Show(\"Update successfully!\");")); var cs = new CSharpSourceCodeGenerator(); cs.Indent = " "; cs.Write(cb); Assert.AreEqual("if (bl == true)" + SourceCodeGenerator.NewLine + "{" + SourceCodeGenerator.NewLine + " MessageBox.Show(\"Update successfully!\");" + SourceCodeGenerator.NewLine + "}" + SourceCodeGenerator.NewLine , cs.ToString()); }
public void CodeBlockBracket() { var cb = new CodeBlock(SourceCodeLanguage.CSharp, "catch (InvalidCastException ex)"); cb.CurlyBracket = true; cb.CodeBlocks.Add(new CodeBlock(SourceCodeLanguage.CSharp, "throw new StoredProcedureSchemaMismatchedException(this, ex);")); var cs = new CSharpSourceCodeGenerator(); cs.CurrentIndentLevel = 3; cs.Indent = " "; cs.Write(cb); Assert.AreEqual(" catch (InvalidCastException ex)" + SourceCodeGenerator.NewLine + " {" + SourceCodeGenerator.NewLine + " throw new StoredProcedureSchemaMismatchedException(this, ex);" + SourceCodeGenerator.NewLine + " }" + SourceCodeGenerator.NewLine , cs.ToString()); }