2 using System.Collections.Generic;
6 namespace MonoTests.Common
8 delegate void AssertThrowsDelegate ();
10 static class AssertExtensions
12 public static void Throws<ET> (AssertThrowsDelegate code, string message)
14 Throws (typeof (ET), code, message);
17 public static void Throws (Type exceptionType, AssertThrowsDelegate code, string message)
20 Assert.Fail ("No code provided for the test.");
22 Exception exception = null;
25 } catch (Exception ex) {
29 if (exceptionType == null) {
30 if (exception == null)
31 Assert.Fail ("{0}{1}Expected: any exception thrown{1}But was: no exception thrown{1}",
32 message, Environment.NewLine);
36 if (exception == null || exception.GetType () != exceptionType)
37 Assert.Fail ("{0}{1}Expected: {2}{1}But was: {3}{1}{4}{1}",
41 exception == null ? "no exception" : exception.GetType ().ToString (),
42 exception == null ? "no exception" : exception.ToString ());
45 public static void Throws (AssertThrowsDelegate code, string message)
47 Throws (null, code, message);