2 using System.Collections.Generic;
6 namespace MonoTests.Common
8 delegate void AssertThrowsDelegate();
10 static class AssertExtensions
12 public static void AreEqual (byte[] expected, byte[] data, string message)
14 if (expected == null) {
17 Assert.Fail ("{0}{1}Expected: null{1}Got: byte array with {2} elements and of rank {3}{1}",
18 message, Environment.NewLine, data.Length, data.Rank);
22 Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: null{1}",
23 message, Environment.NewLine, expected.Length, expected.Rank);
25 if (expected.Rank > 1)
26 Assert.Fail ("Only single-dimensional arrays are supported.");
28 if (expected.Rank != data.Rank || expected.Length != data.Length)
29 Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: byte array with {4} elements and rank {5}{1}",
30 message, Environment.NewLine, expected.Length, expected.Rank, data.Length, data.Rank);
32 int max = expected.Length;
33 for (int i = 0; i < max; i++) {
34 if (expected[i] != data[i])
35 Assert.Fail ("{0}{1}Arrays differ at index {2}.{1}Expected 0x{3:X} got 0x{4:X}{1}",
36 message, Environment.NewLine, i, expected[i], data[i]);
40 public static void Throws<ET> (AssertThrowsDelegate code, string message)
42 Throws(typeof(ET), code, message);
45 public static void Throws(Type exceptionType, AssertThrowsDelegate code, string message)
48 Assert.Fail("No code provided for the test.");
50 Exception exception = null;
60 if (exceptionType == null)
62 if (exception == null)
63 Assert.Fail("{0}{1}Expected: any exception thrown{1}But was: no exception thrown{1}",
64 message, Environment.NewLine);
68 if (exception == null || exception.GetType() != exceptionType)
69 Assert.Fail("{0}{1}Expected: {2}{1}But was: {3}{1}{4}{1}",
73 exception == null ? "no exception" : exception.GetType().ToString(),
74 exception == null ? "no exception" : exception.ToString());
77 public static void Throws(AssertThrowsDelegate code, string message)
79 Throws(null, code, message);