From 8a1fc6b420132425949ae7ccd963f58854e4298c Mon Sep 17 00:00:00 2001 From: Falcon <12919280+falconfly@user.noreply.gitee.com> Date: Thu, 24 Oct 2024 11:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=90=86=E7=B1=BB?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi.Test/ProxyTest.cs | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Falcon.SugarApi.Test/ProxyTest.cs 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); + } + } + + } + +}