1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
// ****************************************************************
// Copyright 2009, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org
// ****************************************************************
using System;
using System.Collections;
#if NET_2_0
using System.Collections.Generic;
#endif
using NUnit.Framework.Tests;
namespace NUnit.Framework.Syntax
{
public class UniqueTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<uniqueitems>";
staticSyntax = Is.Unique;
inheritedSyntax = Helper().Unique;
builderSyntax = Builder().Unique;
}
}
public class CollectionOrderedTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<ordered>";
staticSyntax = Is.Ordered;
inheritedSyntax = Helper().Ordered;
builderSyntax = Builder().Ordered;
}
}
public class CollectionOrderedTest_Descending : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<ordered descending>";
staticSyntax = Is.Ordered.Descending;
inheritedSyntax = Helper().Ordered.Descending;
builderSyntax = Builder().Ordered.Descending;
}
}
public class CollectionOrderedTest_Comparer : SyntaxTest
{
[SetUp]
public void SetUp()
{
IComparer comparer = Comparer.Default;
parseTree = "<ordered System.Collections.Comparer>";
staticSyntax = Is.Ordered.Using(comparer);
inheritedSyntax = Helper().Ordered.Using(comparer);
builderSyntax = Builder().Ordered.Using(comparer);
}
}
public class CollectionOrderedTest_Comparer_Descending : SyntaxTest
{
[SetUp]
public void SetUp()
{
IComparer comparer = Comparer.Default;
parseTree = "<ordered descending System.Collections.Comparer>";
staticSyntax = Is.Ordered.Using(comparer).Descending;
inheritedSyntax = Helper().Ordered.Using(comparer).Descending;
builderSyntax = Builder().Ordered.Using(comparer).Descending;
}
}
public class CollectionOrderedByTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<orderedby SomePropertyName>";
staticSyntax = Is.Ordered.By("SomePropertyName");
inheritedSyntax = Helper().Ordered.By("SomePropertyName");
builderSyntax = Builder().Ordered.By("SomePropertyName");
}
}
public class CollectionOrderedByTest_Descending : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<orderedby SomePropertyName descending>";
staticSyntax = Is.Ordered.By("SomePropertyName").Descending;
inheritedSyntax = Helper().Ordered.By("SomePropertyName").Descending;
builderSyntax = Builder().Ordered.By("SomePropertyName").Descending;
}
}
public class CollectionOrderedByTest_Comparer : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<orderedby SomePropertyName System.Collections.Comparer>";
staticSyntax = Is.Ordered.By("SomePropertyName").Using(Comparer.Default);
inheritedSyntax = Helper().Ordered.By("SomePropertyName").Using(Comparer.Default);
builderSyntax = Builder().Ordered.By("SomePropertyName").Using(Comparer.Default);
}
}
public class CollectionOrderedByTest_Comparer_Descending : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<orderedby SomePropertyName descending System.Collections.Comparer>";
staticSyntax = Is.Ordered.By("SomePropertyName").Using(Comparer.Default).Descending;
inheritedSyntax = Helper().Ordered.By("SomePropertyName").Using(Comparer.Default).Descending;
builderSyntax = Builder().Ordered.By("SomePropertyName").Using(Comparer.Default).Descending;
}
}
public class CollectionContainsTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains 42>";
staticSyntax = Contains.Item(42);
inheritedSyntax = Helper().Contains(42);
builderSyntax = Builder().Contains(42);
}
}
public class CollectionContainsTest_String : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains \"abc\">";
staticSyntax = Contains.Item("abc");
inheritedSyntax = Helper().Contains("abc");
builderSyntax = Builder().Contains("abc");
}
}
public class CollectionContainsTest_Comparer : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains 42>";
staticSyntax = Contains.Item(42).Using(Comparer.Default);
inheritedSyntax = Helper().Contains(42).Using(Comparer.Default);
builderSyntax = Builder().Contains(42).Using(Comparer.Default);
}
[Test]
public void ComparerIsCalled()
{
TestComparer comparer = new TestComparer();
Assert.That(new int[] { 1, 2, 3 },
Contains.Item(2).Using(comparer));
Assert.That(comparer.Called, "Comparer was not called");
}
[Test]
public void ComparerIsCalledInExpression()
{
TestComparer comparer = new TestComparer();
Assert.That(new int[] { 1, 2, 3 },
Has.Length.EqualTo(3).And.Contains(2).Using(comparer));
Assert.That(comparer.Called, "Comparer was not called");
}
}
public class CollectionContainsTest_Comparer_String : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains \"abc\">";
staticSyntax = Contains.Item("abc").Using(Comparer.Default);
inheritedSyntax = Helper().Contains("abc").Using(Comparer.Default);
builderSyntax = Builder().Contains("abc").Using(Comparer.Default);
}
[Test]
public void ComparerIsCalled()
{
TestComparer comparer = new TestComparer();
Assert.That(new string[] { "Hello", "World" },
Contains.Item("World").Using(comparer));
Assert.That(comparer.Called, "Comparer was not called");
}
[Test]
public void ComparerIsCalledInExpression()
{
TestComparer comparer = new TestComparer();
Assert.That(new string[] { "Hello", "World" },
Has.Length.EqualTo(2).And.Contains("World").Using(comparer));
Assert.That(comparer.Called, "Comparer was not called");
}
}
public class CollectionMemberTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains 42>";
staticSyntax = Has.Member(42);
inheritedSyntax = Helper().Contains(42);
builderSyntax = Builder().Contains(42);
}
}
public class CollectionMemberTest_Comparer : SyntaxTest
{
[SetUp]
public void SetUp()
{
parseTree = "<contains 42>";
staticSyntax = Has.Member(42).Using(Comparer.Default);
inheritedSyntax = Helper().Contains(42).Using(Comparer.Default);
builderSyntax = Builder().Contains(42).Using(Comparer.Default);
}
}
public class CollectionSubsetTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
int[] ints = new int[] { 1, 2, 3 };
parseTree = "<subsetof System.Int32[]>";
staticSyntax = Is.SubsetOf(ints);
inheritedSyntax = Helper().SubsetOf(ints);
builderSyntax = Builder().SubsetOf(ints);
}
}
public class CollectionEquivalentTest : SyntaxTest
{
[SetUp]
public void SetUp()
{
int[] ints = new int[] { 1, 2, 3 };
parseTree = "<equivalent System.Int32[]>";
staticSyntax = Is.EquivalentTo(ints);
inheritedSyntax = Helper().EquivalentTo(ints);
builderSyntax = Builder().EquivalentTo(ints);
}
}
}
|