67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sacs.UnitTests.Net.Standard.Base.Utils
|
|
{
|
|
[TestClass]
|
|
public class SerializableUtil_Tester
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
[Serializable]
|
|
private class TestData
|
|
{
|
|
public String stringValue = "String Value";
|
|
public long longValue = 123456;
|
|
}
|
|
[Serializable]
|
|
private class TestDataA : TestData
|
|
{
|
|
public TestDataA()
|
|
{
|
|
stringValue = "String Value A";
|
|
longValue = 654321;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private Random random = new Random();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Deep Copy.
|
|
//-------------------------------------------------------------------
|
|
[TestMethod]
|
|
public void SerializableUtil_DeepCopy()
|
|
{
|
|
// Clone test data.
|
|
TestData data = new TestData();
|
|
TestData data_DeepCopy = SerializableUtil.DeepCopy(data);
|
|
|
|
// Verify results.
|
|
Assert.AreEqual(true, data_DeepCopy is TestData);
|
|
Assert.AreEqual(data.stringValue, data_DeepCopy.stringValue);
|
|
Assert.AreEqual(data.longValue, data_DeepCopy.longValue);
|
|
|
|
// Clone test data A.
|
|
TestDataA dataA = new TestDataA();
|
|
TestDataA dataA_DeepCopy = SerializableUtil.DeepCopy(dataA);
|
|
|
|
// Verify results.
|
|
Assert.AreEqual(true, dataA_DeepCopy is TestData);
|
|
Assert.AreEqual(true, dataA_DeepCopy is TestDataA);
|
|
Assert.AreEqual(dataA.stringValue, dataA_DeepCopy.stringValue);
|
|
Assert.AreEqual(dataA.longValue, dataA_DeepCopy.longValue);
|
|
Assert.AreNotEqual(data.stringValue, dataA_DeepCopy.stringValue);
|
|
Assert.AreNotEqual(data.longValue, dataA_DeepCopy.longValue);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|