PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/SharpTAL.Tests/TALESTests/CodeBlocksTests.cs

https://bitbucket.org/rlacko/sharptal
C# | 53 lines | 48 code | 5 blank | 0 comment | 0 complexity | 6278530e33d71325afdeefb85277f64e MD5 | raw file
Possible License(s): Apache-2.0
  1. namespace SharpTAL.SharpTALTests.TALESTests
  2. {
  3. using System;
  4. using System.Text;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.IO;
  8. using System.Reflection;
  9. using NUnit.Framework;
  10. using SharpTAL.TemplateCache;
  11. [TestFixture]
  12. public class CodeBlocksTests
  13. {
  14. public static void RunTest(string template, string expected, string errMsg)
  15. {
  16. string actual = new Template(template).Render(new Dictionary<string, object> { });
  17. actual = actual.Replace("{", "{").Replace("}", "}");
  18. Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
  19. Environment.NewLine, errMsg, template, actual, expected);
  20. }
  21. [Test]
  22. [ExpectedException(typeof(TemplateParseException))]
  23. public void TestCodeBlockInvalid()
  24. {
  25. RunTest(@"<?csharp if (1 > 2) { ?>",
  26. "",
  27. "CodeBlocks with invalid code failed!");
  28. }
  29. [Test]
  30. public void TestCodeBlocksWithNestedScope()
  31. {
  32. RunTest(@"<?csharp var oranges = new List<int> { 1, 2, 3 }; ?><div>
  33. <?csharp var bananas = new List<int> { 1, 2, 3 }; ?><ul>
  34. <?csharp
  35. foreach(var banana in bananas) output.Write(""<li>banana {0}</li>"", banana);
  36. foreach(var orange in oranges) output.Write(""<li>orange {0}</li>"", orange);
  37. ?>
  38. </ul>
  39. </div>",
  40. @"<div>
  41. <ul>
  42. <li>banana 1</li><li>banana 2</li><li>banana 3</li><li>orange 1</li><li>orange 2</li><li>orange 3</li>
  43. </ul>
  44. </div>",
  45. "CodeBlocks with nested scope failed!");
  46. }
  47. }
  48. }