From 138f36f0057758f8eb45ca4b905d91b7469aac0c Mon Sep 17 00:00:00 2001 From: Travis Parks Date: Sat, 12 Jan 2013 15:11:24 -0500 Subject: [PATCH] Created a complex example for a unit test. I wanted to make sure the code worked before creating a NuGet package. --- mustache-sharp.test/FormatCompilerTester.cs | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/mustache-sharp.test/FormatCompilerTester.cs b/mustache-sharp.test/FormatCompilerTester.cs index 4514303..5f072d7 100644 --- a/mustache-sharp.test/FormatCompilerTester.cs +++ b/mustache-sharp.test/FormatCompilerTester.cs @@ -917,5 +917,56 @@ Last"; } #endregion + + #region Compound Tags + + /// + /// If a format contains multiple tags, they should be handled just fine. + /// + [TestMethod] + public void TestCompile_MultipleTags() + { + FormatCompiler compiler = new FormatCompiler(); + const string format = @"Hello {{Customer.FirstName}}: + +{{#with Order}} +{{#if LineItems}} +Below are your order details: + +{{#each LineItems}} + {{Name}}: {{UnitPrice:C}} x {{Quantity}} +{{/each}} + +Your order total was: {{Total:C}} +{{/if}} +{{/with}}"; + Generator generator = compiler.Compile(format); + string result = generator.Render(new + { + Customer = new { FirstName = "Bob" }, + Order = new + { + Total = 7.50m, + LineItems = new object[] + { + new { Name = "Banana", UnitPrice = 2.50m, Quantity = 1 }, + new { Name = "Orange", UnitPrice = .50m, Quantity = 5 }, + new { Name = "Apple", UnitPrice = .25m, Quantity = 10 }, + } + } + }); + const string expected = @"Hello Bob: + +Below are your order details: + + Banana: $2.50 x 1 + Orange: $0.50 x 5 + Apple: $0.25 x 10 + +Your order total was: $7.50"; + Assert.AreEqual(expected, result, "The wrong text was generated."); + } + + #endregion } }