示例#1
0
        public void TestWeCanResetAdaptorCacheInvalidatedUponAdaptorReset()
        {
            string templates =
                    "foo(x) ::= \"<x.id>: <x.name>\"\n";
            writeFile(tmpdir, "foo.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "foo.stg"));
            group.RegisterModelAdaptor(typeof(User), new UserAdaptor());
            group.GetModelAdaptor(typeof(User)); // get User, SuperUser into cache
            group.GetModelAdaptor(typeof(SuperUser));

            group.RegisterModelAdaptor(typeof(User), new UserAdaptorConst());
            // cache should be reset so we see new adaptor
            Template st = group.GetInstanceOf("foo");
            st.Add("x", new User(100, "parrt"));
            string expecting = "const id value: const name value"; // sees UserAdaptorConst
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }