1
#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2
/************************************************************************************
4
' Copyright � 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5
' Copyright � 2000-2003 Philip A. Craig
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
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:
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.
19
' Portions Copyright � 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20
' or Copyright � 2000-2003 Philip A. Craig
22
' 2. Altered source versions must be plainly marked as such, and must not be
23
' misrepresented as being the original software.
25
' 3. This notice may not be removed or altered from any source distribution.
27
'***********************************************************************************/
36
/// The TestResult abstract class represents
37
/// the result of a test and is used to
38
/// communicate results across AppDomains.
42
public abstract class TestResult
47
/// True if the test executed
49
private bool executed = false;
52
/// True if the test was marked as a failure
54
private bool isFailure = false;
57
/// The elapsed time for executing this test
59
private double time = 0.0;
62
/// The name of the test
67
/// The test that this result pertains to
69
private TestInfo test;
72
/// The stacktrace at the point of failure
74
private string stackTrace;
77
/// Description of this test
79
private string description;
82
/// Message giving the reason for failure
84
protected string messageString;
87
/// Number of asserts executed by this test
89
private int assertCount = 0;
93
#region Protected Constructor
94
protected TestResult(TestInfo test, string name)
99
this.description = test.Description;
107
get { return executed; }
108
set { executed = value; }
111
public virtual bool AllTestsExecuted
113
get { return executed; }
116
public virtual string Name
126
public virtual bool IsSuccess
128
get { return !(isFailure); }
131
public virtual bool IsFailure
133
get { return isFailure; }
134
set { isFailure = value; }
137
public virtual string Description
139
get { return description; }
140
set { description = value; }
149
public string Message
151
get { return messageString; }
154
public virtual string StackTrace
166
public int AssertCount
168
get { return assertCount; }
169
set { assertCount = value; }
174
#region Public Methods
177
/// Mark the test as not run.
179
/// <param name="reason">The reason the test was not run</param>
180
public void NotRun(string reason)
182
NotRun( reason, null );
186
/// Mark the test as not run.
188
/// <param name="reason">The reason the test was not run</param>
189
/// <param name="stackTrace">Stack trace giving the location of the command</param>
190
public void NotRun(string reason, string stackTrace)
192
this.executed = false;
193
this.messageString = reason;
194
this.stackTrace = stackTrace;
198
/// Mark the test as a failure due to an
199
/// assertion having failed.
201
/// <param name="message">Message to display</param>
202
/// <param name="stackTrace">Stack trace giving the location of the failure</param>
203
public void Failure(string message, string stackTrace )
205
this.executed = true;
206
this.isFailure = true;
207
this.messageString = message;
208
this.stackTrace = stackTrace;
213
#region Exception Helpers
215
private string BuildMessage(Exception exception)
217
StringBuilder sb = new StringBuilder();
218
sb.AppendFormat( "{0} : {1}", exception.GetType().ToString(), exception.Message );
220
Exception inner = exception.InnerException;
221
while( inner != null )
223
sb.Append( Environment.NewLine );
224
sb.AppendFormat( " ----> {0} : {1}", inner.GetType().ToString(), inner.Message );
225
inner = inner.InnerException;
228
return sb.ToString();
231
private string BuildStackTrace(Exception exception)
233
if(exception.InnerException!=null)
234
return GetStackTrace(exception) + Environment.NewLine +
235
"--" + exception.GetType().Name + Environment.NewLine +
236
BuildStackTrace(exception.InnerException);
238
return GetStackTrace(exception);
241
private string GetStackTrace(Exception exception)
245
return exception.StackTrace;
249
return "No stack trace available";
255
public abstract void Accept(ResultVisitor visitor);