Beispiel #1
0
        public void SimpleVariableExpansion()
        {
            var propCollection = new PropertyCollection(new Dictionary<string, object>
            {
                {"a", "123"},
                {"b", "456"},
            });
            var cfg = new ResolvingPropertyCollection();
            cfg.AddResolver(new VariableResolver(propCollection));

            cfg.SetValue("v1", "$a$");
            cfg.SetValue("v2", "pre$a$");
            cfg.SetValue("v3", "$a$post");
            cfg.SetValue("v4", "pre$a$post");
            cfg.SetValue("v5", "$a$$a$$a$");
            cfg.SetValue("v6", "$a$$b$");

            Assert.AreEqual("123", cfg.GetValue("v1"));
            Assert.AreEqual("pre123", cfg.GetValue("v2"));
            Assert.AreEqual("123post", cfg.GetValue("v3"));
            Assert.AreEqual("pre123post", cfg.GetValue("v4"));
            Assert.AreEqual("123123123", cfg.GetValue("v5"));
            Assert.AreEqual("123456", cfg.GetValue("v6"));
        }
Beispiel #2
0
        public void InvalidVariableReference()
        {
            var propCollection = new PropertyCollection(new Dictionary<string, object>
            {
                {"a", "123"},
            });
            var cfg = new ResolvingPropertyCollection();
            cfg.AddResolver(new VariableResolver(propCollection));

            cfg.SetValue("v1", " $a ");
            cfg.SetValue("v2", " a$ ");
            cfg.SetValue("v3", " $a $ ");
            cfg.SetValue("v4", " $x$ ");

            Assert.AreEqual(" $a ", cfg.GetValue("v1"));
            Assert.AreEqual(" a$ ", cfg.GetValue("v2"));
            Assert.AreEqual(" #a # ", cfg.GetValue("v3"));
            Assert.AreEqual(" #x# ", cfg.GetValue("v4"));
        }
Beispiel #3
0
        public void InvalidVariableValue()
        {
            var propCollection = new PropertyCollection(new Dictionary<string, object>
            {
                {"a", 123},
                {"b", true},
            });
            var cfg = new ResolvingPropertyCollection();
            cfg.AddResolver(new VariableResolver(propCollection));

            cfg.SetValue("v1", "$a$");
            cfg.SetValue("v2", "$b$");

            Assert.AreEqual("#a#", cfg.GetValue("v1"));
            Assert.AreEqual("#b#", cfg.GetValue("v2"));
        }