2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / nunit20 / core / TestResult.cs
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright © 2000-2003 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright © 2000-2003 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 namespace NUnit.Core
31 {
32         using System;
33
34         /// <summary>
35         /// Summary description for TestResult.
36         /// </summary>
37         /// 
38         [Serializable]
39         public abstract class TestResult
40         {
41                 #region Fields
42
43                 /// <summary>
44                 /// True if the test executed
45                 /// </summary>
46                 private bool executed;
47
48                 /// <summary>
49                 /// True if the test was marked as a failure
50                 /// </summary>
51                 private bool isFailure; 
52
53                 /// <summary>
54                 /// True if the setup failed: This means SetUp for a test case,
55                 /// or TestFixtureSetUp for a fixture.
56                 /// </summary>
57                 private bool setupFailure;
58                 
59                 /// <summary>
60                 /// The elapsed time for executing this test
61                 /// </summary>
62                 private double time;
63
64                 /// <summary>
65                 /// The name of the test
66                 /// </summary>
67                 private string name;
68
69                 /// <summary>
70                 /// The test that this result pertains to
71                 /// </summary>
72                 private ITest test;
73
74                 /// <summary>
75                 /// The stacktrace at the point of failure
76                 /// </summary>
77                 private string stackTrace;
78
79                 /// <summary>
80                 /// Description of this test
81                 /// </summary>
82                 private string description;
83
84                 /// <summary>
85                 /// Message giving the reason for failure
86                 /// </summary>
87                 protected string messageString;
88
89                 /// <summary>
90                 /// Number of asserts executed by this test
91                 /// </summary>
92                 private int assertCount;
93
94                 #endregion
95
96                 #region Protected Constructor
97
98                 protected TestResult(ITest test, string name)
99                 {
100                         this.name = name;
101                         this.test = test;
102                         if(test != null)
103                                 this.description = test.Description;
104                 }
105
106                 #endregion
107
108                 #region Properties
109
110                 public bool Executed 
111                 {
112                         get { return executed; }
113                         set { executed = value; }
114                 }
115
116                 public virtual bool AllTestsExecuted
117                 {
118                         get { return executed; }
119                 }
120
121                 public virtual string Name
122                 {
123                         get{ return name;}
124                 }
125
126                 public ITest Test
127                 {
128                         get{ return test;}
129                 }
130
131                 public virtual bool IsSuccess
132                 {
133                         get { return !(isFailure); }
134                 }
135                 
136                 public virtual bool IsFailure
137                 {
138                         get { return isFailure; }
139                         set { isFailure = value; }
140                 }
141
142                 public bool SetupFailure
143                 {
144                         get { return setupFailure; }
145                         set { setupFailure = value; }
146                 }
147
148                 public virtual string Description
149                 {
150                         get { return description; }
151                         set { description = value; }
152                 }
153
154                 public double Time 
155                 {
156                         get{ return time; }
157                         set{ time = value; }
158                 }
159
160                 public string Message
161                 {
162                         get { return messageString; }
163                 }
164
165                 public virtual string StackTrace
166                 {
167                         get 
168                         { 
169                                 return stackTrace;
170                         }
171                         set 
172                         {
173                                 stackTrace = value;
174                         }
175                 }
176
177                 public int AssertCount
178                 {
179                         get { return assertCount; }
180                         set { assertCount = value; }
181                 }
182
183                 #endregion
184
185                 #region Public Methods
186
187                 public void NotRun(string reason)
188                 {
189                         this.executed = false;
190                         this.messageString = reason;
191                 }
192
193                 public void Failure(string message, string stackTrace )
194                 {
195                         Failure( message, stackTrace, false );
196                 }
197
198                 public void Failure(string message, string stackTrace, bool setupFailure)
199                 {
200                         this.executed = true;
201                         this.isFailure = true;
202                         this.messageString = message;
203                         this.stackTrace = stackTrace;
204                         this.setupFailure = setupFailure;
205                 }
206
207                 #endregion
208
209                 public abstract void Accept(ResultVisitor visitor);
210         }
211 }