~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/GuiException/tests/TestExceptionItem.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
// ****************************************************************
5
 
 
6
 
using System;
7
 
using NUnit.Framework;
8
 
using NUnit.UiException.Tests.data;
9
 
using System.IO;
10
 
 
11
 
namespace NUnit.UiException.Tests
12
 
{
13
 
    [TestFixture]
14
 
    public class TestErrorItem
15
 
    {
16
 
        [Test]
17
 
        [ExpectedException(typeof(ArgumentNullException),
18
 
            ExpectedMessage = "path",
19
 
            MatchType = MessageMatch.Contains)]
20
 
        public void Ctor_Throws_NullPathException()
21
 
        {
22
 
           new ErrorItem(null, 1); // throws exception
23
 
        }
24
 
 
25
 
        [Test]        
26
 
        public void Ctor_With_Line_0()
27
 
        {
28
 
            new ErrorItem("file.txt", 0);
29
 
        }
30
 
 
31
 
        [Test]
32
 
        public void Ctor_2()
33
 
        {
34
 
            ErrorItem item;
35
 
            
36
 
            item = new ErrorItem("Test.cs", "myFunction()", 1);
37
 
 
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"));
43
 
 
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);
50
 
 
51
 
            return;
52
 
        }
53
 
 
54
 
        [Test]
55
 
        public void Test_MethodName()
56
 
        {
57
 
            ErrorItem item;
58
 
 
59
 
            // test to pass
60
 
 
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"));
65
 
 
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"));
70
 
 
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"));                
75
 
 
76
 
            // test to fail
77
 
 
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(""));
82
 
 
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(""));
87
 
 
88
 
            return;
89
 
        }
90
 
 
91
 
        [Test]
92
 
        public void Can_Set_Properties()
93
 
        {
94
 
            ErrorItem item;
95
 
 
96
 
            item = new ErrorItem("/dir/file.txt", 13);
97
 
 
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);
103
 
 
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);
110
 
 
111
 
            return;
112
 
        }
113
 
 
114
 
        [Test]
115
 
        public void Test_FileExtension()
116
 
        {
117
 
            ErrorItem item;
118
 
 
119
 
            item = new ErrorItem("C:\\dir\\file.cs", 1);
120
 
            Assert.That(item.FileExtension, Is.EqualTo("cs"));
121
 
 
122
 
            item = new ErrorItem("C:\\dir\\file.cpp", 1);
123
 
            Assert.That(item.FileExtension, Is.EqualTo("cpp"));
124
 
 
125
 
            item = new ErrorItem("C:\\dir\\file.cs.cpp.plop", 1);
126
 
            Assert.That(item.FileExtension, Is.EqualTo("plop"));
127
 
 
128
 
            item = new ErrorItem("C:\\dir\\file.", 1);
129
 
            Assert.That(item.FileExtension, Is.Null);
130
 
 
131
 
            item = new ErrorItem("C:\\dir\\file", 1);
132
 
            Assert.That(item.FileExtension, Is.Null);
133
 
 
134
 
            return;
135
 
        }
136
 
 
137
 
        [Test]
138
 
        [ExpectedException(typeof(FileNotFoundException),
139
 
            ExpectedMessage = "unknown.txt",
140
 
            MatchType = MessageMatch.Contains)]
141
 
        public void ReadFile_Throws_FileNotExistException()
142
 
        {
143
 
            ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);
144
 
            item.ReadFile(); // throws exception
145
 
        }
146
 
 
147
 
        [Test]
148
 
        public void ReadFile()
149
 
        {
150
 
            ErrorItem item;
151
 
 
152
 
            using (TestResource resource = new TestResource("HelloWorld.txt"))
153
 
            {
154
 
                item = new ErrorItem(resource.Path, 1);
155
 
 
156
 
                Assert.That(item.ReadFile(), Is.Not.Null);
157
 
                Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
158
 
            }
159
 
 
160
 
            return;
161
 
        }        
162
 
 
163
 
        [Test]
164
 
        public void Test_Equals()
165
 
        {
166
 
            ErrorItem itemA;
167
 
            ErrorItem itemB;
168
 
            ErrorItem itemC;
169
 
 
170
 
            itemA = new ErrorItem("file1.txt", 43);
171
 
            itemB = new ErrorItem("file2.txt", 44);
172
 
            itemC = new ErrorItem("file1.txt", "myFunction()", 43);
173
 
 
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);
182
 
 
183
 
            return;
184
 
        }
185
 
    }
186
 
}
 
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
// ****************************************************************
 
5
 
 
6
using System;
 
