All cloners are now able to clone objects without default constructors; began work on a property-based expression tree cloner
git-svn-id: file:///srv/devel/repo-conversion/nusu@243 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
91da3679a8
commit
db8c93eabd
8 changed files with 613 additions and 124 deletions
|
@ -27,128 +27,128 @@ using NUnit.Framework;
|
|||
|
||||
namespace Nuclex.Support.Cloning {
|
||||
|
||||
/// <summary>Unit Test for the expression tree-based cloner</summary>
|
||||
[TestFixture]
|
||||
public class ExpressionTreeClonerTest : CloneFactoryTest {
|
||||
/// <summary>Unit Test for the expression tree-based cloner</summary>
|
||||
[TestFixture]
|
||||
internal class ExpressionTreeClonerTest : CloneFactoryTest {
|
||||
|
||||
/// <summary>Initializes a new unit test suite for the reflection cloner</summary>
|
||||
public ExpressionTreeClonerTest() {
|
||||
this.cloneFactory = new ExpressionTreeCloner();
|
||||
}
|
||||
/// <summary>Initializes a new unit test suite for the reflection cloner</summary>
|
||||
public ExpressionTreeClonerTest() {
|
||||
this.cloneFactory = new ExpressionTreeCloner();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that clones of primitive types can be created</summary>
|
||||
[Test]
|
||||
public void PrimitiveTypesCanBeCloned() {
|
||||
int original = 12345;
|
||||
int clone = this.cloneFactory.DeepClone(original, false);
|
||||
Assert.AreEqual(original, clone);
|
||||
}
|
||||
/// <summary>Verifies that clones of primitive types can be created</summary>
|
||||
[Test]
|
||||
public void PrimitiveTypesCanBeCloned() {
|
||||
int original = 12345;
|
||||
int clone = this.cloneFactory.DeepClone(original, false);
|
||||
Assert.AreEqual(original, clone);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void ReferenceTypesCanBeCloned() {
|
||||
var original = new TestReferenceType() { TestField = 123, TestProperty = 456 };
|
||||
TestReferenceType clone = this.cloneFactory.DeepClone(original, false);
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void ReferenceTypesCanBeCloned() {
|
||||
var original = new TestReferenceType() { TestField = 123, TestProperty = 456 };
|
||||
TestReferenceType clone = this.cloneFactory.DeepClone(original, false);
|
||||
|
||||
Assert.AreNotSame(original, clone);
|
||||
Assert.AreEqual(original.TestField, clone.TestField);
|
||||
Assert.AreEqual(original.TestProperty, clone.TestProperty);
|
||||
}
|
||||
Assert.AreNotSame(original, clone);
|
||||
Assert.AreEqual(original.TestField, clone.TestField);
|
||||
Assert.AreEqual(original.TestProperty, clone.TestProperty);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void PrimitiveArraysCanBeCloned() {
|
||||
var original = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int[] clone = this.cloneFactory.DeepClone(original, false);
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void PrimitiveArraysCanBeCloned() {
|
||||
var original = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int[] clone = this.cloneFactory.DeepClone(original, false);
|
||||
|
||||
Assert.AreNotSame(original, clone);
|
||||
CollectionAssert.AreEqual(original, clone);
|
||||
}
|
||||
Assert.AreNotSame(original, clone);
|
||||
CollectionAssert.AreEqual(original, clone);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void ShallowClonesOfArraysCanBeMade() {
|
||||
var original = new TestReferenceType[] {
|
||||
/// <summary>Verifies that shallow clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void ShallowClonesOfArraysCanBeMade() {
|
||||
var original = new TestReferenceType[] {
|
||||
new TestReferenceType() { TestField = 123, TestProperty = 456 }
|
||||
};
|
||||
TestReferenceType[] clone = this.cloneFactory.ShallowClone(original, false);
|
||||
TestReferenceType[] clone = this.cloneFactory.ShallowClone(original, false);
|
||||
|
||||
Assert.AreSame(original[0], clone[0]);
|
||||
}
|
||||
Assert.AreSame(original[0], clone[0]);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deep clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void DeepClonesOfArraysCanBeMade() {
|
||||
var original = new TestReferenceType[,] {
|
||||
/// <summary>Verifies that deep clones of arrays can be made</summary>
|
||||
[Test]
|
||||
public void DeepClonesOfArraysCanBeMade() {
|
||||
var original = new TestReferenceType[,] {
|
||||
{
|
||||
new TestReferenceType() { TestField = 123, TestProperty = 456 }
|
||||
}
|
||||
};
|
||||
TestReferenceType[,] clone = this.cloneFactory.DeepClone(original, false);
|
||||
TestReferenceType[,] clone = this.cloneFactory.DeepClone(original, false);
|
||||
|
||||
Assert.AreNotSame(original[0, 0], clone[0, 0]);
|
||||
Assert.AreEqual(original[0, 0].TestField, clone[0, 0].TestField);
|
||||
Assert.AreEqual(original[0, 0].TestProperty, clone[0, 0].TestProperty);
|
||||
}
|
||||
Assert.AreNotSame(original[0, 0], clone[0, 0]);
|
||||
Assert.AreEqual(original[0, 0].TestField, clone[0, 0].TestField);
|
||||
Assert.AreEqual(original[0, 0].TestProperty, clone[0, 0].TestProperty);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deep clones of a generic list can be made</summary>
|
||||
[Test]
|
||||
public void GenericListsCanBeCloned() {
|
||||
var original = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
|
||||
List<int> clone = this.cloneFactory.DeepClone(original, false);
|
||||
/// <summary>Verifies that deep clones of a generic list can be made</summary>
|
||||
[Test]
|
||||
public void GenericListsCanBeCloned() {
|
||||
var original = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
|
||||
List<int> clone = this.cloneFactory.DeepClone(original, false);
|
||||
|
||||
CollectionAssert.AreEqual(original, clone);
|
||||
}
|
||||
CollectionAssert.AreEqual(original, clone);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that deep clones of a generic dictionary can be made</summary>
|
||||
[Test]
|
||||
public void GenericDictionariesCanBeCloned() {
|
||||
var original = new Dictionary<int, string>();
|
||||
original.Add(1, "one");
|
||||
Dictionary<int, string> clone = this.cloneFactory.DeepClone(original, false);
|
||||
/// <summary>Verifies that deep clones of a generic dictionary can be made</summary>
|
||||
[Test]
|
||||
public void GenericDictionariesCanBeCloned() {
|
||||
var original = new Dictionary<int, string>();
|
||||
original.Add(1, "one");
|
||||
Dictionary<int, string> clone = this.cloneFactory.DeepClone(original, false);
|
||||
|
||||
Assert.AreEqual("one", clone[1]);
|
||||
}
|
||||
Assert.AreEqual("one", clone[1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a field-based shallow clone of a value type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ShallowFieldBasedClonesOfValueTypesCanBeMade() {
|
||||
HierarchicalValueType original = CreateValueType();
|
||||
HierarchicalValueType clone = this.cloneFactory.ShallowClone(original, false);
|
||||
VerifyClone(ref original, ref clone, isDeepClone: false, isPropertyBasedClone: false);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that a field-based shallow clone of a value type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ShallowFieldBasedClonesOfValueTypesCanBeMade() {
|
||||
HierarchicalValueType original = CreateValueType();
|
||||
HierarchicalValueType clone = this.cloneFactory.ShallowClone(original, false);
|
||||
VerifyClone(ref original, ref clone, isDeepClone: false, isPropertyBasedClone: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a field-based shallow clone of a reference type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ShallowFieldBasedClonesOfReferenceTypesCanBeMade() {
|
||||
HierarchicalReferenceType original = CreateReferenceType();
|
||||
HierarchicalReferenceType clone = this.cloneFactory.ShallowClone(original, false);
|
||||
VerifyClone(original, clone, isDeepClone: false, isPropertyBasedClone: false);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that a field-based shallow clone of a reference type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ShallowFieldBasedClonesOfReferenceTypesCanBeMade() {
|
||||
HierarchicalReferenceType original = CreateReferenceType();
|
||||
HierarchicalReferenceType clone = this.cloneFactory.ShallowClone(original, false);
|
||||
VerifyClone(original, clone, isDeepClone: false, isPropertyBasedClone: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a field-based deep clone of a value type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeepFieldBasedClonesOfValueTypesCanBeMade() {
|
||||
HierarchicalValueType original = CreateValueType();
|
||||
HierarchicalValueType clone = this.cloneFactory.DeepClone(original, false);
|
||||
VerifyClone(ref original, ref clone, isDeepClone: true, isPropertyBasedClone: false);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that a field-based deep clone of a value type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeepFieldBasedClonesOfValueTypesCanBeMade() {
|
||||
HierarchicalValueType original = CreateValueType();
|
||||
HierarchicalValueType clone = this.cloneFactory.DeepClone(original, false);
|
||||
VerifyClone(ref original, ref clone, isDeepClone: true, isPropertyBasedClone: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a field-based deep clone of a reference type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeepFieldBasedClonesOfReferenceTypesCanBeMade() {
|
||||
HierarchicalReferenceType original = CreateReferenceType();
|
||||
HierarchicalReferenceType clone = this.cloneFactory.DeepClone(original, false);
|
||||
VerifyClone(original, clone, isDeepClone: true, isPropertyBasedClone: false);
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifies that a field-based deep clone of a reference type can be performed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeepFieldBasedClonesOfReferenceTypesCanBeMade() {
|
||||
HierarchicalReferenceType original = CreateReferenceType();
|
||||
HierarchicalReferenceType clone = this.cloneFactory.DeepClone(original, false);
|
||||
VerifyClone(original, clone, isDeepClone: true, isPropertyBasedClone: false);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
|
@ -194,10 +194,10 @@ namespace Nuclex.Support.Cloning {
|
|||
}
|
||||
#endif
|
||||
|
||||
/// <summary>Clone factory being tested</summary>
|
||||
private ICloneFactory cloneFactory;
|
||||
/// <summary>Clone factory being tested</summary>
|
||||
private ICloneFactory cloneFactory;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Cloning
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue