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
// ****************************************************************
8
using NUnit.UiException.Tests.data;
11
namespace NUnit.UiException.Tests
14
public class TestErrorItem
17
[ExpectedException(typeof(ArgumentNullException),
18
ExpectedMessage = "path",
19
MatchType = MessageMatch.Contains)]
20
public void Ctor_Throws_NullPathException()
22
new ErrorItem(null, 1); // throws exception
26
public void Ctor_With_Line_0()
28
new ErrorItem("file.txt", 0);
36
item = new ErrorItem("Test.cs", "myFunction()", 1);
38
Assert.That(item.Path, Is.EqualTo("Test.cs"));
39
Assert.That(item.FullyQualifiedMethodName, Is.EqualTo("myFunction()"));
40
Assert.That(item.LineNumber, Is.EqualTo(1));
41
Assert.That(item.HasSourceAttachment, Is.True);
42
Assert.That(item.FileExtension, Is.EqualTo("cs"));
44
item = new ErrorItem(null, "myFunction()", 1);
45
Assert.That(item.Path, Is.Null);
46
Assert.That(item.FileExtension, Is.Null);
47
Assert.That(item.FullyQualifiedMethodName, Is.EqualTo("myFunction()"));
48
Assert.That(item.LineNumber, Is.EqualTo(1));
49
Assert.That(item.HasSourceAttachment, Is.False);
55
public void Test_MethodName()
61
item = new ErrorItem("path", "namespace1.class.fullMethodName(string arg)", 1);
62
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
63
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
64
Assert.That(item.ClassName, Is.EqualTo("class"));
66
item = new ErrorItem("path", ".class.fullMethodName(string arg)", 1);
67
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
68
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
69
Assert.That(item.ClassName, Is.EqualTo("class"));
71
item = new ErrorItem("path", "0123456789012.a()", 1);
72
Assert.That(item.MethodName, Is.EqualTo("a()"));
73
Assert.That(item.BaseMethodName, Is.EqualTo("a"));
74
Assert.That(item.ClassName, Is.EqualTo("0123456789012"));
78
item = new ErrorItem("path", "fullMethodName(string arg)", 1);
79
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
80
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
81
Assert.That(item.ClassName, Is.EqualTo(""));
83
item = new ErrorItem("path", "", 1);
84
Assert.That(item.MethodName, Is.EqualTo(""));
85
Assert.That(item.BaseMethodName, Is.EqualTo(""));
86
Assert.That(item.ClassName, Is.EqualTo(""));
92
public void Can_Set_Properties()
96
item = new ErrorItem("/dir/file.txt", 13);
98
Assert.That(item.FileName, Is.EqualTo("file.txt"));
99
Assert.That(item.FileExtension, Is.EqualTo("txt"));
100
Assert.That(item.Path, Is.EqualTo("/dir/file.txt"));
101
Assert.That(item.LineNumber, Is.EqualTo(13));
102
Assert.That(item.HasSourceAttachment, Is.True);
104
item = new ErrorItem();
105
Assert.That(item.FileName, Is.Null);
106
Assert.That(item.FileExtension, Is.Null);
107
Assert.That(item.Path, Is.Null);
108
Assert.That(item.LineNumber, Is.EqualTo(0));
109
Assert.That(item.HasSourceAttachment, Is.False);
115
public void Test_FileExtension()
119
item = new ErrorItem("C:\\dir\\file.cs", 1);
120
Assert.That(item.FileExtension, Is.EqualTo("cs"));
122
item = new ErrorItem("C:\\dir\\file.cpp", 1);
123
Assert.That(item.FileExtension, Is.EqualTo("cpp"));
125
item = new ErrorItem("C:\\dir\\file.cs.cpp.plop", 1);
126
Assert.That(item.FileExtension, Is.EqualTo("plop"));
128
item = new ErrorItem("C:\\dir\\file.", 1);
129
Assert.That(item.FileExtension, Is.Null);
131
item = new ErrorItem("C:\\dir\\file", 1);
132
Assert.That(item.FileExtension, Is.Null);
138
[ExpectedException(typeof(FileNotFoundException),
139
ExpectedMessage = "unknown.txt",
140
MatchType = MessageMatch.Contains)]
141
public void ReadFile_Throws_FileNotExistException()
143
ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);
144
item.ReadFile(); // throws exception
148
public void ReadFile()
152
using (TestResource resource = new TestResource("HelloWorld.txt"))
154
item = new ErrorItem(resource.Path, 1);
156
Assert.That(item.ReadFile(), Is.Not.Null);
157
Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
164
public void Test_Equals()
170
itemA = new ErrorItem("file1.txt", 43);
171
itemB = new ErrorItem("file2.txt", 44);
172
itemC = new ErrorItem("file1.txt", "myFunction()", 43);
174
Assert.That(itemA.Equals(null), Is.False);
175
Assert.That(itemA.Equals("hello"), Is.False);
176
Assert.That(itemA.Equals(itemB), Is.False);
177
Assert.That(itemA.Equals(itemC), Is.False);
178
Assert.That(itemA.Equals(itemA), Is.True);
179
Assert.That(itemA.Equals(new ErrorItem("file", 43)), Is.False);
180
Assert.That(itemA.Equals(new ErrorItem("file1.txt", 42)), Is.False);
181
Assert.That(itemA.Equals(new ErrorItem("file1.txt", 43)), Is.True);
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
// ****************************************************************
8
using NUnit.UiException.Tests.data;
11
namespace NUnit.UiException.Tests
14
public class TestErrorItem
17
[ExpectedException(typeof(ArgumentNullException),
18
ExpectedMessage = "path",
19
MatchType = MessageMatch.Contains)]
20
public void Ctor_Throws_NullPathException()
22
new ErrorItem(null, 1); // throws exception
26
public void Ctor_With_Line_0()
28
new ErrorItem("file.txt", 0);
36
item = new ErrorItem("Test.cs", "myFunction()", 1);
38
Assert.That(item.Path, Is.EqualTo("Test.cs"));
39
Assert.That(item.FullyQualifiedMethodName, Is.EqualTo("myFunction()"));
40
Assert.That(item.LineNumber, Is.EqualTo(1));
41
Assert.That(item.HasSourceAttachment, Is.True);
42
Assert.That(item.FileExtension, Is.EqualTo("cs"));
44
item = new ErrorItem(null, "myFunction()", 1);
45
Assert.That(item.Path, Is.Null);
46
Assert.That(item.FileExtension, Is.Null);
47
Assert.That(item.FullyQualifiedMethodName, Is.EqualTo("myFunction()"));
48
Assert.That(item.LineNumber, Is.EqualTo(1));
49
Assert.That(item.HasSourceAttachment, Is.False);
55
public void Test_MethodName()
61
item = new ErrorItem("path", "namespace1.class.fullMethodName(string arg)", 1);
62
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
63
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
64
Assert.That(item.ClassName, Is.EqualTo("class"));
66
item = new ErrorItem("path", ".class.fullMethodName(string arg)", 1);
67
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
68
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
69
Assert.That(item.ClassName, Is.EqualTo("class"));
71
item = new ErrorItem("path", "0123456789012.a()", 1);
72
Assert.That(item.MethodName, Is.EqualTo("a()"));
73
Assert.That(item.BaseMethodName, Is.EqualTo("a"));
74
Assert.That(item.ClassName, Is.EqualTo("0123456789012"));
78
item = new ErrorItem("path", "fullMethodName(string arg)", 1);
79
Assert.That(item.MethodName, Is.EqualTo("fullMethodName(string arg)"));
80
Assert.That(item.BaseMethodName, Is.EqualTo("fullMethodName"));
81
Assert.That(item.ClassName, Is.EqualTo(""));
83
item = new ErrorItem("path", "", 1);
84
Assert.That(item.MethodName, Is.EqualTo(""));
85
Assert.That(item.BaseMethodName, Is.EqualTo(""));
86
Assert.That(item.ClassName, Is.EqualTo(""));
92
public void Can_Set_Properties()
96
item = new ErrorItem("/dir/file.txt", 13);
98
Assert.That(item.FileName, Is.EqualTo("file.txt"));
99
Assert.That(item.FileExtension, Is.EqualTo("txt"));
100
Assert.That(item.Path, Is.EqualTo("/dir/file.txt"));
101
Assert.That(item.LineNumber, Is.EqualTo(13));
102
Assert.That(item.HasSourceAttachment, Is.True);
104
item = new ErrorItem();
105
Assert.That(item.FileName, Is.Null);
106
Assert.That(item.FileExtension, Is.Null);
107
Assert.That(item.Path, Is.Null);
108
Assert.That(item.LineNumber, Is.EqualTo(0));
109
Assert.That(item.HasSourceAttachment, Is.False);
115
public void Test_FileExtension()
119
item = new ErrorItem("C:\\dir\\file.cs", 1);
120
Assert.That(item.FileExtension, Is.EqualTo("cs"));
122
item = new ErrorItem("C:\\dir\\file.cpp", 1);
123
Assert.That(item.FileExtension, Is.EqualTo("cpp"));
125
item = new ErrorItem("C:\\dir\\file.cs.cpp.plop", 1);
126
Assert.That(item.FileExtension, Is.EqualTo("plop"));
128
item = new ErrorItem("C:\\dir\\file.", 1);
129
Assert.That(item.FileExtension, Is.Null);
131
item = new ErrorItem("C:\\dir\\file", 1);
132
Assert.That(item.FileExtension, Is.Null);
138
[ExpectedException(typeof(FileNotFoundException),
139
ExpectedMessage = "unknown.txt",
140
MatchType = MessageMatch.Contains)]
141
public void ReadFile_Throws_FileNotExistException()
143
ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);
144
item.ReadFile(); // throws exception
148
public void ReadFile()
152
using (TestResource resource = new TestResource("HelloWorld.txt"))
154
item = new ErrorItem(resource.Path, 1);
156
Assert.That(item.ReadFile(), Is.Not.Null);
157
Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
164
public void Test_Equals()
170
itemA = new ErrorItem("file1.txt", 43);
171
itemB = new ErrorItem("file2.txt", 44);
172
itemC = new ErrorItem("file1.txt", "myFunction()", 43);
174
Assert.That(itemA.Equals(null), Is.False);
175
Assert.That(itemA.Equals("hello"), Is.False);
176
Assert.That(itemA.Equals(itemB), Is.False);
177
Assert.That(itemA.Equals(itemC), Is.False);
178
Assert.That(itemA.Equals(itemA), Is.True);
179
Assert.That(itemA.Equals(new ErrorItem("file", 43)), Is.False);
180
Assert.That(itemA.Equals(new ErrorItem("file1.txt", 42)), Is.False);
181
Assert.That(itemA.Equals(new ErrorItem("file1.txt", 43)), Is.True);