/// <summary> /// Asserts that the action does not throw an exception. /// </summary> /// <param name="action">The action.</param> public static void DoesNotThrow(Action action) { try { action(); } catch (Exception) { Assert.Fail("Expected no exception"); } }
/// <summary> /// Asserts that the action throws the specified exception. /// </summary> /// <typeparam name="T">The type of exception that is expected to be thrown.</typeparam> /// <param name="action">The action.</param> public static void Throws <T>(Action action) where T : Exception { try { action(); Assert.Fail(string.Format(CultureInfo.InvariantCulture, "Expected excpetion {0} did not occur!", typeof(T).Name)); } catch (T) { } }