2 using System.Globalization;
6 public static void AreEqual (string x, string y, string msg)
8 if (x == null && y == null)
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));
16 public static void AreEqual (object x, object y, string msg)
18 if (x == null && y == null)
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));
25 bool isArrayX = x.GetType ().IsArray;
26 bool isArrayY = y.GetType ().IsArray;
28 if (isArrayX && isArrayY) {
29 Array arrayX = (Array) x;
30 Array arrayY = (Array) y;
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));
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));
45 } else if (!x.Equals (y)) {
46 throw new Exception (string.Format (CultureInfo.InvariantCulture,
47 "Expected: {0}, but was: {1}. {2}",
52 public static void Fail (string msg)
54 throw new Exception (msg);
57 public static void IsFalse (bool value, string msg)
60 throw new Exception (msg);
63 public static void IsTrue (bool value, string msg)
66 throw new Exception (msg);
69 public static void IsNotNull (object value, string msg)
72 throw new Exception (msg);
75 public static void IsNull (object value, string msg)
78 throw new Exception (msg);
81 public static void AreSame (object x, object y, string msg)
83 if (!object.ReferenceEquals (x, y))
84 throw new Exception (msg);