2010-03-17 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / nunit24 / NUnitCore / core / TestCase.cs
1 // ****************************************************************\r
2 // This is free software licensed under the NUnit license. You\r
3 // may obtain a copy of the license as well as information regarding\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.\r
5 // ****************************************************************\r
6 \r
7 namespace NUnit.Core\r
8 {\r
9         using System;\r
10         using System.Collections;\r
11         using System.Reflection;\r
12 \r
13         /// <summary>\r
14         /// The abstract TestCase class represents a single test case.\r
15         /// In the present implementation, the only derived class is\r
16         /// TestMethod, but we allow for future test cases which are\r
17         /// implemented in other ways.\r
18         /// </summary>\r
19         public abstract class TestCase : Test\r
20         {\r
21                 public TestCase( string path, string name ) : base( path, name ) { }\r
22 \r
23                 public TestCase( MethodInfo method ) : base ( method ) { }\r
24 \r
25                 public TestCase( TestName testName ) : base ( testName ) { }\r
26 \r
27                 public override int CountTestCases( ITestFilter filter ) \r
28                 {\r
29                         if (filter.Pass(this))\r
30                                 return 1;\r
31 \r
32                         return 0;\r
33                 }\r
34 \r
35                 protected virtual TestCaseResult MakeTestCaseResult()\r
36                 {\r
37                         return new TestCaseResult( new TestInfo(this) );\r
38                 }\r
39 \r
40                 public override TestResult Run(EventListener listener, ITestFilter filter)\r
41                 {\r
42                         return Run( listener ); // Ignore filter for now\r
43                 }\r
44 \r
45                 public override TestResult Run( EventListener listener )\r
46                 {\r
47                         using( new TestContext() )\r
48                         {\r
49                                 TestCaseResult testResult = MakeTestCaseResult();\r
50 \r
51                                 listener.TestStarted( this.TestName );\r
52                                 long startTime = DateTime.Now.Ticks;\r
53 \r
54                                 switch (this.RunState)\r
55                                 {\r
56                                         case RunState.Runnable:\r
57                                         case RunState.Explicit:\r
58                                                 Run(testResult);\r
59                                                 break;\r
60                                         case RunState.Skipped:\r
61                                                 testResult.Skip(IgnoreReason);\r
62                                                 break;\r
63                                         default:\r
64                                         case RunState.NotRunnable:\r
65                                         case RunState.Ignored:\r
66                                                 testResult.Ignore(IgnoreReason);\r
67                                                 break;\r
68                                 }\r
69 \r
70                                 long stopTime = DateTime.Now.Ticks;\r
71                                 double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;\r
72                                 testResult.Time = time;\r
73 \r
74                                 listener.TestFinished(testResult);\r
75                                 return testResult;\r
76                         }\r
77                 }\r
78 \r
79                 public override string TestType\r
80                 {\r
81                         get { return "Test Case"; }\r
82                 }\r
83 \r
84                 public override bool IsSuite\r
85                 {\r
86                         get { return false; }\r
87                 }\r
88 \r
89                 public override IList Tests\r
90                 {\r
91                         get { return null; }\r
92                 }\r
93 \r
94                 public abstract void Run(TestCaseResult result);\r
95         }\r
96 }\r