diff --git a/Falcon.SugarApi.Test/ProxyTest.cs b/Falcon.SugarApi.Test/ProxyTest.cs new file mode 100644 index 0000000..71c1ad4 --- /dev/null +++ b/Falcon.SugarApi.Test/ProxyTest.cs @@ -0,0 +1,68 @@ +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); + } + } + + } + +}