Falcon.SugarApi/Falcon.SugarApi.Test/ObjectExtendTest.cs

59 lines
1.6 KiB
C#
Raw Normal View History

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));
}
}
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";
}
}