Beispiel #1
0
        public void TestUnloadImportedTemplate()
        {
            string dir1 = Path.Combine(tmpdir, "d1");
            string a = "a() ::= <<dir1 a>>\n";
            string b = "b() ::= <<dir1 b>>\n";
            writeFile(dir1, "a.st", a);
            writeFile(dir1, "b.st", b);
            string dir2 = Path.Combine(tmpdir, "d2");
            a = "a() ::= << <b()> >>\n";
            writeFile(dir2, "a.st", a);

            TemplateGroup group1 = new TemplateGroupDirectory(dir1);
            TemplateGroup group2 = new TemplateGroupDirectory(dir2);
            group2.ImportTemplates(group1);

            Template st = group2.GetInstanceOf("a");
            Template st2 = group2.GetInstanceOf("b");
            int originalHashCode = RuntimeHelpers.GetHashCode(st);
            int originalHashCode2 = RuntimeHelpers.GetHashCode(st2);
            group1.Unload(); // blast cache
            st = group2.GetInstanceOf("a");
            int newHashCode = RuntimeHelpers.GetHashCode(st);
            Assert.AreEqual(originalHashCode == newHashCode, false); // diff objects

            string expected = " dir1 b ";
            string result = st.Render();
            Assert.AreEqual(expected, result);

            st = group2.GetInstanceOf("b");
            int newHashCode2 = RuntimeHelpers.GetHashCode(st);
            Assert.AreEqual(originalHashCode2 == newHashCode2, false); // diff objects
            result = st.Render();
            expected = "dir1 b";
            Assert.AreEqual(expected, result);
        }
Beispiel #2
0
 public void TestUnloadingSimpleGroup()
 {
     string dir = tmpdir;
     string a =
         "a(x) ::= <<foo>>\n";
     string b =
         "b() ::= <<bar>>\n";
     writeFile(dir, "a.st", a);
     writeFile(dir, "b.st", b);
     TemplateGroup group = new TemplateGroupDirectory(dir);
     group.Load(); // force load
     Template st = group.GetInstanceOf("a");
     int originalHashCode = RuntimeHelpers.GetHashCode(st);
     group.Unload(); // blast cache
     st = group.GetInstanceOf("a");
     int newHashCode = RuntimeHelpers.GetHashCode(st);
     Assert.AreEqual(originalHashCode == newHashCode, false); // diff objects
     string expected = "foo";
     string result = st.Render();
     Assert.AreEqual(expected, result);
     st = group.GetInstanceOf("b");
     expected = "bar";
     result = st.Render();
     Assert.AreEqual(expected, result);
 }