添加代理类测试
This commit is contained in:
parent
d32e95cdff
commit
8a1fc6b420
68
Falcon.SugarApi.Test/ProxyTest.cs
Normal file
68
Falcon.SugarApi.Test/ProxyTest.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using Falcon.SugarApi.Proxy;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Falcon.SugarApi.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// 代理类测试
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ProxyTest
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础功能测试
|
||||
/// </summary>
|
||||
[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<TestObject>
|
||||
{
|
||||
public ProxyObj1(TestObject target) : base(target) {
|
||||
}
|
||||
|
||||
public override void SetAction(string prop,object? value) {
|
||||
value = "ProxyObj1 run:" + value;
|
||||
base.SetAction(prop,value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user