Files
Common-VS2019/SacsCoreUnitTests/Standard/Base/Utils/SerializableUtil_Tester.cs
T

66 lines
1.7 KiB
C#

using NUnit.Framework;
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
{
[TestFixture]
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();
// --- Tests ---
[Test]
public void SerializableUtil_DeepCopy()
{
// Clone test data.
TestData data = new TestData();
TestData data_DeepCopy = SerializableUtil.DeepCopy(data);
// Verify results.
Assert.That(data_DeepCopy is TestData, Is.EqualTo(true));
Assert.That(data_DeepCopy.stringValue, Is.EqualTo(data.stringValue));
Assert.That(data_DeepCopy.longValue, Is.EqualTo(data.longValue));
// Clone test data A.
TestDataA dataA = new TestDataA();
TestDataA dataA_DeepCopy = SerializableUtil.DeepCopy(dataA);
// Verify results.
Assert.That(dataA_DeepCopy is TestData, Is.EqualTo(true));
Assert.That(dataA_DeepCopy is TestDataA, Is.EqualTo(true));
Assert.That(dataA_DeepCopy.stringValue, Is.EqualTo(dataA.stringValue));
Assert.That(dataA_DeepCopy.longValue, Is.EqualTo(dataA.longValue));
Assert.That(dataA_DeepCopy.stringValue, Is.Not.EqualTo(data.stringValue));
Assert.That(dataA_DeepCopy.longValue, Is.Not.EqualTo(data.longValue));
}
// --- The End ---
}
}