Just Code‎ > ‎

C# - Snippet, Expected exception snippet

posted Dec 19, 2013, 7:21 AM by Peter Henell   [ updated Dec 19, 2013, 7:22 AM ]

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;
        }
Comments