Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. namespace  Microsoft.VisualStudio.TestTools.UnitTesting
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.  
  8.     public static class AssertEx
  9.     {
  10.  
  11.         /// <summary>
  12.         /// Verifies that the specified exception type is thrown.
  13.         /// </summary>
  14.         /// <typeparam name="TException">The type of the expected exception.</typeparam>
  15.         /// <param name="action">The action.</param>
  16.         public static void Throws<TException>(Action action) where TException: Exception
  17.         {        
  18.             try
  19.             {
  20.                 action();
  21.                 Assert.Fail("No expected '{0}' exception thrown.", typeof(TException));
  22.             }
  23.             catch (TException)
  24.             {
  25.                 // expected exception
  26.             }
  27.         }
  28.     }
  29. }