11using System ;
22using System . Linq ;
33using Liquid . NET . Constants ;
4+ using Liquid . NET . Utils ;
45using NUnit . Framework ;
56
67namespace Liquid . NET . Tests . Examples
@@ -86,7 +87,6 @@ public void Test_Parsing_Error()
8687 Assert . That ( error , Is . StringContaining ( "line 1:52 at <EOF>: Missing '}}'" ) ) ;
8788 }
8889
89-
9090 [ Test ]
9191 public void Test_Rendering_Error ( )
9292 {
@@ -98,5 +98,48 @@ public void Test_Rendering_Error()
9898 //Console.WriteLine("The RESULT was : " + renderingResult.Result);
9999 Assert . That ( error , Is . StringContaining ( "Liquid error: divided by 0" ) ) ;
100100 }
101+
102+ [ Test ]
103+ public void Poco_Object_Should_Be_Serialized ( )
104+ {
105+ ITemplateContext ctx = new TemplateContext ( )
106+ . DefineLocalVariable ( "poco" , new MyPoco
107+ {
108+ MyStringField = "A string field" ,
109+ MyNullableIntField = 123 ,
110+ MyOtherField = "Some Other Field" ,
111+ MyIgnoredField = "This Shouldn't Show Up" ,
112+ MyIgnoreIfNotNullField = null ,
113+ NestedPoco = new MyPoco { MyStringField = "Nested Poco" }
114+
115+ } . ToLiquid ( ) ) ;
116+
117+ var parsingResult = LiquidTemplate . Create ( "Poco Result: {{ poco }}" ) ;
118+ var renderingResult = parsingResult . LiquidTemplate . Render ( ctx ) ;
119+
120+ Assert . That ( renderingResult . Result , Is . StringContaining ( @"Poco Result: { ""mystringfield"" : ""A string field"", ""mynullableintfield"" : 123, ""myrenamedfield"" : ""Some Other Field"", ""nestedpoco"" : { ""mystringfield"" : ""Nested Poco"", ""mynullableintfield"" : null, ""myrenamedfield"" : null } }" ) ) ;
121+ }
122+
123+ public class MyPoco
124+ {
125+ public String MyStringField { get ; set ; }
126+
127+ public int ? MyNullableIntField { get ; set ; }
128+
129+ [ LiquidName ( "myrenamedfield" ) ]
130+ public String MyOtherField { get ; set ; }
131+
132+ [ LiquidIgnoreIfNull ]
133+ public String MyIgnoreIfNotNullField { get ; set ; }
134+
135+ [ LiquidIgnore ]
136+ public String MyIgnoredField { get ; set ; }
137+
138+ [ LiquidIgnoreIfNull ]
139+ public MyPoco NestedPoco { get ; set ; }
140+
141+ }
142+
143+
101144 }
102145}
0 commit comments