public static void VerifyThrowsException <TExceptionType>(string expectedExceptionMessage, params Action[] actions) where TExceptionType : Exception { var exceptionConfiguration = new ExceptionConfiguration(typeof(TExceptionType), expectedExceptionMessage); try { new TestVerifyClause(exceptionConfiguration).Verify(actions); } catch (Exception e) { Exception result = null; bool succeeded = true; try { result = new ExceptionRewriter().RewriteStacktrace(e); } catch { succeeded = false; } if (!succeeded) { throw; } throw result; } }
public static void VerifyThrowsException <TExceptionType>(string expectedExceptionMessage, params Action[] actions) where TExceptionType : Exception { var exceptionConfiguration = new ExceptionConfiguration(typeof(TExceptionType), expectedExceptionMessage); try { new TestVerifyClause(exceptionConfiguration).Verify(actions); } catch (Exception e) { throw new AssertionException(e); } }
private void Verify(IEnumerable<ITestStep> steps, ExceptionConfiguration exceptionConfiguration) { var scenarioDescription = new StringBuilder(); foreach (var step in steps) { TestStepExecutor.Verify(scenarioDescription, step, exceptionConfiguration); } if (_exceptionConfiguration.ExpectException) { Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception of type {0} was not thrown.", _exceptionConfiguration.ExpectedExceptionType)); } }
private void Verify(IEnumerable <ITestStep> steps, ExceptionConfiguration exceptionConfiguration) { var scenarioDescription = new StringBuilder(); foreach (var step in steps) { TestStepExecutor.Verify(scenarioDescription, step, exceptionConfiguration); } if (_exceptionConfiguration.ExpectException) { Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception of type {0} was not thrown.", _exceptionConfiguration.ExpectedExceptionType)); } }
public static void Verify(StringBuilder scenarioDescription, ITestStep testStep, ExceptionConfiguration exceptionConfiguration) { scenarioDescription.Append(testStep.Description); try { testStep.Action(); scenarioDescription.AppendLine(testStep.SuccessSuffix); } catch (Exception e) { if (!exceptionConfiguration.ExpectException) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw; } var exceptionType = e.GetType(); if (exceptionType != exceptionConfiguration.ExpectedExceptionType) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception of type {0} but caught type {1}", exceptionConfiguration.ExpectedExceptionType, exceptionType), e); } if (exceptionConfiguration.ExpectExceptionMessage) { if (e.Message != exceptionConfiguration.ExpectedExceptionMessage) { scenarioDescription.AppendLine(testStep.FailureSuffix); Console.Error.WriteLine(scenarioDescription.ToString()); throw new AssertionException(String.Format("Expected exception message '{0}' but had '{1}'", exceptionConfiguration.ExpectedExceptionMessage, e.Message), e); } } exceptionConfiguration.CaughtExpectedException(); scenarioDescription.AppendLine(testStep.SuccessSuffix); } }
public TestVerifyClause(ExceptionConfiguration exceptionConfiguration) { _exceptionConfiguration = exceptionConfiguration; }