Example #1
0
        [Test] public void CloneComplexObject()
        {
            Random     rnd        = new Random(1);
            TestObject data       = new TestObject(rnd, 5);
            TestObject dataResult = data.DeepClone();

            Assert.IsTrue(data.Equals(dataResult));
            Assert.IsFalse(data.AnyReferenceEquals(dataResult));
        }
Example #2
0
		[Test] public void CloneComplexObject()
		{
			Random rnd = new Random();
			TestObject data = new TestObject(rnd, 5);
			TestObject dataResult = data.DeepClone();

			Assert.IsTrue(data.Equals(dataResult));
			Assert.IsFalse(data.AnyReferenceEquals(dataResult));
		}
Example #3
0
		[Test] public void CopyToTarget()
		{
			Random rnd = new Random();
			TestObject data = new TestObject(rnd, 5);
			TestObject dataResult = new TestObject();
			data.DeepCopyTo(dataResult);

			Assert.IsTrue(data.Equals(dataResult));
			Assert.IsFalse(data.AnyReferenceEquals(dataResult));
		}
Example #4
0
        [Test] public void CopyToTarget()
        {
            Random     rnd        = new Random(1);
            TestObject data       = new TestObject(rnd, 5);
            TestObject dataResult = new TestObject();

            data.DeepCopyTo(dataResult);

            Assert.IsTrue(data.Equals(dataResult));
            Assert.IsFalse(data.AnyReferenceEquals(dataResult));
        }
Example #5
0
		[Test] public void CopyToTargetPreservation()
		{
			// Create two identical test objects, then change one field
			TestObject source = new TestObject(new Random(0), 5);
			TestObject target = new TestObject(new Random(0), 5);
			TestObject targetFirstChild = target.DictField.First().Value;
			source.StringField = "NewValue";

			// Copy data from source to target
			source.DeepCopyTo(target);

			// Make sure the data is equal and old object instances have been preserved
			Assert.IsTrue(source.Equals(target));
			Assert.IsFalse(source.AnyReferenceEquals(target));
			Assert.AreSame(targetFirstChild, target.DictField.First().Value);
		}
Example #6
0
        [Test] public void CopyToTargetPreservation()
        {
            // Create two identical test objects, then change one field
            TestObject source           = new TestObject(new Random(0), 5);
            TestObject target           = new TestObject(new Random(0), 5);
            TestObject targetFirstChild = target.DictField.First().Value;

            source.StringField = "NewValue";

            // Copy data from source to target
            source.DeepCopyTo(target);

            // Make sure the data is equal and old object instances have been preserved
            Assert.IsTrue(source.Equals(target));
            Assert.IsFalse(source.AnyReferenceEquals(target));
            Assert.AreSame(targetFirstChild, target.DictField.First().Value);
        }
Example #7
0
        [Test] public void CopyToTargetPreservation()
        {
            // Create two identical test objects, then change one field
            TestObject source = new TestObject(new Random(0), 5);
            TestObject target = new TestObject(new Random(0), 5);
            TestObject targetFirstDictChild = target.DictField.First().Value;

            source.StringField = "NewValue";

            // Copy data from source to target
            source.DeepCopyTo(target);

            // Make sure the data is equal and old object instances have been preserved
            Assert.IsTrue(source.Equals(target));
            Assert.IsFalse(source.AnyReferenceEquals(target));
            Assert.AreSame(targetFirstDictChild, target.DictField.First().Value);

            // Note that we can't expect hashset child objects to be preserved, as
            // there is no defined item identity in a hashset. It cannot be indexed
            // by any value, so there is no definition of an "equivalent" item in
            // source and target.
        }