the examples for .Proxy()

 using Sparrow.Reflection;

    [TestClass]
    public class ProxyTest
    {
        [TestMethod]
        public void get_value_via_property_proxy()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            Assert.AreEqual(obj.Name, obj.Proxy().Properties["Name"]);
        }

        [TestMethod]
        public void set_value_via_property_proxy()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            var changedLocation = "Xiamen,China";
            obj.Proxy().Properties["Location"] = changedLocation;

            Assert.AreEqual(changedLocation,obj.Location);
        }


        [TestMethod]
        public void get_value_via_field_proxy()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            Assert.AreEqual(obj.Country, obj.Proxy().Fields["Country"]);
        }

             
        [TestMethod]
        public void invoke_method_via_method_proxy()
        {
            var obj = new MockObject();

            Assert.AreEqual("Hi,world", obj.Proxy().Methods["SayHello"](new []{"world"}));
        }

        [TestMethod]
        public void shortcut_for_set_property_value()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            var changedLocation = "Xiamen,China";
            obj.Proxy()["Location"] = changedLocation;

            Assert.AreEqual(changedLocation, obj.Location);
        }


        [TestMethod]
        public void shortcut_for_get_property_value()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            Assert.AreEqual(obj.Location, obj.Proxy()["Location"]);
        }

        [TestMethod]
        public void shortcut_for_get_field_value()
        {
            var obj = new MockObject { Name = "dayi", Blog = "http://walkingboy.cnblogs.com", Location = "Xiamen" };

            Assert.AreEqual("China", obj.Proxy()["Country"]);
        }


    }

Last edited Aug 29, 2010 at 12:17 PM by cnlangzi, version 1

Comments

No comments yet.