* ConfigurationManagerTest.cs: Added/improved tests for
[mono.git] / mcs / class / System.Configuration / Test / standalone / Assert.cs
1 using System;
2 using System.Globalization;
3
4 class Assert
5 {
6         public static void AreEqual (string x, string y, string msg)
7         {
8                 if (x == null && y == null)
9                         return;
10                 if ((x == null || y == null) || !x.Equals (y))
11                         throw new Exception (string.Format (CultureInfo.InvariantCulture,
12                                 "Expected: {0}, but was: {1}. {2}",
13                                 x == null ? "<null>" : x, y == null ? "<null>" : y, msg));
14         }
15
16         public static void AreEqual (object x, object y, string msg)
17         {
18                 if (x == null && y == null)
19                         return;
20                 if ((x == null || y == null))
21                         throw new Exception (string.Format (CultureInfo.InvariantCulture,
22                                 "Expected: {0}, but was: {1}. {2}",
23                                 x == null ? "<null>" : x, y == null ? "<null>" : y, msg));
24
25                 bool isArrayX = x.GetType ().IsArray;
26                 bool isArrayY = y.GetType ().IsArray;
27
28                 if (isArrayX && isArrayY) {
29                         Array arrayX = (Array) x;
30                         Array arrayY = (Array) y;
31
32                         if (arrayX.Length != arrayY.Length)
33                                 throw new Exception (string.Format (CultureInfo.InvariantCulture,
34                                         "Length of arrays differs. Expected: {0}, but was: {1}. {2}",
35                                         arrayX.Length, arrayY.Length, msg));
36
37                         for (int i = 0; i < arrayX.Length; i++) {
38                                 object itemX = arrayX.GetValue (i);
39                                 object itemY = arrayY.GetValue (i);
40                                 if (!itemX.Equals (itemY))
41                                         throw new Exception (string.Format (CultureInfo.InvariantCulture,
42                                                 "Arrays differ at position {0}. Expected: {1}, but was: {2}. {3}",
43                                                 i, itemX, itemY, msg));
44                         }
45                 } else if (!x.Equals (y)) {
46                         throw new Exception (string.Format (CultureInfo.InvariantCulture,
47                                 "Expected: {0}, but was: {1}. {2}",
48                                 x, y, msg));
49                 }
50         }
51
52         public static void Fail (string msg)
53         {
54                 throw new Exception (msg);
55         }
56
57         public static void IsFalse (bool value, string msg)
58         {
59                 if (value)
60                         throw new Exception (msg);
61         }
62
63         public static void IsTrue (bool value, string msg)
64         {
65                 if (!value)
66                         throw new Exception (msg);
67         }
68
69         public static void IsNotNull (object value, string msg)
70         {
71                 if (value == null)
72                         throw new Exception (msg);
73         }
74
75         public static void IsNull (object value, string msg)
76         {
77                 if (value != null)
78                         throw new Exception (msg);
79         }
80
81         public static void AreSame (object x, object y, string msg)
82         {
83                 if (!object.ReferenceEquals (x, y))
84                         throw new Exception (msg);
85         }
86 }