@@ -260,7 +260,7 @@ public void Should_Act_On_IfCondition_SingleLine()
260
260
//Template
261
261
var template = new ObjectSemanticsTemplate
262
262
{
263
- FileContents = "IsEnabled: {{ if-start:invoices( !=null) }}YES{{ if-end:invoices }}"
263
+ FileContents = "IsEnabled: {{ #if(invoices !=null) }}YES{{ #endif }}"
264
264
} ;
265
265
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
266
266
string expectedResult = "IsEnabled: YES" ;
@@ -284,7 +284,7 @@ public void Should_Act_On_IfCondition_SingleLine_With_Attribute()
284
284
//Template
285
285
var template = new ObjectSemanticsTemplate
286
286
{
287
- FileContents = "InvoicedPerson: {{ if-start:invoices( !=null) }}{{StudentName}}{{ if-end:invoices }}"
287
+ FileContents = "InvoicedPerson: {{ #if(invoices !=null) }}{{StudentName}}{{ #endif }}"
288
288
} ;
289
289
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
290
290
string expectedResult = "InvoicedPerson: John Doe" ;
@@ -309,9 +309,9 @@ public void Should_Act_On_IfCondition_MultiLine()
309
309
var template = new ObjectSemanticsTemplate
310
310
{
311
311
FileContents = @"status
312
- {{ if-start:invoices( !=null) }}
312
+ {{ #if(invoices !=null) }}
313
313
<h4>condition--passed</h4>
314
- {{ if-end:invoices }}"
314
+ {{ #endif }}"
315
315
} ;
316
316
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
317
317
string expectedResult = "status\r \n \r \n <h4>condition--passed</h4>\r \n " ;
@@ -336,9 +336,9 @@ public void Should_Act_On_IfCondition_MultiLine_With_Attribute()
336
336
var template = new ObjectSemanticsTemplate
337
337
{
338
338
FileContents = @"status
339
- {{ if-start:invoices( !=null) }}
339
+ {{ #if(invoices !=null) }}
340
340
<h4>Hi, I have invoices for {{ StudentName }} </h4>
341
- {{ if-end:invoices }}"
341
+ {{ #endif }}"
342
342
} ;
343
343
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
344
344
string expectedResult = "status\r \n \r \n <h4>Hi, I have invoices for John Doe </h4>\r \n " ;
@@ -363,15 +363,15 @@ public void Should_Act_On_IfCondition_Having_Loop_As_Child()
363
363
var template = new ObjectSemanticsTemplate
364
364
{
365
365
FileContents = @"
366
- {{ if-start:invoices(!= null) }}
366
+ {{ #if (invoices != null) }}
367
367
{{ StudentName }} Invoices
368
368
{{ for-each-start:invoices }}
369
369
<tr>
370
370
<td>{{ Id }}</td>
371
371
<td>{{ RefNo }}</td>
372
372
</tr>
373
373
{{ for-each-end:invoices }}
374
- {{ if-end:invoices }}"
374
+ {{ #endif }}"
375
375
} ;
376
376
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
377
377
string expectedResult = "\r \n \r \n John Doe Invoices" +
@@ -390,7 +390,7 @@ public void Should_Act_On_IfCondition_Having_Loop_As_Child()
390
390
//#Match =, !=, >, >=, <, and <=.
391
391
392
392
[ Theory ]
393
- [ InlineData ( "=" , 5000 ) ]
393
+ [ InlineData ( "== " , 5000 ) ]
394
394
[ InlineData ( "!=" , 0 ) ]
395
395
[ InlineData ( ">" , 2000 ) ]
396
396
[ InlineData ( "<=" , 5001 ) ]
@@ -402,7 +402,7 @@ public void Should_Act_On_IfCondition_Equality_Checks(string condition, double a
402
402
//Template
403
403
var template = new ObjectSemanticsTemplate
404
404
{
405
- FileContents = string . Format ( "{2} if-start:balance( {0}{1}) {3} {0} passed {2} if-end:balance {3}" , condition , amount , "{{" , "}}" )
405
+ FileContents = string . Format ( "{2} #if(balance {0}{1}) {3} {0} passed {2} #endif {3}" , condition , amount , "{{" , "}}" )
406
406
} ;
407
407
408
408
string expectedResult = string . Format ( " {0} passed " , condition ) ;
@@ -412,8 +412,6 @@ public void Should_Act_On_IfCondition_Equality_Checks(string condition, double a
412
412
413
413
414
414
415
-
416
-
417
415
[ Fact ]
418
416
public void Should_Act_On_IfCondition_IEnumerable_Tests_Equall ( )
419
417
{
@@ -430,7 +428,7 @@ public void Should_Act_On_IfCondition_IEnumerable_Tests_Equall()
430
428
//Template
431
429
var template = new ObjectSemanticsTemplate
432
430
{
433
- FileContents = "{{ if-start:invoices(= 2) }} 2 records {{ if-end:invoices }}"
431
+ FileContents = "{{ #if(invoices== 2) }} 2 records {{ #endif }}"
434
432
} ;
435
433
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
436
434
string expectedResult = " 2 records " ;
@@ -454,7 +452,7 @@ public void Should_Act_On_IfCondition_IEnumerable_Tests_NotEqualNull()
454
452
//Template
455
453
var template = new ObjectSemanticsTemplate
456
454
{
457
- FileContents = "{{ if-start:invoices( !=null) }} is not NULL {{ if-end:invoices }}"
455
+ FileContents = "{{ #if(invoices !=null) }} is not NULL {{ #endif }}"
458
456
} ;
459
457
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
460
458
string expectedResult = " is not NULL " ;
@@ -473,7 +471,7 @@ public void Should_Act_On_IfCondition_IEnumerable_Tests_NULL_Object_Behaviour()
473
471
//Template
474
472
var template = new ObjectSemanticsTemplate
475
473
{
476
- FileContents = "{{ if-start:invoices(= null) }} is NULL {{ if-end:invoices }}"
474
+ FileContents = "{{ #if(invoices== null) }} is NULL {{ #endif }}"
477
475
} ;
478
476
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
479
477
string expectedResult = " is NULL " ;
@@ -491,7 +489,7 @@ public void Should_Act_On_IfCondition_IEnumerable_Tests_Count_NULL_Object_Behavi
491
489
//Template
492
490
var template = new ObjectSemanticsTemplate
493
491
{
494
- FileContents = "{{ if-start:invoices(= 0) }} no records {{ if-end:invoices }}"
492
+ FileContents = "{{ #if(invoices== 0) }} no records {{ #endif }}"
495
493
} ;
496
494
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
497
495
string expectedResult = " no records " ;
@@ -510,7 +508,7 @@ public void Should_Act_On_IfCondition_IEnumerable_Tests_Count_Object_Behaviour()
510
508
//Template
511
509
var template = new ObjectSemanticsTemplate
512
510
{
513
- FileContents = "{{ if-start:invoices(= null) }} no records {{ if-end:invoices }}"
511
+ FileContents = "{{ #if(invoices== null) }} no records {{ #endif }}"
514
512
} ;
515
513
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
516
514
string expectedResult = " no records " ;
@@ -529,7 +527,7 @@ public void Should_Act_On_IfCondition_Having_ElseIf_Inline(double amount)
529
527
//Template
530
528
var template = new ObjectSemanticsTemplate
531
529
{
532
- FileContents = "{{ if-start:Balance(= 5000) }} --ok-passed-- {{ else-if }} --error-failed-- {{ if-end:Balance }}"
530
+ FileContents = "{{ #if(Balance== 5000) }} --ok-passed-- {{ # else }} --error-failed-- {{ #endif }}"
533
531
} ;
534
532
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
535
533
string expectedResult = ( amount == 5000 ) ? " --ok-passed-- " : " --error-failed-- " ;
@@ -547,11 +545,11 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine(double amount)
547
545
var template = new ObjectSemanticsTemplate
548
546
{
549
547
FileContents = @"
550
- {{ if-start:Balance( =5000) }}
548
+ {{ #if(Balance= =5000) }}
551
549
--ok-passed--
552
- {{ else-if }}
550
+ {{ # else }}
553
551
--error-failed--
554
- {{ if-end:Balance }}"
552
+ {{ #endif }}"
555
553
} ;
556
554
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
557
555
string expectedResult = ( amount == 5000 ) ? "\r \n \r \n --ok-passed--\r \n " : "\r \n \r \n --error-failed--\r \n " ;
@@ -570,11 +568,11 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_EquallsNull
570
568
var template = new ObjectSemanticsTemplate
571
569
{
572
570
FileContents = @"
573
- {{ if-start:StudentName( =NULL) }}
571
+ {{ #if(StudentName= =NULL) }}
574
572
--ok-passed--
575
- {{ else-if }}
573
+ {{ # else }}
576
574
--error-failed--
577
- {{ if-end:Balance }}"
575
+ {{ #endif }}"
578
576
} ;
579
577
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
580
578
string expectedResult = string . IsNullOrEmpty ( studentName ) ? "\r \n \r \n --ok-passed--\r \n " : "\r \n \r \n --error-failed--\r \n " ;
@@ -593,19 +591,18 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_NotEquallsN
593
591
var template = new ObjectSemanticsTemplate
594
592
{
595
593
FileContents = @"
596
- {{ if-start:StudentName( !=NULL) }}
594
+ {{ #if(StudentName !=NULL) }}
597
595
--ok-passed--
598
- {{ else-if }}
596
+ {{ # else }}
599
597
--error-failed--
600
- {{ if-end:Balance }}"
598
+ {{ #endif }}"
601
599
} ;
602
600
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
603
601
string expectedResult = ( ! string . IsNullOrEmpty ( studentName ) ) ? "\r \n \r \n --ok-passed--\r \n " : "\r \n \r \n --error-failed--\r \n " ;
604
602
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
605
603
}
606
604
607
605
608
-
609
606
[ Theory ]
610
607
[ InlineData ( null ) ]
611
608
[ InlineData ( "John Doe" ) ]
@@ -618,11 +615,11 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_Equalls(str
618
615
var template = new ObjectSemanticsTemplate
619
616
{
620
617
FileContents = @"
621
- {{ if-start:StudentName( =John Doe) }}
618
+ {{ #if(StudentName= =John Doe) }}
622
619
--ok-passed--
623
- {{ else-if }}
620
+ {{ # else }}
624
621
--error-failed--
625
- {{ if-end:Balance }}"
622
+ {{ #endif }}"
626
623
} ;
627
624
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
628
625
string expectedResult = ( studentName == "John Doe" ) ? "\r \n \r \n --ok-passed--\r \n " : "\r \n \r \n --error-failed--\r \n " ;
@@ -638,7 +635,7 @@ public void Should_Act_On_IfCondition_Simple_Property_String_Equality()
638
635
//Template
639
636
var template = new ObjectSemanticsTemplate
640
637
{
641
- FileContents = "{{ if-start:studentName(= John Doe) }} YES, i am John Doe {{ if-end:studentName }}"
638
+ FileContents = "{{ #if(studentName== John Doe) }} YES, i am John Doe {{ #endif }}"
642
639
} ;
643
640
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
644
641
string expectedResult = " YES, i am John Doe " ;
@@ -667,16 +664,16 @@ public void Should_Act_On_IfCondition_Having_ElseIf_Having_A_LoopBlock(bool popu
667
664
var template = new ObjectSemanticsTemplate
668
665
{
669
666
FileContents = @"
670
- {{ if-start:invoices( =null) }}
667
+ {{ #if(invoices= =null) }}
671
668
-- no invoices found --
672
- {{ else-if }}
669
+ {{ # else }}
673
670
{{ for-each-start:invoices }}
674
671
<tr>
675
672
<td>{{ Id }}</td>
676
673
<td>{{ RefNo }}</td>
677
674
</tr>
678
675
{{ for-each-end:invoices }}
679
- {{ if-end:invoices }}"
676
+ {{ #endif }}"
680
677
} ;
681
678
string generatedTemplate = TemplateMapper . Map ( student , template ) ;
682
679
string expectedResult = ( populateInvoices ) ? "\r \n " +
@@ -692,6 +689,58 @@ public void Should_Act_On_IfCondition_Having_ElseIf_Having_A_LoopBlock(bool popu
692
689
: "\r \n \r \n -- no invoices found --\r \n " ;
693
690
Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
694
691
}
692
+
693
+
694
+
695
+
696
+ [ Fact ]
697
+ public void Should_Act_On_IfCondition_Having_Multiple_IF_Condition_Blocks_SingleLine ( )
698
+ {
699
+ //Create Model
700
+ Student student = new Student { StudentName = "John Doe" , Balance = 2000 } ;
701
+ //Template
702
+ var template = new ObjectSemanticsTemplate
703
+ {
704
+ FileContents = "{{ #if(studentName==John Doe) }} YES, i am John Doe {{ #endif }} | {{ #if(Balance==2000) }} YES, my balance is 2000 {{ #endif }}"
705
+ } ;
706
+ string generatedTemplate = TemplateMapper . Map ( student , template ) ;
707
+ string expectedResult = " YES, i am John Doe | YES, my balance is 2000 " ;
708
+ Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
709
+ }
710
+
711
+ [ Theory ]
712
+ [ InlineData ( null ) ]
713
+ [ InlineData ( "John Doe" ) ]
714
+ [ InlineData ( "" ) ]
715
+ public void Should_Act_On_IfCondition_Having_Multiple_IF_Condition_Blocks_MultiLine ( string studentName )
716
+ {
717
+ //Create Model
718
+ Student student = new Student { StudentName = studentName } ;
719
+ //Template
720
+ var template = new ObjectSemanticsTemplate
721
+ {
722
+ FileContents = @"
723
+ #Test 1
724
+ {{ #if(StudentName!=NULL) }}
725
+ --ok-passed--
726
+ {{ #else }}
727
+ --error-failed--
728
+ {{ #endif }}
729
+ #Test 2
730
+ {{ #if(StudentName==John Doe) }}
731
+ --I am, John Doe--
732
+ {{ #else }}
733
+ --I am NOT--
734
+ {{ #endif }}"
735
+
736
+ } ;
737
+ string generatedTemplate = TemplateMapper . Map ( student , template ) ;
738
+ string expectedResult = ( studentName == "John Doe" )
739
+ ?
740
+ "\r \n #Test 1\r \n \r \n --ok-passed--\r \n \r \n #Test 2\r \n \r \n --I am, John Doe--\r \n "
741
+ : "\r \n #Test 1\r \n \r \n --error-failed--\r \n \r \n #Test 2\r \n \r \n --I am NOT--\r \n " ;
742
+ Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
743
+ }
695
744
#endregion
696
745
}
697
746
}
0 commit comments