Esempio n. 1
0
        public void StringTemplateValueConverter_Caches_And_Reuses_Converters_And_Behaves_Properly_When_Caches_Are_Cleared()
        {
            StringTemplate.ClearCache(); // Make sure we don't use instances from other tests...

            var values = new ValuesWithMiscConverters {
                AttributedWithStateMutatorConverter = 0
            };
            var otherValues = new OtherValuesWithMiscConverters {
                AttributedWithStateMutatorConverter2 = 0
            };

            string actual1 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);
            string actual2 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);

            // Clear the cached getters and converters.
            // This test will fail if the getters cache is cleared, but not the converters cache.
            StringTemplate.ClearCache();

            string actual3 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);
            string actual4 = StringTemplate.Format("{AttributedWithStateMutatorConverter2}", otherValues);

            // The converter instance should be reused, so its state is preserved and incremented between calls
            Assert.Equal("1", actual1);
            Assert.Equal("2", actual2);
            Assert.Equal("1", actual3);
            Assert.Equal("2", actual4); // tests caching across types and members
        }
Esempio n. 2
0
        public void Test_ClearCached()
        {
            var t1 = StringTemplate.Parse("{X}");

            StringTemplate.ClearCache();
            var t2 = StringTemplate.Parse("{X}");

            Assert.NotSame(t1, t2);
        }
Esempio n. 3
0
        public void StringTemplateValueConverter_Caches_And_Reuses_Converters()
        {
            StringTemplate.ClearCache(); // Make sure we don't use instances from other tests...

            var values = new ValuesWithMiscConverters {
                AttributedWithStateMutatorConverter = 0
            };
            var otherValues = new OtherValuesWithMiscConverters {
                AttributedWithStateMutatorConverter2 = 0
            };

            string actual1 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);
            string actual2 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);
            string actual3 = StringTemplate.Format("{AttributedWithStateMutatorConverter}", values);
            string actual4 = StringTemplate.Format("{AttributedWithStateMutatorConverter2}", otherValues);

            // The converter instance should be reused, so its state is preserved and incremented between calls
            Assert.Equal("1", actual1);
            Assert.Equal("2", actual2);
            Assert.Equal("3", actual3);
            Assert.Equal("4", actual4); // tests caching across types and members
        }