Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.ComponentModel.Composition / Tests / ComponentModelUnitTest / System / UnitTesting / TestUtilities.cs
1 // -----------------------------------------------------------------------\r
2 // Copyright (c) Microsoft Corporation.  All rights reserved.\r
3 // -----------------------------------------------------------------------\r
4 using System;\r
5 using System.Collections;\r
6 using System.Collections.Generic;\r
7 using System.Collections.ObjectModel;\r
8 using System.ComponentModel.Composition;\r
9 using System.IO;\r
10 using System.Linq;\r
11 using System.Reflection;\r
12 \r
13 using Microsoft.VisualStudio.TestTools.UnitTesting;\r
14 \r
15 namespace System.UnitTesting\r
16 {\r
17     public static class TestUtilities\r
18     {\r
19 \r
20         public static void CheckICollectionOfTConformance<T>(ICollection<T> list, T a, T b, T c, T d)\r
21         {\r
22             list.Clear();\r
23             EnumerableAssert.AreEqual(list);\r
24 \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
28 \r
29             list.Add(a);\r
30             EnumerableAssert.AreEqual(list, a);\r
31 \r
32             list.Add(b);\r
33             EnumerableAssert.AreEqual(list, a, b);\r
34 \r
35             list.Add(c);\r
36             EnumerableAssert.AreEqual(list, a, b, c);\r
37 \r
38             list.Remove(b);\r
39             EnumerableAssert.AreEqual(list, a, c);\r
40 \r
41             list.Remove(c);\r
42             EnumerableAssert.AreEqual(list, a);\r
43 \r
44             list.Remove(a);\r
45             EnumerableAssert.AreEqual(list);\r
46 \r
47             list.Add(a); list.Add(b); list.Add(c);\r
48 \r
49             list.Clear();\r
50             EnumerableAssert.AreEqual(list);\r
51 \r
52             list.Clear();\r
53             EnumerableAssert.AreEqual(list);\r
54 \r
55             list.Add(d); list.Add(c); list.Add(b); list.Add(a);\r
56 \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
60         }\r
61 \r
62         public static void CheckIListOfTConformance<T>(IList<T> list, T a, T b, T c, T d)\r
63         {\r
64             CheckICollectionOfTConformance(list, a, b, c, d);\r
65 \r
66             list.Clear();\r
67             list.Insert(0, d);\r
68             list.Insert(0, a);\r
69             list.Insert(1, c);\r
70             list.Insert(1, b);\r
71             CompareListContents(list, a, b, c, d);\r
72 \r
73             list[1] = a;\r
74             CompareListContents(list, a, a, c, d);\r
75 \r
76             list.RemoveAt(2);\r
77             CompareListContents(list, a, a, d);\r
78 \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
82         }\r
83 \r
84         \r
85 \r
86         public static void CompareListContents<T>(IList<T> list, params object[] values)\r
87         {\r
88             EnumerableAssert.AreEqual(list, values);\r
89 \r
90             for (var index = 0; index < values.Length; index++)\r
91             {\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
94             }\r
95         }\r
96     }\r
97 }\r