The issue here is that CollectionAssert.AreEqual() will be comparing the elements using Equals().
For reference types that do not override Equals(), that will do a reference comparison. This is not what you want.
Fortunately, you can work around this because CollectionAssert.AreEqual() has an overload that lets you specify a comparer.
Thus, all you need to do is create a comparer which returns zero if two of the elements are equal, and non-zero if they are not. This is slightly complicated by the fact that an ArrayList stores objects, so you need to cast to the right type to make the comparison.
(Note that this is somewhat of an abuse of IComparer since it is
supposed to return -ve, 0 or +ve to provide an ordered comparison of
the left and right hand sides. However, CollectionAssert.AreEqual()
only uses it to test for equality, so it is enough for us to return
zero or non-zero in our implementation.
The AreEqual() method would ideally use an
IEqualityComparer<T>
to compare the elements, but I think that postdates AreEqual() so it
wasn't available at the time that AreEqual() was written.)
Assuming that your elements are of type string[] (which you say they are) then you can create a comparer to compare the elements as follows:
var comparer = Comparer<object>.Create((a, b) => ((string[]) a).SequenceEqual((string[]) b) ? 0 : 1);
Then you can pass that comparer to AreEqual().
An example will make this clear:
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
list1.Add(Enumerable.Range( 0, 10).Select(n => n.ToString()).ToArray());
list1.Add(Enumerable.Range(10, 10).Select(n => n.ToString()).ToArray());
list1.Add(Enumerable.Range(20, 10).Select(n => n.ToString()).ToArray());
list2.Add(Enumerable.Range( 0, 10).Select(n => n.ToString()).ToArray());
list2.Add(Enumerable.Range(10, 10).Select(n => n.ToString()).ToArray());
list2.Add(Enumerable.Range(20, 10).Select(n => n.ToString()).ToArray());
var comparer = Comparer<object>.Create((a, b) => ((string[]) a).SequenceEqual((string[]) b) ? 0 : 1);
CollectionAssert.AreEqual(list1, list2, comparer);
This assert will succeed, but to prove that this will detect differences, change the last list2.Add() to list2.Add(Enumerable.Range(20, 9).Select(n => n.ToString()).ToArray()); and the assert will fail.
CollectionAssert.AreEquivalentwhich will check if the lists contain the same elements not considering their order.