~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/NUnitFramework/core/ExpectedExceptionTestCase.cs

  • Committer: jnewkirk
  • Date: 2002-07-10 20:00:13 UTC
  • Revision ID: vcs-imports@canonical.com-20020710200013-j8us5mbi0usp7p02
initialĀ load

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (C) 2002. James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. All Rights Reserved.
 
3
//
 
4
namespace Nunit.Core
 
5
{
 
6
        using System;
 
7
        using System.Diagnostics;
 
8
        using System.Reflection;
 
9
 
 
10
        /// <summary>
 
11
        /// Summary description for ExpectedExceptionTestCase.
 
12
        /// </summary>
 
13
        public class ExpectedExceptionTestCase : TemplateTestCase
 
14
        {
 
15
                private Type expectedException;
 
16
 
 
17
                public ExpectedExceptionTestCase(object fixture, MethodInfo info, Type expectedException)
 
18
                        : base(fixture, info)
 
19
                {
 
20
                        this.expectedException = expectedException;
 
21
                }
 
22
 
 
23
                protected override internal void ProcessException(Exception exception, TestCaseResult testResult)
 
24
                {
 
25
                        if (expectedException.Equals(exception.GetType()))
 
26
                        {
 
27
                                testResult.Success();
 
28
                        }
 
29
                        else
 
30
                        {
 
31
                                string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name;
 
32
                                testResult.Failure(message, exception.StackTrace);
 
33
                        }
 
34
 
 
35
                        return;
 
36
                }
 
37
 
 
38
                protected override internal void ProcessNoException(TestCaseResult testResult)
 
39
                {
 
40
                        testResult.Failure(expectedException.Name + " was expected", null);
 
41
                }
 
42
        }
 
43
}