PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/SharpTAL.Tests/TALTests/TALConditionTests.cs

https://bitbucket.org/rlacko/sharptal
C# | 73 lines | 63 code | 10 blank | 0 comment | 0 complexity | 208125dc6ae3ccf3f554134fcc6eab5c MD5 | raw file
Possible License(s): Apache-2.0
  1. namespace SharpTAL.SharpTALTests.TALTests
  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 TALConditionTests
  13. {
  14. public static Dictionary<string, object> globals;
  15. [TestFixtureSetUp]
  16. public void SetUpClass()
  17. {
  18. }
  19. [TestFixtureTearDown]
  20. public void CleanupClass()
  21. {
  22. }
  23. [SetUp]
  24. public void SetUp()
  25. {
  26. globals = new Dictionary<string, object>();
  27. globals.Add("test", "testing");
  28. globals.Add("one", new List<object>() { 1 });
  29. globals.Add("two", new List<object>() { "one", "two" });
  30. globals.Add("three", new List<object>() { 1, "Two", 3 });
  31. }
  32. public static void RunTest(string template, string expected, string errMsg)
  33. {
  34. string actual = new Template(template).Render(globals);
  35. Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
  36. Environment.NewLine, errMsg, template, actual, expected);
  37. }
  38. [Test]
  39. public void TestConditionDefault()
  40. {
  41. RunTest(
  42. @"<html tal:condition=""default"">Hello</html>",
  43. "<html>Hello</html>",
  44. "Condition 'default' did not evaluate to true");
  45. }
  46. [Test]
  47. public void TestConditionExists()
  48. {
  49. RunTest(
  50. @"<html tal:condition=""test"">Hello</html>",
  51. "<html>Hello</html>",
  52. "Condition for something that exists evaluated false");
  53. }
  54. [Test]
  55. public void TestConditionNull()
  56. {
  57. RunTest(
  58. @"<html tal:condition=""null"">Hello</html>",
  59. "",
  60. "Condition null evaluated to true");
  61. }
  62. }
  63. }