@@ -47,35 +47,62 @@ public void Should_Map_Enumerable_Collection_In_Object()
47
47
var template = new ObjectSemanticsTemplate
48
48
{
49
49
FileContents = @"{{ StudentName }} Invoices
50
- {{ for-each-start: invoices }}
50
+ {{ #foreach( invoices) }}
51
51
<tr>
52
52
<td>{{ Id }}</td>
53
53
<td>{{ RefNo }}</td>
54
54
<td>{{ Narration }}</td>
55
55
<td>{{ Amount:N0 }}</td>
56
56
<td>{{ InvoiceDate:yyyy-MM-dd }}</td>
57
57
</tr>
58
- {{ for-each-end:invoices }}"
58
+ {{ #endforeach }}"
59
59
} ;
60
60
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
61
- string expectedResult = "John Doe Invoices" +
62
- "\r \n <tr>" +
63
- "\r \n <td>2</td>" +
64
- "\r \n <td>INV_002</td>" +
65
- "\r \n <td>Grade II Fees Invoice</td>" +
66
- "\r \n <td>2,000</td>" +
67
- "\r \n <td>2023-04-01</td>" +
68
- "\r \n </tr>" +
69
- "\r \n <tr>" +
70
- "\r \n <td>1</td>" +
71
- "\r \n <td>INV_001</td>" +
72
- "\r \n <td>Grade I Fees Invoice</td>" +
73
- "\r \n <td>320</td>" +
74
- "\r \n <td>2022-08-01</td>" +
75
- "\r \n </tr>" ;
61
+ string expectedResult = @"John Doe Invoices
62
+
63
+ <tr>
64
+ <td>2</td>
65
+ <td>INV_002</td>
66
+ <td>Grade II Fees Invoice</td>
67
+ <td>2,000</td>
68
+ <td>2023-04-01</td>
69
+ </tr>
70
+
71
+ <tr>
72
+ <td>1</td>
73
+ <td>INV_001</td>
74
+ <td>Grade I Fees Invoice</td>
75
+ <td>320</td>
76
+ <td>2022-08-01</td>
77
+ </tr>" ;
78
+ Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
79
+ }
80
+
81
+
82
+ [ Fact ]
83
+ public void Should_Map_Enumerable_Collection_SingleLine_Test ( )
84
+ {
85
+ //Create Model
86
+ Student student = new Student
87
+ {
88
+ StudentName = "John Doe" ,
89
+ Invoices = new List < Invoice >
90
+ {
91
+ new Invoice { Id = 2 , RefNo = "INV_002" , Narration = "Grade II Fees Invoice" , Amount = 2000 , InvoiceDate = new DateTime ( 2023 , 04 , 01 ) } ,
92
+ new Invoice { Id = 1 , RefNo = "INV_001" , Narration = "Grade I Fees Invoice" , Amount = 320 , InvoiceDate = new DateTime ( 2022 , 08 , 01 ) }
93
+ }
94
+ } ;
95
+ //Template
96
+ var template = new ObjectSemanticsTemplate
97
+ {
98
+ FileContents = @"{{ #foreach(invoices) }} [{{RefNo}}] {{ #endforeach }}"
99
+ } ;
100
+ string generatedTemplate = TemplateMapper . Map ( student , template ) ;
101
+ string expectedResult = " [INV_002] [INV_001] " ;
76
102
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
77
103
}
78
104
105
+
79
106
[ Fact ]
80
107
public void Should_Map_Multiple_Enumerable_Collection_On_Same_Template ( )
81
108
{
@@ -95,24 +122,27 @@ public void Should_Map_Multiple_Enumerable_Collection_On_Same_Template()
95
122
FileContents = @"
96
123
{{ StudentName }} Invoices
97
124
LOOP #1
98
- {{ for-each-start: invoices }}
125
+ {{ #foreach( invoices) }}
99
126
<h5>{{ Id }} On Loop #1</h5>
100
- {{ for-each-end:invoices }}
127
+ {{ #endforeach }}
101
128
LOOP #2
102
- {{ for-each-start: invoices }}
129
+ {{ #foreach( invoices) }}
103
130
<h5>{{ Id }} On Loop #2</h5>
104
- {{ for-each-end:invoices }}
105
- "
131
+ {{ #endforeach }}"
106
132
} ;
107
133
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
108
- string expectedResult = "\r \n John Doe Invoices" +
109
- "\r \n LOOP #1" +
110
- "\r \n <h5>2 On Loop #1</h5>" +
111
- "\r \n <h5>1 On Loop #1</h5>" +
112
- "\r \n LOOP #2" +
113
- "\r \n <h5>2 On Loop #2</h5>" +
114
- "\r \n <h5>1 On Loop #2</h5>" +
115
- "\r \n " ; ;
134
+ string expectedResult = @"
135
+ John Doe Invoices
136
+ LOOP #1
137
+
138
+ <h5>2 On Loop #1</h5>
139
+
140
+ <h5>1 On Loop #1</h5>
141
+ LOOP #2
142
+
143
+ <h5>2 On Loop #2</h5>
144
+
145
+ <h5>1 On Loop #2</h5>" ;
116
146
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
117
147
}
118
148
@@ -156,7 +186,7 @@ public void Should_Return_Unknown_Properties_If_Not_Found_In_Object()
156
186
FileContents = @"Unknown Object example: {{StudentIdentityCardXyx}}"
157
187
} ;
158
188
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
159
- string expectedString = "Unknown Object example: {{StudentIdentityCardXyx}}" ;
189
+ string expectedString = "Unknown Object example: {{ StudentIdentityCardXyx }}" ;
160
190
Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
161
191
}
162
192
@@ -365,24 +395,29 @@ public void Should_Act_On_IfCondition_Having_Loop_As_Child()
365
395
FileContents = @"
366
396
{{ #if (invoices != null) }}
367
397
{{ StudentName }} Invoices
368
- {{ for-each-start: invoices }}
398
+ {{ #foreach( invoices) }}
369
399
<tr>
370
400
<td>{{ Id }}</td>
371
401
<td>{{ RefNo }}</td>
372
402
</tr>
373
- {{ for-each-end:invoices }}
403
+ {{ #endforeach }}
374
404
{{ #endif }}"
375
405
} ;
376
406
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
377
- string expectedResult = "\r \n \r \n John Doe Invoices" +
378
- "\r \n <tr>" +
379
- "\r \n <td>2</td>" +
380
- "\r \n <td>INV_002</td>" +
381
- "\r \n </tr>" +
382
- "\r \n <tr>" +
383
- "\r \n <td>1</td>" +
384
- "\r \n <td>INV_001</td>" +
385
- "\r \n </tr>\r \n " ; ;
407
+ string expectedResult = @"
408
+
409
+ John Doe Invoices
410
+
411
+ <tr>
412
+ <td>2</td>
413
+ <td>INV_002</td>
414
+ </tr>
415
+
416
+ <tr>
417
+ <td>1</td>
418
+ <td>INV_001</td>
419
+ </tr>
420
+ " ;
386
421
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
387
422
}
388
423
@@ -667,26 +702,33 @@ public void Should_Act_On_IfCondition_Having_ElseIf_Having_A_LoopBlock(bool popu
667
702
{{ #if(invoices==null) }}
668
703
-- no invoices found --
669
704
{{ #else }}
670
- {{ for-each-start: invoices }}
705
+ {{ #foreach( invoices) }}
671
706
<tr>
672
707
<td>{{ Id }}</td>
673
708
<td>{{ RefNo }}</td>
674
709
</tr>
675
- {{ for-each-end:invoices }}
710
+ {{ #endforeach }}
676
711
{{ #endif }}"
677
712
} ;
678
713
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
679
- string expectedResult = ( populateInvoices ) ? "\r \n " +
680
- "\r \n <tr>" +
681
- "\r \n <td>2</td>" +
682
- "\r \n <td>INV_002</td>" +
683
- "\r \n </tr>" +
684
- "\r \n <tr>" +
685
- "\r \n <td>1</td>" +
686
- "\r \n <td>INV_001</td>" +
687
- "\r \n </tr>\r \n "
688
-
689
- : "\r \n \r \n -- no invoices found --\r \n " ;
714
+ string expectedResult = ( populateInvoices ) ? @"
715
+
716
+
717
+ <tr>
718
+ <td>2</td>
719
+ <td>INV_002</td>
720
+ </tr>
721
+
722
+ <tr>
723
+ <td>1</td>
724
+ <td>INV_001</td>
725
+ </tr>
726
+ "
727
+
728
+ : @"
729
+
730
+ -- no invoices found --
731
+ " ;
690
732
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
691
733
}
692
734
0 commit comments