File tree 4 files changed +54
-1
lines changed
src/CodeGenHelpers/Internals
tests/CodeGenHelpers.Tests
4 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ private string GetIndentedValue(string value)
111
111
112
112
public void Dispose ( )
113
113
{
114
- while ( _indentLevel > 0 )
114
+ if ( _indentLevel > 0 )
115
115
{
116
116
_indentLevel -- ;
117
117
EnsureStringBuilder ( ) . AppendLine ( GetIndentedValue ( "}" ) ) ;
Original file line number Diff line number Diff line change
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+
10
+ namespace CodeGenHelpers . SampleCode
11
+ {
12
+ partial class MultipleMethodClass
13
+ {
14
+ public void Bar ( )
15
+ {
16
+ }
17
+
18
+ public void Foo ( )
19
+ {
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -29,4 +29,20 @@ public void GenerateCodeSubBlock()
29
29
var r = sut . Render ( ) ;
30
30
Assert . Equal ( expected , r ) ;
31
31
}
32
+
33
+ [ Fact ]
34
+ public void GenerateIfElse ( )
35
+ {
36
+ var writer = new CodeWriter ( IndentStyle . Tabs ) ;
37
+
38
+ writer . If ( "true" )
39
+ . WithBody ( w => w . AppendLine ( "CrashTheSystem();" ) )
40
+ . Else ( )
41
+ . WithBody ( w => w . AppendLine ( "DontCrashTheSystem();" ) )
42
+ . EndIf ( ) ;
43
+
44
+ const string expected = "if (true)\r \n {\r \n \t CrashTheSystem();\r \n }\r \n else\r \n {\r \n \t DontCrashTheSystem();\r \n }\r \n " ;
45
+ var r = writer . Render ( ) ;
46
+ Assert . Equal ( expected , r ) ;
47
+ }
32
48
}
Original file line number Diff line number Diff line change @@ -35,5 +35,20 @@ public void GenerateMethodWithPrimitiveParameter()
35
35
36
36
MakeAssertion ( builder ) ;
37
37
}
38
+
39
+ [ Fact ]
40
+ public void GenerateMultipleMethodsInClass ( )
41
+ {
42
+ var builder = CodeBuilder . Create ( Namespace )
43
+ . AddClass ( "MultipleMethodClass" )
44
+ . AddMethod ( "Foo" )
45
+ . MakePublicMethod ( )
46
+ . Class
47
+ . AddMethod ( "Bar" )
48
+ . MakePublicMethod ( )
49
+ . Class ;
50
+
51
+ MakeAssertion ( builder ) ;
52
+ }
38
53
}
39
54
}
You can’t perform that action at this time.
0 commit comments