Exemplo n.º 1
0
        public void test_StringTemplate()
        {
            var st = new StringTemplate();

            var vars = new Hashtable()
            {
                { "name", "John" },
                { "company", "Johnson&Johnson" },
                { "age", 65 },
                { "birthday", new DateTime(1985, 1, 5) }
            };
            var noMarkerStr = "Just a text without markers.";

            Assert.AreEqual(noMarkerStr, st.Eval(vars, noMarkerStr));

            var simpleMarkersStr    = "Hello, {var:name}, you are {var:age} years old! You born in {databind:[birthday].Month}/{var:birthday,dd}.";
            var simpleMarkersStrRes = "Hello, John, you are 65 years old! You born in 1/05.";

            Assert.AreEqual(simpleMarkersStrRes, st.Eval(vars, simpleMarkersStr));

            Assert.AreEqual("Johnson&Johnson", st.Eval(vars, "{xml:{var:company}}"));
        }