Falcon.SugarApi/Falcon.SugarApi.Test/ObjectExtendTest.cs
2022-07-14 09:01:38 +08:00

67 lines
1.8 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Falcon.SugarApi;
namespace Falcon.SugarApi.Test
{
[TestClass]
public class ObjectExtendTest
{
[TestMethod]
public void CloneToTest() {
var s = new SourceClass { };
var t = new TargetClass { };
t.ica.ItemA = "itemb";
Assert.IsTrue(t.ica.ItemA == "itemb");
var r = s.CloneTo(t);
Assert.IsNotNull(s);
Assert.IsNotNull(r);
Assert.IsNotNull(t);
Assert.IsTrue(s.ia == t.ia, $"a.id:{s.ia},t.ia:{t.ia}");
Assert.IsTrue(t.ia == 1);
Assert.IsTrue(s.sa == t.sa);
Assert.IsTrue(s.sc == "sc");
Assert.IsTrue(t.sd == "sd");
Assert.IsTrue(s.ica.ItemA == "itema");
Assert.IsTrue(t.ica.ItemA == "itema");
Assert.IsTrue(t.ica.Equals(s.ica));
}
[TestMethod]
public void ChangeTypeTest() {
int s = 1;
var t = s.ChangeType(typeof(int));
Console.WriteLine(t.GetType().FullName);
Assert.IsTrue(t.GetType().Equals(typeof(int)));
}
}
public class SourceClass
{
public int ia { get; set; } = 1;
public string sa { get; set; } = "sa";
public string sc { get; set; } = "sc";
public ItemClass ica { get; set; } = new ItemClass();
}
public class TargetClass
{
public int ia { get; set; }
public string sa { get; set; }
public string sd { get; set; } = "sd";
public ItemClass ica { get; set; } = new ItemClass();
}
public class ItemClass
{
public string ItemA { get; set; } = "itema";
}
}