C# - Snippet, Expected exception snippet

Post date: Dec 19, 2013 3:21:49 PM

private bool ExpectedExceptionHappened<T>(Action testInAction, string testName) where T : Exception { bool exceptionHappened = false; try { testInAction(); } catch (T ex) { Console.WriteLine(ex.ToString()); exceptionHappened = true; } Assert.That(exceptionHappened, "Exception did not happen during test: " + testName); return exceptionHappened; }