Removed UNITTEST constant from most files; tried switching to Moq, but encountered some InternalsVisibleTo() problems; ripped out NuGet again because it is so very bad
This commit is contained in:
parent
8b011981d9
commit
090b1375c0
26 changed files with 31 additions and 123 deletions
592
Tests/Cloning/CloneFactoryTest.cs
Normal file
592
Tests/Cloning/CloneFactoryTest.cs
Normal file
|
@ -0,0 +1,592 @@
|
|||
#region Apache License 2.0
|
||||
/*
|
||||
Nuclex .NET Framework
|
||||
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
using System;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Cloning {
|
||||
|
||||
/// <summary>Base class for unit tests verifying the clone factory</summary>
|
||||
internal abstract class CloneFactoryTest {
|
||||
|
||||
#region class DerivedReferenceType
|
||||
|
||||
/// <summary>A derived reference type being used for testing</summary>
|
||||
protected class DerivedReferenceType : TestReferenceType {
|
||||
|
||||
/// <summary>Field holding an integer value for testing</summary>
|
||||
public int DerivedField;
|
||||
/// <summary>Property holding an integer value for testing</summary>
|
||||
public int DerivedProperty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#endregion // class DerivedReferenceType
|
||||
|
||||
#region class TestReferenceType
|
||||
|
||||
/// <summary>A reference type being used for testing</summary>
|
||||
protected class TestReferenceType {
|
||||
|
||||
/// <summary>Field holding an integer value for testing</summary>
|
||||
public int TestField;
|
||||
/// <summary>Property holding an integer value for testing</summary>
|
||||
public int TestProperty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#endregion // class TestReferenceType
|
||||
|
||||
#region struct TestValueType
|
||||
|
||||
/// <summary>A value type being used for testing</summary>
|
||||
protected struct TestValueType {
|
||||
|
||||
/// <summary>Field holding an integer value for testing</summary>
|
||||
public int TestField;
|
||||
/// <summary>Property holding an integer value for testing</summary>
|
||||
public int TestProperty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#endregion // struct TestValueType
|
||||
|
||||
#region struct HierarchicalValueType
|
||||
|
||||
/// <summary>A value type containiner other complex types used for testing</summary>
|
||||
protected struct HierarchicalValueType {
|
||||
|
||||
/// <summary>Field holding an integer value for testing</summary>
|
||||
public int TestField;
|
||||
/// <summary>Property holding an integer value for testing</summary>
|
||||
public int TestProperty { get; set; }
|
||||
/// <summary>Value type field for testing</summary>
|
||||
public TestValueType ValueTypeField;
|
||||
/// <summary>Value type property for testing</summary>
|
||||
public TestValueType ValueTypeProperty { get; set; }
|
||||
/// <summary>Reference type field for testing</summary>
|
||||
public TestReferenceType ReferenceTypeField;
|
||||
/// <summary>Reference type property for testing</summary>
|
||||
public TestReferenceType ReferenceTypeProperty { get; set; }
|
||||
/// <summary>An array field of reference types</summary>
|
||||
public TestReferenceType[,][] ReferenceTypeArrayField;
|
||||
/// <summary>An array property of reference types</summary>
|
||||
public TestReferenceType[,][] ReferenceTypeArrayProperty { get; set; }
|
||||
/// <summary>A reference type field that's always null</summary>
|
||||
public TestReferenceType AlwaysNullField;
|
||||
/// <summary>A reference type property that's always null</summary>
|
||||
public TestReferenceType AlwaysNullProperty { get; set; }
|
||||
/// <summary>A property that only has a getter</summary>
|
||||
public TestReferenceType GetOnlyProperty { get { return null; } }
|
||||
/// <summary>A property that only has a setter</summary>
|
||||
public TestReferenceType SetOnlyProperty { set { } }
|
||||
/// <summary>A read-only field</summary>
|
||||
public readonly TestValueType ReadOnlyField;
|
||||
/// <summary>Field typed as base class holding a derived instance</summary>
|
||||
public TestReferenceType DerivedField;
|
||||
/// <summary>Field typed as base class holding a derived instance</summary>
|
||||
public TestReferenceType DerivedProperty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#endregion // struct HierarchicalValueType
|
||||
|
||||
#region struct HierarchicalReferenceType
|
||||
|
||||
/// <summary>A value type containiner other complex types used for testing</summary>
|
||||
protected class HierarchicalReferenceType {
|
||||
|
||||
/// <summary>Field holding an integer value for testing</summary>
|
||||
public int TestField;
|
||||
/// <summary>Property holding an integer value for testing</summary>
|
||||
public int TestProperty { get; set; }
|
||||
/// <summary>Value type field for testing</summary>
|
||||
public TestValueType ValueTypeField;
|
||||
/// <summary>Value type property for testing</summary>
|
||||
public TestValueType ValueTypeProperty { get; set; }
|
||||
/// <summary>Reference type field for testing</summary>
|
||||
public TestReferenceType ReferenceTypeField;
|
||||
/// <summary>Reference type property for testing</summary>
|
||||
public TestReferenceType ReferenceTypeProperty { get; set; }
|
||||
/// <summary>An array field of reference types</summary>
|
||||
public TestReferenceType[,][] ReferenceTypeArrayField;
|
||||
/// <summary>An array property of reference types</summary>
|
||||
public TestReferenceType[,][] ReferenceTypeArrayProperty { get; set; }
|
||||
/// <summary>A reference type field that's always null</summary>
|
||||
public TestReferenceType AlwaysNullField;
|
||||
/// <summary>A reference type property that's always null</summary>
|
||||
public TestReferenceType AlwaysNullProperty { get; set; }
|
||||
/// <summary>A property that only has a getter</summary>
|
||||
public TestReferenceType GetOnlyProperty { get { return null; } }
|
||||
/// <summary>A property that only has a setter</summary>
|
||||
public TestReferenceType SetOnlyProperty { set { } }
|
||||
/// <summary>A read-only field</summary>
|
||||
public readonly TestValueType ReadOnlyField;
|
||||
/// <summary>Field typed as base class holding a derived instance</summary>
|
||||
public TestReferenceType DerivedField;
|
||||
/// <summary>Field typed as base class holding a derived instance</summary>
|
||||
public TestReferenceType DerivedProperty { get; set; }
|
||||
|
||||
}
|
||||
|
||||
#endregion // struct HierarchicalReferenceType
|
||||
|
||||
#region class ClassWithoutDefaultConstructor
|
||||
|
||||
/// <summary>A class that does not have a default constructor</summary>
|
||||
public class ClassWithoutDefaultConstructor {
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the class without default constructor
|
||||
/// </summary>
|
||||
/// <param name="dummy">Dummy value that will be saved by the instance</param>
|
||||
public ClassWithoutDefaultConstructor(int dummy) {
|
||||
this.dummy = dummy;
|
||||
}
|
||||
|
||||
/// <summary>Dummy value that has been saved by the instance</summary>
|
||||
public int Dummy {
|
||||
get { return this.dummy; }
|
||||
}
|
||||
|
||||
/// <summary>Dummy value that has been saved by the instance</summary>
|
||||
private int dummy;
|
||||
|
||||
}
|
||||
|
||||
#endregion // class ClassWithoutDefaultConstructor
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a cloned object exhibits the expected state for the type of
|
||||
/// clone that has been performed
|
||||
/// </summary>
|
||||
/// <param name="original">Original instance the clone was created from</param>
|
||||
/// <param name="clone">Cloned instance that will be checked for correctness</param>
|
||||
/// <param name="isDeepClone">Whether the cloned instance is a deep clone</param>
|
||||
/// <param name="isPropertyBasedClone">
|
||||
/// Whether a property-based clone was performed
|
||||
/// </param>
|
||||
protected static void VerifyClone(
|
||||
HierarchicalReferenceType original, HierarchicalReferenceType clone,
|
||||
bool isDeepClone, bool isPropertyBasedClone
|
||||
) {
|
||||
Assert.AreNotSame(original, clone);
|
||||
|
||||
if(isPropertyBasedClone) {
|
||||
Assert.AreEqual(0, clone.TestField);
|
||||
Assert.AreEqual(0, clone.ValueTypeField.TestField);
|
||||
Assert.AreEqual(0, clone.ValueTypeField.TestProperty);
|
||||
Assert.AreEqual(0, clone.ValueTypeProperty.TestField);
|
||||
Assert.IsNull(clone.ReferenceTypeField);
|
||||
Assert.IsNull(clone.DerivedField);
|
||||
|
||||
if(isDeepClone) {
|
||||
Assert.AreNotSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
Assert.AreNotSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedProperty);
|
||||
|
||||
var originalDerived = (DerivedReferenceType)original.DerivedProperty;
|
||||
var clonedDerived = (DerivedReferenceType)clone.DerivedProperty;
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
Assert.AreEqual(0, clone.ReferenceTypeProperty.TestField);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0]
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2]
|
||||
);
|
||||
Assert.AreEqual(0, clone.ReferenceTypeArrayProperty[1, 3][0].TestField);
|
||||
Assert.AreEqual(0, clone.ReferenceTypeArrayProperty[1, 3][2].TestField);
|
||||
} else {
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Assert.AreEqual(original.TestField, clone.TestField);
|
||||
Assert.AreEqual(original.ValueTypeField.TestField, clone.ValueTypeField.TestField);
|
||||
Assert.AreEqual(original.ValueTypeField.TestProperty, clone.ValueTypeField.TestProperty);
|
||||
Assert.AreEqual(
|
||||
original.ValueTypeProperty.TestField, clone.ValueTypeProperty.TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeField.TestField, clone.ReferenceTypeField.TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeField.TestProperty, clone.ReferenceTypeField.TestProperty
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeProperty.TestField, clone.ReferenceTypeProperty.TestField
|
||||
);
|
||||
|
||||
if(isDeepClone) {
|
||||
Assert.AreNotSame(original.ReferenceTypeField, clone.ReferenceTypeField);
|
||||
Assert.AreNotSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreNotSame(original.DerivedField, clone.DerivedField);
|
||||
Assert.AreNotSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedField);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedProperty);
|
||||
|
||||
var originalDerived = (DerivedReferenceType)original.DerivedField;
|
||||
var clonedDerived = (DerivedReferenceType)clone.DerivedField;
|
||||
Assert.AreEqual(originalDerived.TestField, clonedDerived.TestField);
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedField, clonedDerived.DerivedField);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
originalDerived = (DerivedReferenceType)original.DerivedProperty;
|
||||
clonedDerived = (DerivedReferenceType)clone.DerivedProperty;
|
||||
Assert.AreEqual(originalDerived.TestField, clonedDerived.TestField);
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedField, clonedDerived.DerivedField);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayField, clone.ReferenceTypeArrayField
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0]
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2]
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0].TestField,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0].TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2].TestField,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2].TestField
|
||||
);
|
||||
} else {
|
||||
Assert.AreSame(original.DerivedField, clone.DerivedField);
|
||||
Assert.AreSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.AreSame(original.ReferenceTypeField, clone.ReferenceTypeField);
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayField, clone.ReferenceTypeArrayField
|
||||
);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a cloned object exhibits the expected state for the type of
|
||||
/// clone that has been performed
|
||||
/// </summary>
|
||||
/// <param name="original">Original instance the clone was created from</param>
|
||||
/// <param name="clone">Cloned instance that will be checked for correctness</param>
|
||||
/// <param name="isDeepClone">Whether the cloned instance is a deep clone</param>
|
||||
/// <param name="isPropertyBasedClone">
|
||||
/// Whether a property-based clone was performed
|
||||
/// </param>
|
||||
protected static void VerifyClone(
|
||||
ref HierarchicalValueType original, ref HierarchicalValueType clone,
|
||||
bool isDeepClone, bool isPropertyBasedClone
|
||||
) {
|
||||
if(isPropertyBasedClone) {
|
||||
Assert.AreEqual(0, clone.TestField);
|
||||
Assert.AreEqual(0, clone.ValueTypeField.TestField);
|
||||
Assert.AreEqual(0, clone.ValueTypeField.TestProperty);
|
||||
Assert.AreEqual(0, clone.ValueTypeProperty.TestField);
|
||||
Assert.IsNull(clone.ReferenceTypeField);
|
||||
Assert.IsNull(clone.DerivedField);
|
||||
|
||||
if(isDeepClone) {
|
||||
Assert.AreNotSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
Assert.AreNotSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedProperty);
|
||||
|
||||
var originalDerived = (DerivedReferenceType)original.DerivedProperty;
|
||||
var clonedDerived = (DerivedReferenceType)clone.DerivedProperty;
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
Assert.AreEqual(0, clone.ReferenceTypeProperty.TestField);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0]
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2]
|
||||
);
|
||||
Assert.AreEqual(0, clone.ReferenceTypeArrayProperty[1, 3][0].TestField);
|
||||
Assert.AreEqual(0, clone.ReferenceTypeArrayProperty[1, 3][2].TestField);
|
||||
} else {
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Assert.AreEqual(original.TestField, clone.TestField);
|
||||
Assert.AreEqual(original.ValueTypeField.TestField, clone.ValueTypeField.TestField);
|
||||
Assert.AreEqual(original.ValueTypeField.TestProperty, clone.ValueTypeField.TestProperty);
|
||||
Assert.AreEqual(
|
||||
original.ValueTypeProperty.TestField, clone.ValueTypeProperty.TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeField.TestField, clone.ReferenceTypeField.TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeField.TestProperty, clone.ReferenceTypeField.TestProperty
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeProperty.TestField, clone.ReferenceTypeProperty.TestField
|
||||
);
|
||||
|
||||
if(isDeepClone) {
|
||||
Assert.AreNotSame(original.ReferenceTypeField, clone.ReferenceTypeField);
|
||||
Assert.AreNotSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreNotSame(original.DerivedField, clone.DerivedField);
|
||||
Assert.AreNotSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedField);
|
||||
Assert.IsInstanceOf<DerivedReferenceType>(clone.DerivedProperty);
|
||||
|
||||
var originalDerived = (DerivedReferenceType)original.DerivedField;
|
||||
var clonedDerived = (DerivedReferenceType)clone.DerivedField;
|
||||
Assert.AreEqual(originalDerived.TestField, clonedDerived.TestField);
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedField, clonedDerived.DerivedField);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
originalDerived = (DerivedReferenceType)original.DerivedProperty;
|
||||
clonedDerived = (DerivedReferenceType)clone.DerivedProperty;
|
||||
Assert.AreEqual(originalDerived.TestField, clonedDerived.TestField);
|
||||
Assert.AreEqual(originalDerived.TestProperty, clonedDerived.TestProperty);
|
||||
Assert.AreEqual(originalDerived.DerivedField, clonedDerived.DerivedField);
|
||||
Assert.AreEqual(originalDerived.DerivedProperty, clonedDerived.DerivedProperty);
|
||||
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayField, clone.ReferenceTypeArrayField
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0]
|
||||
);
|
||||
Assert.AreNotSame(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2],
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2]
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0].TestField,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0].TestField
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2].TestField,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2].TestField
|
||||
);
|
||||
} else {
|
||||
Assert.AreSame(original.DerivedField, clone.DerivedField);
|
||||
Assert.AreSame(original.DerivedProperty, clone.DerivedProperty);
|
||||
Assert.AreSame(original.ReferenceTypeField, clone.ReferenceTypeField);
|
||||
Assert.AreSame(original.ReferenceTypeProperty, clone.ReferenceTypeProperty);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayField, clone.ReferenceTypeArrayField
|
||||
);
|
||||
Assert.AreSame(
|
||||
original.ReferenceTypeArrayProperty, clone.ReferenceTypeArrayProperty
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(original.TestProperty, clone.TestProperty);
|
||||
Assert.AreEqual(
|
||||
original.ValueTypeProperty.TestProperty, clone.ValueTypeProperty.TestProperty
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeProperty.TestProperty, clone.ReferenceTypeProperty.TestProperty
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][0].TestProperty,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][0].TestProperty
|
||||
);
|
||||
Assert.AreEqual(
|
||||
original.ReferenceTypeArrayProperty[1, 3][2].TestProperty,
|
||||
clone.ReferenceTypeArrayProperty[1, 3][2].TestProperty
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Creates a value type with random data for testing</summary>
|
||||
/// <returns>A new value type with random data</returns>
|
||||
protected static HierarchicalValueType CreateValueType() {
|
||||
return new HierarchicalValueType() {
|
||||
TestField = 123,
|
||||
TestProperty = 321,
|
||||
ReferenceTypeArrayField = new TestReferenceType[2, 4][] {
|
||||
{
|
||||
null, null, null, null
|
||||
},
|
||||
{
|
||||
null, null, null,
|
||||
new TestReferenceType[3] {
|
||||
new TestReferenceType() { TestField = 101, TestProperty = 202 },
|
||||
null,
|
||||
new TestReferenceType() { TestField = 909, TestProperty = 808 }
|
||||
}
|
||||
},
|
||||
},
|
||||
ReferenceTypeArrayProperty = new TestReferenceType[2, 4][] {
|
||||
{
|
||||
null, null, null, null
|
||||
},
|
||||
{
|
||||
null, null, null,
|
||||
new TestReferenceType[3] {
|
||||
new TestReferenceType() { TestField = 303, TestProperty = 404 },
|
||||
null,
|
||||
new TestReferenceType() { TestField = 707, TestProperty = 606 }
|
||||
}
|
||||
},
|
||||
},
|
||||
ValueTypeField = new TestValueType() {
|
||||
TestField = 456,
|
||||
TestProperty = 654
|
||||
},
|
||||
ValueTypeProperty = new TestValueType() {
|
||||
TestField = 789,
|
||||
TestProperty = 987,
|
||||
},
|
||||
ReferenceTypeField = new TestReferenceType() {
|
||||
TestField = 135,
|
||||
TestProperty = 531
|
||||
},
|
||||
ReferenceTypeProperty = new TestReferenceType() {
|
||||
TestField = 246,
|
||||
TestProperty = 642,
|
||||
},
|
||||
DerivedField = new DerivedReferenceType() {
|
||||
DerivedField = 100,
|
||||
DerivedProperty = 200,
|
||||
TestField = 300,
|
||||
TestProperty = 400
|
||||
},
|
||||
DerivedProperty = new DerivedReferenceType() {
|
||||
DerivedField = 500,
|
||||
DerivedProperty = 600,
|
||||
TestField = 700,
|
||||
TestProperty = 800
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Creates a reference type with random data for testing</summary>
|
||||
/// <returns>A new reference type with random data</returns>
|
||||
protected static HierarchicalReferenceType CreateReferenceType() {
|
||||
return new HierarchicalReferenceType() {
|
||||
TestField = 123,
|
||||
TestProperty = 321,
|
||||
ReferenceTypeArrayField = new TestReferenceType[2, 4][] {
|
||||
{
|
||||
null, null, null, null
|
||||
},
|
||||
{
|
||||
null, null, null,
|
||||
new TestReferenceType[3] {
|
||||
new TestReferenceType() { TestField = 101, TestProperty = 202 },
|
||||
null,
|
||||
new TestReferenceType() { TestField = 909, TestProperty = 808 }
|
||||
}
|
||||
},
|
||||
},
|
||||
ReferenceTypeArrayProperty = new TestReferenceType[2, 4][] {
|
||||
{
|
||||
null, null, null, null
|
||||
},
|
||||
{
|
||||
null, null, null,
|
||||
new TestReferenceType[3] {
|
||||
new TestReferenceType() { TestField = 303, TestProperty = 404 },
|
||||
null,
|
||||
new TestReferenceType() { TestField = 707, TestProperty = 606 }
|
||||
}
|
||||
},
|
||||
},
|
||||
ValueTypeField = new TestValueType() {
|
||||
TestField = 456,
|
||||
TestProperty = 654
|
||||
},
|
||||
ValueTypeProperty = new TestValueType() {
|
||||
TestField = 789,
|
||||
TestProperty = 987,
|
||||
},
|
||||
ReferenceTypeField = new TestReferenceType() {
|
||||
TestField = 135,
|
||||
TestProperty = 531
|
||||
},
|
||||
ReferenceTypeProperty = new TestReferenceType() {
|
||||
TestField = 246,
|
||||
TestProperty = 642,
|
||||
},
|
||||
DerivedField = new DerivedReferenceType() {
|
||||
DerivedField = 100,
|
||||
DerivedProperty = 200,
|
||||
TestField = 300,
|
||||
TestProperty = 400
|
||||
},
|
||||
DerivedProperty = new DerivedReferenceType() {
|
||||
DerivedField = 500,
|
||||
DerivedProperty = 600,
|
||||
TestField = 700,
|
||||
TestProperty = 800
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Useless method that avoids a compile warnings due to unused fields
|
||||
/// </summary>
|
||||
protected void AvoidCompilerWarnings() {
|
||||
var reference = new HierarchicalReferenceType() {
|
||||
AlwaysNullField = new TestReferenceType()
|
||||
};
|
||||
var value = new HierarchicalValueType() {
|
||||
AlwaysNullField = new TestReferenceType()
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Cloning
|
|
@ -19,8 +19,6 @@ limitations under the License.
|
|||
|
||||
#if !NO_SETS
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -220,6 +218,4 @@ namespace Nuclex.Support.Cloning {
|
|||
|
||||
} // namespace Nuclex.Support.Cloning
|
||||
|
||||
#endif // UNITTEST
|
||||
|
||||
#endif // !NO_SETS
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -194,5 +192,3 @@ namespace Nuclex.Support.Cloning {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Cloning
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -141,5 +139,3 @@ namespace Nuclex.Support.Cloning {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Cloning
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
|
@ -48,5 +46,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@ -706,5 +704,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -21,8 +21,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
@ -132,5 +130,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -51,5 +49,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -53,5 +51,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -21,8 +21,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
@ -252,5 +250,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,13 +17,10 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
|
@ -386,5 +383,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,16 +17,12 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if !NO_NMOCK
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
using NMock;
|
||||
|
||||
using Moq;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
/// <summary>Unit Test for the observable collection class</summary>
|
||||
|
@ -65,35 +61,32 @@ namespace Nuclex.Support.Collections {
|
|||
/// <summary>Initialization routine executed before each test is run</summary>
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
this.mockery = new MockFactory();
|
||||
|
||||
this.mockedSubscriber = this.mockery.CreateMock<IObservableCollectionSubscriber>();
|
||||
this.mockedSubscriber = new Mock<IObservableCollectionSubscriber>();
|
||||
|
||||
this.observedCollection = new ObservableCollection<int>();
|
||||
this.observedCollection.Clearing += new EventHandler(
|
||||
this.mockedSubscriber.MockObject.Clearing
|
||||
this.mockedSubscriber.Object.Clearing
|
||||
);
|
||||
this.observedCollection.Cleared += new EventHandler(
|
||||
this.mockedSubscriber.MockObject.Cleared
|
||||
this.mockedSubscriber.Object.Cleared
|
||||
);
|
||||
this.observedCollection.ItemAdded += new EventHandler<ItemEventArgs<int>>(
|
||||
this.mockedSubscriber.MockObject.ItemAdded
|
||||
this.mockedSubscriber.Object.ItemAdded
|
||||
);
|
||||
this.observedCollection.ItemRemoved += new EventHandler<ItemEventArgs<int>>(
|
||||
this.mockedSubscriber.MockObject.ItemRemoved
|
||||
this.mockedSubscriber.Object.ItemRemoved
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Tests whether the Clearing event is fired</summary>
|
||||
[Test]
|
||||
public void TestClearingEvent() {
|
||||
this.mockedSubscriber.Expects.One.Method(m => m.Clearing(null, null)).WithAnyArguments();
|
||||
this.mockedSubscriber.Expects.One.Method(m => m.Cleared(null, null)).WithAnyArguments();
|
||||
this.observedCollection.Clear();
|
||||
|
||||
this.mockery.VerifyAllExpectationsHaveBeenMet();
|
||||
this.mockedSubscriber.Verify(c => c.Clearing(null, null), Times.Once);
|
||||
this.mockedSubscriber.Verify(c => c.Cleared(null, null), Times.Once);
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>Tests whether the ItemAdded event is fired</summary>
|
||||
[Test]
|
||||
public void TestItemAddedEvent() {
|
||||
|
@ -127,9 +120,7 @@ namespace Nuclex.Support.Collections {
|
|||
|
||||
CollectionAssert.AreEqual(integers, testCollection);
|
||||
}
|
||||
|
||||
/// <summary>Mock object factory</summary>
|
||||
private MockFactory mockery;
|
||||
*/
|
||||
/// <summary>The mocked observable collection subscriber</summary>
|
||||
private Mock<IObservableCollectionSubscriber> mockedSubscriber;
|
||||
/// <summary>An observable collection to which a mock will be subscribed</summary>
|
||||
|
@ -138,7 +129,3 @@ namespace Nuclex.Support.Collections {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
|
||||
#endif // UNITTEST
|
||||
|
||||
#endif // !NO_NMOCK
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
@ -557,5 +555,3 @@ namespace Nuclex.Support.IO {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.IO
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
@ -522,5 +520,3 @@ namespace Nuclex.Support.IO {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.IO
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -20,8 +20,6 @@ limitations under the License.
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.IO {
|
||||
|
@ -31,7 +29,7 @@ namespace Nuclex.Support.IO {
|
|||
internal class RingMemoryStreamTest {
|
||||
|
||||
/// <summary>Prepares some test data for the units test methods</summary>
|
||||
[TestFixtureSetUp]
|
||||
[OneTimeSetUp]
|
||||
public void Setup() {
|
||||
this.testBytes = new byte[20];
|
||||
for(int i = 0; i < 20; ++i)
|
||||
|
@ -325,5 +323,3 @@ namespace Nuclex.Support.IO {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.IO
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -20,8 +20,6 @@ limitations under the License.
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Licensing {
|
||||
|
@ -137,5 +135,3 @@ namespace Nuclex.Support.Licensing {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Licensing
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -19,8 +19,6 @@ limitations under the License.
|
|||
|
||||
using System;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Parsing {
|
||||
|
@ -653,5 +651,3 @@ namespace Nuclex.Support.Parsing {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Parsing
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
@ -228,5 +226,3 @@ namespace Nuclex.Support.Parsing {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Parsing
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -462,5 +460,3 @@ namespace Nuclex.Support.Settings {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Settings
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -160,5 +158,3 @@ namespace Nuclex.Support.Settings {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Settings
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST && WINDOWS
|
||||
#if WINDOWS
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -362,4 +362,4 @@ namespace Nuclex.Support.Settings {
|
|||
|
||||
} // namespace Nuclex.Support.Settings
|
||||
|
||||
#endif // UNITTEST
|
||||
#endif // WINDOWS
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
*/
|
||||
#endregion // Apache License 2.0
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -351,5 +349,3 @@ namespace Nuclex.Support.Threading {
|
|||
}
|
||||
|
||||
} // namespace Nuclex.Support.Threading
|
||||
|
||||
#endif // UNITTEST
|
||||
|
|
|
@ -23,8 +23,6 @@ using System;
|
|||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Threading {
|
||||
|
@ -252,6 +250,4 @@ namespace Nuclex.Support.Threading {
|
|||
|
||||
} // namespace Nuclex.Support.Threading
|
||||
|
||||
#endif // UNITTEST
|
||||
|
||||
#endif // !NO_CONCURRENT_COLLECTIONS
|
||||
|
|
|
@ -23,8 +23,6 @@ using System;
|
|||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITTEST
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Nuclex.Support.Threading {
|
||||
|
@ -454,6 +452,4 @@ namespace Nuclex.Support.Threading {
|
|||
|
||||
} // namespace Nuclex.Support.Threading
|
||||
|
||||
#endif // UNITTEST
|
||||
|
||||
#endif // !NO_CONCURRENT_COLLECTIONS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue