2
// Copyright (C) 2002. James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. All Rights Reserved.
7
using System.Reflection;
10
/// Summary description for TestCase.
12
public abstract class TemplateTestCase : TestCase
14
private object fixture;
15
private MethodInfo method;
17
public TemplateTestCase(object fixture, MethodInfo method) : base(fixture.GetType().FullName, method.Name)
19
this.fixture = fixture;
23
public override void Run(TestCaseResult testResult)
27
DateTime start = DateTime.Now;
33
ProcessNoException(testResult);
35
catch(NunitException exception)
37
ProcessException(exception.InnerException, testResult);
41
ProcessException(exp, testResult);
49
catch(NunitException exception)
51
ProcessException(exception.InnerException, testResult);
55
ProcessException(exp, testResult);
58
DateTime stop = DateTime.Now;
59
TimeSpan span = stop.Subtract(start);
60
testResult.Time = (double)span.Ticks / (double)TimeSpan.TicksPerSecond;
65
testResult.NotRun(this.IgnoreReason);
71
private void InvokeTearDown()
73
MethodInfo method = FindTearDownMethod(fixture);
78
method.Invoke(fixture, null);
80
catch(TargetInvocationException e)
82
Exception inner = e.InnerException;
83
throw new NunitException("Rethrown",inner);
88
private MethodInfo FindTearDownMethod(object fixture)
90
return FindMethodByAttribute(fixture, typeof(Nunit.Framework.TearDownAttribute));
93
private void InvokeSetUp()
95
MethodInfo method = FindSetUpMethod(fixture);
100
method.Invoke(fixture, null);
102
catch(TargetInvocationException e)
104
Exception inner = e.InnerException;
105
throw new NunitException("Rethrown",inner);
110
private MethodInfo FindSetUpMethod(object fixture)
112
return FindMethodByAttribute(fixture, typeof(Nunit.Framework.SetUpAttribute));
115
private MethodInfo FindMethodByAttribute(object fixture, Type type)
117
foreach(MethodInfo method in fixture.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic))
119
if(method.IsDefined(type,true))
127
private void InvokeTestCase()
131
method.Invoke(fixture, null);
133
catch(TargetInvocationException e)
135
Exception inner = e.InnerException;
136
throw new NunitException("Rethrown",inner);
140
protected internal abstract void ProcessNoException(TestCaseResult testResult);
142
protected internal abstract void ProcessException(Exception exception, TestCaseResult testResult);