7
using NUnit.Framework;
 
8
using NUnit.UiException.Tests.data;
 
9
using System.IO;
 
10
 
 
11
namespace NUnit.UiException.Tests
 
12
{
 
13
    [TestFixture]
 
14
    public class TestErrorItem
 
15
    {
 
16
        [Test]
 
17
        [ExpectedException(typeof(ArgumentNullException),
 
18
            ExpectedMessage = "path",
 
19
            MatchType = MessageMatch.Contains)]
 
20
        public void Ctor_Throws_NullPathException()
 
21
        {
 
22
           new ErrorItem(null, 1); // throws exception
 
23
        }
 
24
 
 
25
        [Test]        
 
26
        public void Ctor_With_Line_0()
 
27
        {
 
28
            new ErrorItem("file.txt", 0);
 
29
        }
 
30
 
 
31
        [Test]
 
32
        public void Ctor_2()
 
33
        {
 
34
            ErrorItem item;
 
35
            
 
36
            item = new ErrorItem("Test.cs", "myFunction()", 1);
 
37
 
 
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"));
 
43
 
 
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);
 
50
 
 
51
            return;
 
52
        }
 
53
 
 
54
        [Test]
 
55
        public void Test_MethodName()
 
56
        {
 
57
            ErrorItem item;
 
58
 
 
59
            // test to pass
 
60
 
 
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"));
 
65
 
 
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"));
 
70
 
 
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"));                
 
75
 
 
76
            // test to fail
 
77
 
 
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(""));
 
82
 
 
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(""));
 
87
 
 
88
            return;
 
89
        }
 
90
 
 
91
        [Test]
 
92
        public void Can_Set_Properties()
 
93
        {
 
94
            ErrorItem item;
 
95
 
 
96
            item = new ErrorItem("/dir/file.txt", 13);
 
97
 
 
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);
 
103
 
 
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);
 
110
 
 
111
            return;
 
112
        }
 
113
 
 
114
        [Test]
 
115
        public void Test_FileExtension()
 
116
        {
 
117
            ErrorItem item;
 
118
 
 
119
            item = new ErrorItem("C:\\dir\\file.cs", 1);
 
120
            Assert.That(item.FileExtension, Is.EqualTo("cs"));
 
121
 
 
122
            item = new ErrorItem("C:\\dir\\file.cpp", 1);
 
123
            Assert.That(item.FileExtension, Is.EqualTo("cpp"));
 
124
 
 
125
            item = new ErrorItem("C:\\dir\\file.cs.cpp.plop", 1);
 
126
            Assert.That(item.FileExtension, Is.EqualTo("plop"));
 
127
 
 
128
            item = new ErrorItem("C:\\dir\\file.", 1);
 
129
            Assert.That(item.FileExtension, Is.Null);
 
130
 
 
131
            item = new ErrorItem("C:\\dir\\file", 1);
 
132
            Assert.That(item.FileExtension, Is.Null);
 
133
 
 
134
            return;
 
135
        }
 
136
 
 
137
        [Test]
 
138
        [ExpectedException(typeof(FileNotFoundException),
 
139
            ExpectedMessage = "unknown.txt",
 
140
            MatchType = MessageMatch.Contains)]
 
141
        public void ReadFile_Throws_FileNotExistException()
 
142
        {
 
143
            ErrorItem item = new ErrorItem("C:\\unknown\\unknown.txt", 1);
 
144
            item.ReadFile(); // throws exception
 
145
        }
 
146
 
 
147
        [Test]
 
148
        public void ReadFile()
 
149
        {
 
150
            ErrorItem item;
 
151
 
 
152
            using (TestResource resource = new TestResource("HelloWorld.txt"))
 
153
            {
 
154
                item = new ErrorItem(resource.Path, 1);
 
155
 
 
156
                Assert.That(item.ReadFile(), Is.Not.Null);
 
157
                Assert.That(item.ReadFile(), Is.EqualTo("Hello world!"));
 
158
            }
 
159
 
 
160
            return;
 
161
        }        
 
162
 
 
163
        [Test]
 
164
        public void Test_Equals()
 
165
        {
 
166
            ErrorItem itemA;
 
167
            ErrorItem itemB;
 
168
            ErrorItem itemC;
 
169
 
 
170
            itemA = new ErrorItem("file1.txt", 43);
 
171
            itemB = new ErrorItem("file2.txt", 44);
 
172
            itemC = new ErrorItem("file1.txt", "myFunction()", 43);
 
173
 
 
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);
 
182
 
 
183
            return;
 
184
        }
 
185
    }
 
186
}