@@ -832,5 +832,65 @@ public void Should_Escape_Xml_Char_In_LOOPS_If_Option_Is_Enabled()
832832 #endregion
833833
834834
835+ #region Nullable Property Tests
836+ [ Fact ]
837+ public void Should_Map_Nullable_DateTime_Property_Given_NULL ( )
838+ {
839+ //Create Model
840+ StudentClockInDetail clockInDetails = new StudentClockInDetail { LastClockedInDate = null } ;
841+ var template = new ObjectSemanticsTemplate
842+ {
843+ FileContents = @"Last Clocked In: {{ LastClockedInDate:yyyy-MM-dd }}"
844+ } ;
845+ string generatedTemplate = TemplateMapper . Map ( clockInDetails , template ) ;
846+ string expectedString = "Last Clocked In: " ;
847+ Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
848+ }
849+
850+ [ Fact ]
851+ public void Should_Map_Nullable_DateTime_Property_Given_A_Value ( )
852+ {
853+ //Create Model
854+ StudentClockInDetail clockInDetails = new StudentClockInDetail { LastClockedInDate = DateTime . Now } ;
855+ var template = new ObjectSemanticsTemplate
856+ {
857+ FileContents = @"Last Clocked In: {{ LastClockedInDate:yyyy-MM-dd }}"
858+ } ;
859+ string generatedTemplate = TemplateMapper . Map ( clockInDetails , template ) ;
860+ string expectedString = $ "Last Clocked In: { DateTime . Now : yyyy-MM-dd} ";
861+ Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
862+ }
863+
864+ [ Fact ]
865+ public void Should_Map_Nullable_Number_Property_Given_NULL ( )
866+ {
867+ //Create Model
868+ StudentClockInDetail clockInDetails = new StudentClockInDetail { LastClockedInPoints = null } ;
869+ var template = new ObjectSemanticsTemplate
870+ {
871+ FileContents = @"Last Clocked In Points: {{ LastClockedInPoints:N2 }}"
872+ } ;
873+ string generatedTemplate = TemplateMapper . Map ( clockInDetails , template ) ;
874+ string expectedString = "Last Clocked In Points: " ;
875+ Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
876+ }
877+
878+ [ Theory ]
879+ [ InlineData ( null ) ]
880+ [ InlineData ( 2500 ) ]
881+ [ InlineData ( 200 ) ]
882+ public void Should_Map_Nullable_Number_Property_Given_A_Value ( long ? number )
883+ {
884+ //Create Model
885+ StudentClockInDetail clockInDetails = new StudentClockInDetail { LastClockedInPoints = number } ;
886+ var template = new ObjectSemanticsTemplate
887+ {
888+ FileContents = @"Last Clocked In Points: {{ LastClockedInPoints:N2 }}"
889+ } ;
890+ string generatedTemplate = TemplateMapper . Map ( clockInDetails , template ) ;
891+ string expectedString = $ "Last Clocked In Points: { number : N2} ";
892+ Assert . Equal ( expectedString , generatedTemplate , false , true , true ) ;
893+ }
894+ #endregion
835895 }
836896}
0 commit comments