I have a class hierachy like this
public class A
{
protected class B
{
String Name { get; set; }
}
protected class C : KeyedCollection<String, B>
{
// ...
}
protected C Collection { get; }
// ...
public A Copy ()
{
// Creates a deep copy of this instance.
}
}
Now I'd like to write a unit test to compare if two instances of A have the same items B inside the property KeyedCollection. However, I'm not being able to perform a foreach loop into the A instances. What I had tried,
[TestClass]
public class TestClass
{
public void ATest()
{
A original = new A();
A copy = A.Copy();
// ...
A_Accessor originalAccessor = A_Accessor.AttachShadow(original);
A_Accessor copyAccessor = A_Accessor.AttachShadow(copy);
foreach(var originalItem in originalAccessor.Collection)
{
var copyItem = copyAccessor[originalItem.Name];
Assert.AreEqual(originalItem, copyItem);
}
}
}
This code doesn't even compile because the C class accessor doesn't implements the IEnumerable interface (it doesn't implement any interface from KeyedCollection class). Does anyone have an idea about how can I overcome this issue?
The error message I'm getting is
foreach statement cannot operate on variables of type 'C' because 'A_Accessor.C' does not contain a public definition for 'GetEnumerator'