@@ -784,5 +784,53 @@ public void Should_Act_On_IfCondition_Having_Multiple_IF_Condition_Blocks_MultiL
784784 Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
785785 }
786786 #endregion
787+
788+
789+ #region Xml Char Escape Tests
790+ [ Fact ]
791+ public void Should_Escape_Xml_Char_If_Option_Is_Enabled ( )
792+ {
793+ //Create Model
794+ Student student = new Student { StudentName = "I've got \" special\" < & also >" } ;
795+ var template = new ObjectSemanticsTemplate
796+ {
797+ FileContents = @"{{ StudentName }}"
798+ } ;
799+ string generatedTemplate = TemplateMapper . Map ( student , template , null , new TemplateMapperOptions
800+ {
801+ XmlCharEscaping = true
802+ } ) ;
803+ string expectedString = "I've got "special" < & also >" ;
804+ Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
805+ }
806+
807+
808+ [ Fact ]
809+ public void Should_Escape_Xml_Char_In_LOOPS_If_Option_Is_Enabled ( )
810+ {
811+ //Create Model
812+ Student student = new Student
813+ {
814+ Invoices = new List < Invoice >
815+ {
816+ new Invoice { Narration = "I've got \" special\" " } ,
817+ new Invoice { Narration = "I've got < & also >" }
818+ }
819+ } ;
820+ //Template
821+ var template = new ObjectSemanticsTemplate
822+ {
823+ FileContents = @"{{ #foreach(invoices) }} [{{ Narration }}] {{ #endforeach }}"
824+ } ;
825+ string generatedTemplate = TemplateMapper . Map ( student , template , null , new TemplateMapperOptions
826+ {
827+ XmlCharEscaping = true
828+ } ) ;
829+ string expectedResult = @" [I've got "special"] [I've got < & also >] " ;
830+ Assert . Equal ( expectedResult , generatedTemplate , false , true , true ) ;
831+ }
832+ #endregion
833+
834+
787835 }
788836}
0 commit comments