/// <summary> /// Records any exception which is thrown by the given code. /// </summary> /// <param name="code">The code which may thrown an exception.</param> /// <returns>Returns the exception that was thrown by the code; null, otherwise.</returns> public static Exception Exception(CustomizeAssert.ThrowsDelegate code) { try { code(); return(null); } catch (Exception ex) { return(ex); } }
/// <summary>Verifies that the <paramref name="@delegate"/> throws the specified exception type.</summary> /// <typeparam name="T">The type of exception expected to be thrown.</typeparam> /// <param name="delegate">A <see cref="CustomizeAssert.ThrowsDelegate"/> which represents the action which should throw the exception.</param> /// <param name="exceptionChecker">Additional checks on the exception object.</param> public static void ShouldThrow <T>(this CustomizeAssert.ThrowsDelegate @delegate, Action <T> exceptionChecker = null) where T : Exception { var exception = CustomizeAssert.Throws <T>(@delegate); exceptionChecker?.Invoke(exception); }