1
// ****************************************************************
2
// This is free software licensed under the NUnit license. You may
3
// obtain a copy of the license at http://nunit.org
4
// ****************************************************************
7
using System.Collections.Generic;
11
namespace NUnit.UiException
14
/// (Formerly named ExceptionItem)
16
/// This is the output analysis of one error line coming from
17
/// a stack trace that still gathers the same data but in more
18
/// convenient way to be read from.
19
/// An ErrorItem represents one error with possible location
20
/// informations such as:
21
/// - filename where the error has occured
22
/// - file's line number
25
public class ErrorItem
28
/// An access path to the source file referred by this item.
33
/// The full qualified name of the member method referred by this item.
35
private string _fullyQualifiedMethodName;
38
/// The line index where the exception occured.
43
/// Store the content of the file pointed by _path.
48
/// Create an instance of ErrorItem that
49
/// has source code attachments.
51
public ErrorItem(string path, int lineNumber)
53
UiExceptionHelper.CheckNotNull(path, "path");
62
/// Create a new exception item.
64
/// <param name="path">An absolute path to the source code file.</param>
65
/// <param name="fullMethodName">A full qualified name of a member method.</param>
66
/// <param name="lineNumber">A line index where the exception occured.</param>
67
public ErrorItem(string path, string fullMethodName, int lineNumber)
70
_fullyQualifiedMethodName = fullMethodName;
77
/// Create an instance of ErrorItem that doesn't have
78
/// any source code attachments.
86
/// Reads and returns the part of Path that contains the filename
87
/// of the source code file.
89
public string FileName
91
get { return (System.IO.Path.GetFileName(_path)); }
95
/// Gets the absolute path to the source code file.
99
get { return (_path); }
103
/// Returns the file language - e.g.: the string after
104
/// the last dot or null -
106
public string FileExtension
115
dotIndex = _path.LastIndexOf(".", StringComparison.Ordinal);
116
if (dotIndex > -1 && dotIndex < _path.Length - 1)
117
return (_path.Substring(dotIndex + 1));
124
/// Gets the full qualified name of the member method.
126
public string FullyQualifiedMethodName
128
get { return (_fullyQualifiedMethodName); }
132
/// Reads and return the method part from the FullyQualifiedMethodName.
133
/// The value contains the signature of the method.
135
public string MethodName
141
if (FullyQualifiedMethodName == null)
144
if ((index = FullyQualifiedMethodName.LastIndexOf(".",
145
StringComparison.Ordinal)) == -1)
146
return (FullyQualifiedMethodName);
148
return (FullyQualifiedMethodName.Substring(index + 1));
153
/// Gets the method name without the argument list.
155
public string BaseMethodName
159
string method = MethodName;
160
int index = method.IndexOf("(", StringComparison.Ordinal);
163
return (method.Substring(0, index));
170
/// Reads and returns the class part from the FullyQualifiedMethodName.
172
public string ClassName
179
if (FullyQualifiedMethodName == null)
182
if ((end_index = FullyQualifiedMethodName.LastIndexOf(".",
183
StringComparison.Ordinal)) == -1)
186
start_index = end_index - 1;
187
while (start_index > 0 && FullyQualifiedMethodName[start_index] != '.')
190
if (start_index >= 0 && FullyQualifiedMethodName[start_index] == '.')
193
return (FullyQualifiedMethodName.Substring(start_index, end_index - start_index));
198
/// Gets the line number where the exception occured.
200
public int LineNumber
202
get { return (_line); }
206
/// Gets a boolean that says whether this item has source
207
/// code localization attachments.
209
public bool HasSourceAttachment {
210
get { return (_path != null); }
214
/// Read and return the content of the underlying file. If the file
215
/// cannot be found or read an exception is raised.
217
public string ReadFile()
219
if (!System.IO.File.Exists(_path))
220
throw new FileNotFoundException("File does not exist. File: " + _path);
224
StreamReader rder = new StreamReader(_path);
225
_text = rder.ReadToEnd();
232
public override string ToString() {
233
return ("TraceItem: {'" + _path + "', " + _fullyQualifiedMethodName + ", " + _line + "}");
236
public override bool Equals(object obj)
238
ErrorItem item = obj as ErrorItem;
243
return (_path == item._path &&
244
_fullyQualifiedMethodName == item._fullyQualifiedMethodName &&
245
_line == item._line);
248
public override int GetHashCode() {
249
return base.GetHashCode();
1
// ****************************************************************
2
// This is free software licensed under the NUnit license. You may
3
// obtain a copy of the license at http://nunit.org
4
// ****************************************************************
7
using System.Collections.Generic;
11
namespace NUnit.UiException
14
/// (Formerly named ExceptionItem)
16
/// This is the output analysis of one error line coming from
17
/// a stack trace that still gathers the same data but in more
18
/// convenient way to be read from.
19
/// An ErrorItem represents one error with possible location
20
/// informations such as:
21
/// - filename where the error has occured
22
/// - file's line number
25
public class ErrorItem
28
/// An access path to the source file referred by this item.
33
/// The full qualified name of the member method referred by this item.
35
private string _fullyQualifiedMethodName;
38
/// The line index where the exception occured.
43
/// Store the content of the file pointed by _path.
48
/// Create an instance of ErrorItem that
49
/// has source code attachments.
51
public ErrorItem(string path, int lineNumber)
53
UiExceptionHelper.CheckNotNull(path, "path");
62
/// Create a new exception item.
64
/// <param name="path">An absolute path to the source code file.</param>
65
/// <param name="fullMethodName">A full qualified name of a member method.</param>
66
/// <param name="lineNumber">A line index where the exception occured.</param>
67
public ErrorItem(string path, string fullMethodName, int lineNumber)
70
_fullyQualifiedMethodName = fullMethodName;
77
/// Create an instance of ErrorItem that doesn't have
78
/// any source code attachments.
86
/// Reads and returns the part of Path that contains the filename
87
/// of the source code file.
89
public string FileName
91
get { return (System.IO.Path.GetFileName(_path)); }
95
/// Gets the absolute path to the source code file.
99
get { return (_path); }
103
/// Returns the file language - e.g.: the string after
104
/// the last dot or null -
106
public string FileExtension
115
dotIndex = _path.LastIndexOf(".", StringComparison.Ordinal);
116
if (dotIndex > -1 && dotIndex < _path.Length - 1)
117
return (_path.Substring(dotIndex + 1));
124
/// Gets the full qualified name of the member method.
126
public string FullyQualifiedMethodName
128
get { return (_fullyQualifiedMethodName); }
132
/// Reads and return the method part from the FullyQualifiedMethodName.
133
/// The value contains the signature of the method.
135
public string MethodName
141
if (FullyQualifiedMethodName == null)
144
if ((index = FullyQualifiedMethodName.LastIndexOf(".",
145
StringComparison.Ordinal)) == -1)
146
return (FullyQualifiedMethodName);
148
return (FullyQualifiedMethodName.Substring(index + 1));
153
/// Gets the method name without the argument list.
155
public string BaseMethodName
159
string method = MethodName;
160
int index = method.IndexOf("(", StringComparison.Ordinal);
163
return (method.Substring(0, index));
170
/// Reads and returns the class part from the FullyQualifiedMethodName.
172
public string ClassName
179
if (FullyQualifiedMethodName == null)
182
if ((end_index = FullyQualifiedMethodName.LastIndexOf(".",
183
StringComparison.Ordinal)) == -1)
186
start_index = end_index - 1;
187
while (start_index > 0 && FullyQualifiedMethodName[start_index] != '.')
190
if (start_index >= 0 && FullyQualifiedMethodName[start_index] == '.')
193
return (FullyQualifiedMethodName.Substring(start_index, end_index - start_index));
198
/// Gets the line number where the exception occured.
200
public int LineNumber
202
get { return (_line); }
206
/// Gets a boolean that says whether this item has source
207
/// code localization attachments.
209
public bool HasSourceAttachment {
210
get { return (_path != null); }
214
/// Read and return the content of the underlying file. If the file
215
/// cannot be found or read an exception is raised.
217
public string ReadFile()
219
if (!System.IO.File.Exists(_path))
220
throw new FileNotFoundException("File does not exist. File: " + _path);
224
StreamReader rder = new StreamReader(_path);
225
_text = rder.ReadToEnd();
232
public override string ToString() {
233
return ("TraceItem: {'" + _path + "', " + _fullyQualifiedMethodName + ", " + _line + "}");
236
public override bool Equals(object obj)
238
ErrorItem item = obj as ErrorItem;
243
return (_path == item._path &&
244
_fullyQualifiedMethodName == item._fullyQualifiedMethodName &&
245
_line == item._line);
248
public override int GetHashCode() {
249
return base.GetHashCode();