AssertEx.cs 392 B

12345678910111213141516171819202122
  1. using System;
  2. using NUnit.Framework;
  3. namespace MonoTests {
  4. static class AssertEx {
  5. static public T Throws<T> (Action code) where T : Exception
  6. {
  7. T exception = null;
  8. try {
  9. code ();
  10. } catch (T ex) {
  11. exception = ex;
  12. }
  13. Assert.IsNotNull (exception);
  14. // to check for exact type
  15. Assert.AreEqual(typeof(T), exception.GetType ());
  16. return exception;
  17. }
  18. }
  19. }