Skip to content

Commit 6042329

Browse files
committed
Added POCO examples
1 parent 71fbcf1 commit 6042329

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Liquid.NET.Tests/Examples/ExampleTests.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using Liquid.NET.Constants;
4+
using Liquid.NET.Utils;
45
using NUnit.Framework;
56

67
namespace 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
}

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- master
88

99
environment:
10-
release_version: '0.9.5'
10+
release_version: '0.9.6'
1111

1212
version: $(release_version).{build}
1313

@@ -46,7 +46,7 @@
4646
- release
4747

4848
environment:
49-
release_version: '0.9.5'
49+
release_version: '0.9.6'
5050

5151
version: $(release_version).{build}
5252
configuration: Release

0 commit comments

Comments
 (0)