예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public TestVerifyClause(ExceptionConfiguration exceptionConfiguration)
 {
     _exceptionConfiguration = exceptionConfiguration;
 }
예제 #8
0
 public TestVerifyClause(ExceptionConfiguration exceptionConfiguration)
 {
     _exceptionConfiguration = exceptionConfiguration;
 }