Exemplo n.º 1
0
        public void Alter()
        {
            var testObj = new TypedObject();
            var dict = new DynamicAdapter(testObj, new MapOptions {
                CanAlterProperties = false
            });

            dynamic dyn = dict;

            Assert.Throws<InvalidOperationException>(() =>
            {
                dyn.newprop = "newdata";
            }, "Can't add a prop");

            Assert.Throws<InvalidOperationException>(() =>
            {
                dict.Remove("Stringprop");
            }, "Can't rmove a prop");

            // we can update with just CanAlterProprerties=false but IsReadOnly=true

            dyn.stringprop = "stringdata";

            dict.Options.CanAlterProperties = true;

            dyn.newprop = "newdata";
            Assert.AreEqual("newdata",dict["Newprop"]);

            Assert.IsTrue(dict.ContainsKey("stringprop"));
            dict.Remove("Stringprop");
            Assert.IsFalse(dict.ContainsKey("stringprop"));
        }
Exemplo n.º 2
0
        public void Remove()
        {
            var testObj = new TypedObject();
            var dict = new DynamicAdapter(testObj);
            dynamic dyn=dict;

            int count = dict.Count;
            dyn.newprop = "newdata";
            Assert.AreEqual(count + 1, dict.Count, "Added a property");

            Assert.IsTrue(dict.Remove("stringprop"));
            Assert.AreEqual(count, dict.Count, "Removed a property");

            dict["doubleprop"] = 5.67;
            Assert.IsFalse(dict.Remove(new KeyValuePair<string,object>("doubleprop",1.23)),
                "Can't remove KVP with diff value");
            Assert.IsTrue(dict.ContainsKey("DoubleProp"));

            Assert.IsTrue(dict.Remove(new KeyValuePair<string,object>("doubleprop",5.67)),
                "Removed KVP with wrong case");
            Assert.IsFalse(dict.ContainsKey("DoubleProp"));

            Assert.AreEqual(count - 1, dict.Count, "Count is correct at end");
        }