using Falcon.SugarApi.Proxy; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Falcon.SugarApi.Test { /// /// 代理类测试 /// [TestClass] public class ProxyTest { /// /// 基础功能测试 /// [TestMethod] public void BaseTest() { var obj = new TestObject { Name = "tom" }; //普通代理测试 var pobj = new ProxyObj(obj); pobj.SetAction("Name","123"); Assert.AreEqual(obj.Name,"ProxyObj run:123"); Assert.IsTrue(pobj.GetFunc("Name").ToString() == "ProxyObj run:123"); pobj.Invoke("SetName","jack"); Assert.IsTrue(obj.Name == "jack"); //泛型代理测试 var pobj1 = new ProxyObj1(obj); pobj1.SetAction("Name","123"); Assert.AreEqual(obj.Name,"ProxyObj1 run:123"); Assert.IsTrue(pobj1.GetFunc("Name").ToString() == "ProxyObj1 run:123"); pobj1.Invoke("SetName","jack1"); Assert.IsTrue(obj.Name == "jack1"); } class TestObject { public string Name { get; set; } public void SetName(string newName) { this.Name = newName; } } class ProxyObj:ProxyBase { public ProxyObj(object target) : base(target) { } public override void SetAction(string prop,object? value) { value = "ProxyObj run:" + value; base.SetAction(prop,value); } } class ProxyObj1:Proxy { public ProxyObj1(TestObject target) : base(target) { } public override void SetAction(string prop,object? value) { value = "ProxyObj1 run:" + value; base.SetAction(prop,value); } } } }