1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections;
\r
6 using System.Collections.Generic;
\r
7 using System.Collections.ObjectModel;
\r
8 using System.ComponentModel.Composition;
\r
11 using System.Reflection;
\r
13 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
15 namespace System.UnitTesting
\r
17 public static class TestUtilities
\r
20 public static void CheckICollectionOfTConformance<T>(ICollection<T> list, T a, T b, T c, T d)
\r
23 EnumerableAssert.AreEqual(list);
\r
25 Assert.IsFalse(list.IsReadOnly, "The list should not report being read-only for these tests to work");
\r
26 Assert.IsFalse(list.Contains(a), "Contains should fail for anything when the collection is empty");
\r
27 Assert.IsFalse(list.Remove(a), "Remove should fail on anything when the collection is empty");
\r
30 EnumerableAssert.AreEqual(list, a);
\r
33 EnumerableAssert.AreEqual(list, a, b);
\r
36 EnumerableAssert.AreEqual(list, a, b, c);
\r
39 EnumerableAssert.AreEqual(list, a, c);
\r
42 EnumerableAssert.AreEqual(list, a);
\r
45 EnumerableAssert.AreEqual(list);
\r
47 list.Add(a); list.Add(b); list.Add(c);
\r
50 EnumerableAssert.AreEqual(list);
\r
53 EnumerableAssert.AreEqual(list);
\r
55 list.Add(d); list.Add(c); list.Add(b); list.Add(a);
\r
57 T[] destination = new T[5];
\r
58 list.CopyTo(destination, 0);
\r
59 EnumerableAssert.AreEqual(destination, d, c, b, a, default(T));
\r
62 public static void CheckIListOfTConformance<T>(IList<T> list, T a, T b, T c, T d)
\r
64 CheckICollectionOfTConformance(list, a, b, c, d);
\r
71 CompareListContents(list, a, b, c, d);
\r
74 CompareListContents(list, a, a, c, d);
\r
77 CompareListContents(list, a, a, d);
\r
79 Assert.AreEqual(2, list.IndexOf(d), "Expected indexof to return the correct location of {0}", d);
\r
80 Assert.AreEqual(-1, list.IndexOf(b), "{0} should not be found in the collection", b);
\r
81 Assert.AreEqual(-1, list.IndexOf(c), "{0} should not be found in the collection", c);
\r
86 public static void CompareListContents<T>(IList<T> list, params object[] values)
\r
88 EnumerableAssert.AreEqual(list, values);
\r
90 for (var index = 0; index < values.Length; index++)
\r
92 Assert.AreEqual(values[index], list[index],
\r
93 "List should return true for Contains on every element, index {0}, length {1}", index, values[index]);
\r