PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/SharpTAL.Tests/METALTests/METALNameSpaceTests.cs

https://bitbucket.org/rlacko/sharptal
C# | 77 lines | 65 code | 10 blank | 2 comment | 0 complexity | b0042c4d95c6c876b7516a56a800d990 MD5 | raw file
Possible License(s): Apache-2.0
  1. namespace SharpTAL.SharpTALTests.METALTests
  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 METALNameSpaceTests
  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<int>() { 1 });
  29. globals.Add("two", new List<string>() { "one", "two" });
  30. globals.Add("three", new List<object>() { 1, "Two", 3 });
  31. }
  32. public static void RunTest(string macros, string template, string expected, string errMsg)
  33. {
  34. template += macros;
  35. string actual = new Template(template).Render(globals);
  36. actual = actual.Replace("{", "{{").Replace("}", "}}");
  37. Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
  38. Environment.NewLine, errMsg, template, actual, expected);
  39. }
  40. // Test that rebinding the namespaces works
  41. [Test]
  42. public void TestSingleBindNoCommands()
  43. {
  44. RunTest(@"",
  45. @"<html xmlns:newmetal=""http://xml.zope.org/namespaces/metal""><body metal:use-macro=""macros[&quot;one&quot;]"">Nowt <i metal:fill-slot=""blue"">white</i> here</body></html>",
  46. @"<html><body metal:use-macro=""macros[&quot;one&quot;]"">Nowt <i metal:fill-slot=""blue"">white</i> here</body></html>",
  47. "Single Bind, commands, failed.");
  48. }
  49. [Test]
  50. public void TestSingleBindCommands()
  51. {
  52. RunTest(@"<div xmlns:newmetal=""http://xml.zope.org/namespaces/metal"" newmetal:define-macro=""one"" class=""funny"">Before <b newmetal:define-slot=""blue"">blue</b> After</div>",
  53. @"<html xmlns:newmetal=""http://xml.zope.org/namespaces/metal""><body newmetal:use-macro='macros[""one""]'>Nowt <i newmetal:fill-slot=""blue"">white</i> here</body></html>",
  54. @"<html><div class=""funny"">Before <i>white</i> After</div></html>",
  55. "Single Bind, commands, failed.");
  56. }
  57. // Test to ensure that using elements in the metal namespace omits tags
  58. [Test]
  59. public void TestMETALEmlement()
  60. {
  61. RunTest(@"<newmetal:div xmlns:newmetal=""http://xml.zope.org/namespaces/metal"" newmetal:define-macro=""one"" class=""funny"">Before <b newmetal:define-slot=""blue"">blue</b> After</newmetal:div>",
  62. @"<html xmlns:newmetal=""http://xml.zope.org/namespaces/metal""><body newmetal:use-macro='macros[""one""]'>Nowt <newmetal:block newmetal:fill-slot=""blue"">white</newmetal:block> here</body></html>",
  63. @"<html>Before white After</html>",
  64. "METAL namespace does not cause implicit omit-tag");
  65. }
  66. }
  67. }