source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/lib/NUnit/NUnit-2.5.10.11092/samples/vb/syntax/AssertSyntaxTests.vb@ 1146

Last change on this file since 1146 was 1146, checked in by Sam Habiel, 13 years ago

Initial Import of BMX4

File size: 26.7 KB
Line 
1' ****************************************************************
2' Copyright 2007, Charlie Poole
3' This is free software licensed under the NUnit license. You may
4' obtain a copy of the license at http:'nunit.org/?p=license&r=2.4
5' ****************************************************************
6
7Option Explicit On
8
9Imports System
10Imports NUnit.Framework
11Imports NUnit.Framework.Constraints
12Imports Text = NUnit.Framework.Text
13
14Namespace NUnit.Samples
15
16 ' This test fixture attempts to exercise all the syntactic
17 ' variations of Assert without getting into failures, errors
18 ' or corner cases. Thus, some of the tests may be duplicated
19 ' in other fixtures.
20 '
21 ' Each test performs the same operations using the classic
22 ' syntax (if available) and the new syntax in both the
23 ' helper-based and inherited forms.
24 '
25 ' This Fixture will eventually be duplicated in other
26 ' supported languages.
27
28 <TestFixture()> _
29 Public Class AssertSyntaxTests
30 Inherits AssertionHelper
31
32#Region "Simple Constraint Tests"
33 <Test()> _
34 Public Sub IsNull()
35 Dim nada As Object = Nothing
36
37 ' Classic syntax
38 Assert.IsNull(nada)
39
40 ' Helper syntax
41 Assert.That(nada, Iz.Null)
42
43 ' Inherited syntax
44 Expect(nada, Null)
45 End Sub
46
47
48 <Test()> _
49 Public Sub IsNotNull()
50 ' Classic syntax
51 Assert.IsNotNull(42)
52
53 ' Helper syntax
54 Assert.That(42, Iz.Not.Null)
55
56 ' Inherited syntax
57 Expect(42, Iz.Not.Null)
58 End Sub
59
60 <Test()> _
61 Public Sub IsTrue()
62 ' Classic syntax
63 Assert.IsTrue(2 + 2 = 4)
64
65 ' Helper syntax
66 Assert.That(2 + 2 = 4, Iz.True)
67 Assert.That(2 + 2 = 4)
68
69 ' Inherited syntax
70 Expect(2 + 2 = 4, Iz.True)
71 Expect(2 + 2 = 4)
72 End Sub
73
74 <Test()> _
75 Public Sub IsFalse()
76 ' Classic syntax
77 Assert.IsFalse(2 + 2 = 5)
78
79 ' Helper syntax
80 Assert.That(2 + 2 = 5, Iz.False)
81
82 ' Inherited syntax
83 Expect(2 + 2 = 5, Iz.False)
84 End Sub
85
86 <Test()> _
87 Public Sub IsNaN()
88 Dim d As Double = Double.NaN
89 Dim f As Single = Single.NaN
90
91 ' Classic syntax
92 Assert.IsNaN(d)
93 Assert.IsNaN(f)
94
95 ' Helper syntax
96 Assert.That(d, Iz.NaN)
97 Assert.That(f, Iz.NaN)
98
99 ' Inherited syntax
100 Expect(d, NaN)
101 Expect(f, NaN)
102 End Sub
103
104 <Test()> _
105 Public Sub EmptyStringTests()
106 ' Classic syntax
107 Assert.IsEmpty("")
108 Assert.IsNotEmpty("Hello!")
109
110 ' Helper syntax
111 Assert.That("", Iz.Empty)
112 Assert.That("Hello!", Iz.Not.Empty)
113
114 ' Inherited syntax
115 Expect("", Empty)
116 Expect("Hello!", Iz.Not.Empty)
117 End Sub
118
119 <Test()> _
120 Public Sub EmptyCollectionTests()
121
122 Dim boolArray As Boolean() = New Boolean() {}
123 Dim nonEmpty As Integer() = New Integer() {1, 2, 3}
124
125 ' Classic syntax
126 Assert.IsEmpty(boolArray)
127 Assert.IsNotEmpty(nonEmpty)
128
129 ' Helper syntax
130 Assert.That(boolArray, Iz.Empty)
131 Assert.That(nonEmpty, Iz.Not.Empty)
132
133 ' Inherited syntax
134 Expect(boolArray, Iz.Empty)
135 Expect(nonEmpty, Iz.Not.Empty)
136 End Sub
137#End Region
138
139#Region "TypeConstraint Tests"
140 <Test()> _
141 Public Sub ExactTypeTests()
142 ' Classic syntax workarounds
143 Assert.AreEqual(GetType(String), "Hello".GetType())
144 Assert.AreEqual("System.String", "Hello".GetType().FullName)
145 Assert.AreNotEqual(GetType(Integer), "Hello".GetType())
146 Assert.AreNotEqual("System.Int32", "Hello".GetType().FullName)
147
148 ' Helper syntax
149 Assert.That("Hello", Iz.TypeOf(GetType(String)))
150 Assert.That("Hello", Iz.Not.TypeOf(GetType(Integer)))
151
152 ' Inherited syntax
153 Expect("Hello", Iz.TypeOf(GetType(String)))
154 Expect("Hello", Iz.Not.TypeOf(GetType(Integer)))
155 End Sub
156
157 <Test()> _
158 Public Sub InstanceOfTypeTests()
159 ' Classic syntax
160 Assert.IsInstanceOf(GetType(String), "Hello")
161 Assert.IsNotInstanceOf(GetType(String), 5)
162
163 ' Helper syntax
164 Assert.That("Hello", Iz.InstanceOf(GetType(String)))
165 Assert.That(5, Iz.Not.InstanceOf(GetType(String)))
166
167 ' Inherited syntax
168 Expect("Hello", InstanceOf(GetType(String)))
169 Expect(5, Iz.Not.InstanceOf(GetType(String)))
170 End Sub
171
172 <Test()> _
173 Public Sub AssignableFromTypeTests()
174 ' Classic syntax
175 Assert.IsAssignableFrom(GetType(String), "Hello")
176 Assert.IsNotAssignableFrom(GetType(String), 5)
177
178 ' Helper syntax
179 Assert.That("Hello", Iz.AssignableFrom(GetType(String)))
180 Assert.That(5, Iz.Not.AssignableFrom(GetType(String)))
181
182 ' Inherited syntax
183 Expect("Hello", AssignableFrom(GetType(String)))
184 Expect(5, Iz.Not.AssignableFrom(GetType(String)))
185 End Sub
186#End Region
187
188#Region "StringConstraintTests"
189 <Test()> _
190 Public Sub SubstringTests()
191 Dim phrase As String = "Hello World!"
192 Dim array As String() = New String() {"abc", "bad", "dba"}
193
194 ' Classic Syntax
195 StringAssert.Contains("World", phrase)
196
197 ' Helper syntax
198 Assert.That(phrase, Text.Contains("World"))
199 ' Only available using new syntax
200 Assert.That(phrase, Text.DoesNotContain("goodbye"))
201 Assert.That(phrase, Text.Contains("WORLD").IgnoreCase)
202 Assert.That(phrase, Text.DoesNotContain("BYE").IgnoreCase)
203 Assert.That(array, Text.All.Contains("b"))
204
205 ' Inherited syntax
206 Expect(phrase, Contains("World"))
207 ' Only available using new syntax
208 Expect(phrase, Text.DoesNotContain("goodbye"))
209 Expect(phrase, Contains("WORLD").IgnoreCase)
210 Expect(phrase, Text.DoesNotContain("BYE").IgnoreCase)
211 Expect(array, All.Contains("b"))
212 End Sub
213
214 <Test()> _
215 Public Sub StartsWithTests()
216 Dim phrase As String = "Hello World!"
217 Dim greetings As String() = New String() {"Hello!", "Hi!", "Hola!"}
218
219 ' Classic syntax
220 StringAssert.StartsWith("Hello", phrase)
221
222 ' Helper syntax
223 Assert.That(phrase, Text.StartsWith("Hello"))
224 ' Only available using new syntax
225 Assert.That(phrase, Text.DoesNotStartWith("Hi!"))
226 Assert.That(phrase, Text.StartsWith("HeLLo").IgnoreCase)
227 Assert.That(phrase, Text.DoesNotStartWith("HI").IgnoreCase)
228 Assert.That(greetings, Text.All.StartsWith("h").IgnoreCase)
229
230 ' Inherited syntax
231 Expect(phrase, StartsWith("Hello"))
232 ' Only available using new syntax
233 Expect(phrase, Text.DoesNotStartWith("Hi!"))
234 Expect(phrase, StartsWith("HeLLo").IgnoreCase)
235 Expect(phrase, Text.DoesNotStartWith("HI").IgnoreCase)
236 Expect(greetings, All.StartsWith("h").IgnoreCase)
237 End Sub
238
239 <Test()> _
240 Public Sub EndsWithTests()
241 Dim phrase As String = "Hello World!"
242 Dim greetings As String() = New String() {"Hello!", "Hi!", "Hola!"}
243
244 ' Classic Syntax
245 StringAssert.EndsWith("!", phrase)
246
247 ' Helper syntax
248 Assert.That(phrase, Text.EndsWith("!"))
249 ' Only available using new syntax
250 Assert.That(phrase, Text.DoesNotEndWith("?"))
251 Assert.That(phrase, Text.EndsWith("WORLD!").IgnoreCase)
252 Assert.That(greetings, Text.All.EndsWith("!"))
253
254 ' Inherited syntax
255 Expect(phrase, EndsWith("!"))
256 ' Only available using new syntax
257 Expect(phrase, Text.DoesNotEndWith("?"))
258 Expect(phrase, EndsWith("WORLD!").IgnoreCase)
259 Expect(greetings, All.EndsWith("!"))
260 End Sub
261
262 <Test()> _
263 Public Sub EqualIgnoringCaseTests()
264
265 Dim phrase As String = "Hello World!"
266 Dim array1 As String() = New String() {"Hello", "World"}
267 Dim array2 As String() = New String() {"HELLO", "WORLD"}
268 Dim array3 As String() = New String() {"HELLO", "Hello", "hello"}
269
270 ' Classic syntax
271 StringAssert.AreEqualIgnoringCase("hello world!", phrase)
272
273 ' Helper syntax
274 Assert.That(phrase, Iz.EqualTo("hello world!").IgnoreCase)
275 'Only available using new syntax
276 Assert.That(phrase, Iz.Not.EqualTo("goodbye world!").IgnoreCase)
277 Assert.That(array1, Iz.EqualTo(array2).IgnoreCase)
278 Assert.That(array3, Iz.All.EqualTo("hello").IgnoreCase)
279
280 ' Inherited syntax
281 Expect(phrase, EqualTo("hello world!").IgnoreCase)
282 'Only available using new syntax
283 Expect(phrase, Iz.Not.EqualTo("goodbye world!").IgnoreCase)
284 Expect(array1, EqualTo(array2).IgnoreCase)
285 Expect(array3, All.EqualTo("hello").IgnoreCase)
286 End Sub
287
288 <Test()> _
289 Public Sub RegularExpressionTests()
290 Dim phrase As String = "Now is the time for all good men to come to the aid of their country."
291 Dim quotes As String() = New String() {"Never say never", "It's never too late", "Nevermore!"}
292
293 ' Classic syntax
294 StringAssert.IsMatch("all good men", phrase)
295 StringAssert.IsMatch("Now.*come", phrase)
296
297 ' Helper syntax
298 Assert.That(phrase, Text.Matches("all good men"))
299 Assert.That(phrase, Text.Matches("Now.*come"))
300 ' Only available using new syntax
301 Assert.That(phrase, Text.DoesNotMatch("all.*men.*good"))
302 Assert.That(phrase, Text.Matches("ALL").IgnoreCase)
303 Assert.That(quotes, Text.All.Matches("never").IgnoreCase)
304
305 ' Inherited syntax
306 Expect(phrase, Matches("all good men"))
307 Expect(phrase, Matches("Now.*come"))
308 ' Only available using new syntax
309 Expect(phrase, Text.DoesNotMatch("all.*men.*good"))
310 Expect(phrase, Matches("ALL").IgnoreCase)
311 Expect(quotes, All.Matches("never").IgnoreCase)
312 End Sub
313#End Region
314
315#Region "Equality Tests"
316 <Test()> _
317 Public Sub EqualityTests()
318
319 Dim i3 As Integer() = {1, 2, 3}
320 Dim d3 As Double() = {1.0, 2.0, 3.0}
321 Dim iunequal As Integer() = {1, 3, 2}
322
323 ' Classic Syntax
324 Assert.AreEqual(4, 2 + 2)
325 Assert.AreEqual(i3, d3)
326 Assert.AreNotEqual(5, 2 + 2)
327 Assert.AreNotEqual(i3, iunequal)
328
329 ' Helper syntax
330 Assert.That(2 + 2, Iz.EqualTo(4))
331 Assert.That(2 + 2 = 4)
332 Assert.That(i3, Iz.EqualTo(d3))
333 Assert.That(2 + 2, Iz.Not.EqualTo(5))
334 Assert.That(i3, Iz.Not.EqualTo(iunequal))
335
336 ' Inherited syntax
337 Expect(2 + 2, EqualTo(4))
338 Expect(2 + 2 = 4)
339 Expect(i3, EqualTo(d3))
340 Expect(2 + 2, Iz.Not.EqualTo(5))
341 Expect(i3, Iz.Not.EqualTo(iunequal))
342 End Sub
343
344 <Test()> _
345 Public Sub EqualityTestsWithTolerance()
346 ' CLassic syntax
347 Assert.AreEqual(5.0R, 4.99R, 0.05R)
348 Assert.AreEqual(5.0F, 4.99F, 0.05F)
349
350 ' Helper syntax
351 Assert.That(4.99R, Iz.EqualTo(5.0R).Within(0.05R))
352 Assert.That(4D, Iz.Not.EqualTo(5D).Within(0.5D))
353 Assert.That(4.99F, Iz.EqualTo(5.0F).Within(0.05F))
354 Assert.That(4.99D, Iz.EqualTo(5D).Within(0.05D))
355 Assert.That(499, Iz.EqualTo(500).Within(5))
356 Assert.That(4999999999L, Iz.EqualTo(5000000000L).Within(5L))
357
358 ' Inherited syntax
359 Expect(4.99R, EqualTo(5.0R).Within(0.05R))
360 Expect(4D, Iz.Not.EqualTo(5D).Within(0.5D))
361 Expect(4.99F, EqualTo(5.0F).Within(0.05F))
362 Expect(4.99D, EqualTo(5D).Within(0.05D))
363 Expect(499, EqualTo(500).Within(5))
364 Expect(4999999999L, EqualTo(5000000000L).Within(5L))
365 End Sub
366
367 <Test()> _
368 Public Sub EqualityTestsWithTolerance_MixedFloatAndDouble()
369 ' Bug Fix 1743844
370 Assert.That(2.20492R, Iz.EqualTo(2.2R).Within(0.01F), _
371 "Double actual, Double expected, Single tolerance")
372 Assert.That(2.20492R, Iz.EqualTo(2.2F).Within(0.01R), _
373 "Double actual, Single expected, Double tolerance")
374 Assert.That(2.20492R, Iz.EqualTo(2.2F).Within(0.01F), _
375 "Double actual, Single expected, Single tolerance")
376 Assert.That(2.20492F, Iz.EqualTo(2.2F).Within(0.01R), _
377 "Single actual, Single expected, Double tolerance")
378 Assert.That(2.20492F, Iz.EqualTo(2.2R).Within(0.01R), _
379 "Single actual, Double expected, Double tolerance")
380 Assert.That(2.20492F, Iz.EqualTo(2.2R).Within(0.01F), _
381 "Single actual, Double expected, Single tolerance")
382 End Sub
383
384 <Test()> _
385 Public Sub EqualityTestsWithTolerance_MixingTypesGenerally()
386 ' Extending tolerance to all numeric types
387 Assert.That(202.0R, Iz.EqualTo(200.0R).Within(2), _
388 "Double actual, Double expected, int tolerance")
389 Assert.That(4.87D, Iz.EqualTo(5).Within(0.25R), _
390 "Decimal actual, int expected, Double tolerance")
391 Assert.That(4.87D, Iz.EqualTo(5L).Within(1), _
392 "Decimal actual, long expected, int tolerance")
393 Assert.That(487, Iz.EqualTo(500).Within(25), _
394 "int actual, int expected, int tolerance")
395 Assert.That(487L, Iz.EqualTo(500).Within(25), _
396 "long actual, int expected, int tolerance")
397 End Sub
398#End Region
399
400#Region "Comparison Tests"
401 <Test()> _
402 Public Sub ComparisonTests()
403 ' Classic Syntax
404 Assert.Greater(7, 3)
405 Assert.GreaterOrEqual(7, 3)
406 Assert.GreaterOrEqual(7, 7)
407
408 ' Helper syntax
409 Assert.That(7, Iz.GreaterThan(3))
410 Assert.That(7, Iz.GreaterThanOrEqualTo(3))
411 Assert.That(7, Iz.AtLeast(3))
412 Assert.That(7, Iz.GreaterThanOrEqualTo(7))
413 Assert.That(7, Iz.AtLeast(7))
414
415 ' Inherited syntax
416 Expect(7, GreaterThan(3))
417 Expect(7, GreaterThanOrEqualTo(3))
418 Expect(7, AtLeast(3))
419 Expect(7, GreaterThanOrEqualTo(7))
420 Expect(7, AtLeast(7))
421
422 ' Classic syntax
423 Assert.Less(3, 7)
424 Assert.LessOrEqual(3, 7)
425 Assert.LessOrEqual(3, 3)
426
427 ' Helper syntax
428 Assert.That(3, Iz.LessThan(7))
429 Assert.That(3, Iz.LessThanOrEqualTo(7))
430 Assert.That(3, Iz.AtMost(7))
431 Assert.That(3, Iz.LessThanOrEqualTo(3))
432 Assert.That(3, Iz.AtMost(3))
433
434 ' Inherited syntax
435 Expect(3, LessThan(7))
436 Expect(3, LessThanOrEqualTo(7))
437 Expect(3, AtMost(7))
438 Expect(3, LessThanOrEqualTo(3))
439 Expect(3, AtMost(3))
440 End Sub
441#End Region
442
443#Region "Collection Tests"
444 <Test()> _
445 Public Sub AllItemsTests()
446
447 Dim ints As Object() = {1, 2, 3, 4}
448 Dim doubles As Object() = {0.99, 2.1, 3.0, 4.05}
449 Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
450
451 ' Classic syntax
452 CollectionAssert.AllItemsAreNotNull(ints)
453 CollectionAssert.AllItemsAreInstancesOfType(ints, GetType(Integer))
454 CollectionAssert.AllItemsAreInstancesOfType(strings, GetType(String))
455 CollectionAssert.AllItemsAreUnique(ints)
456
457 ' Helper syntax
458 Assert.That(ints, Iz.All.Not.Null)
459 Assert.That(ints, Has.None.Null)
460 Assert.That(ints, Iz.All.InstanceOfType(GetType(Integer)))
461 Assert.That(ints, Has.All.InstanceOfType(GetType(Integer)))
462 Assert.That(strings, Iz.All.InstanceOfType(GetType(String)))
463 Assert.That(strings, Has.All.InstanceOfType(GetType(String)))
464 Assert.That(ints, Iz.Unique)
465 ' Only available using new syntax
466 Assert.That(strings, Iz.Not.Unique)
467 Assert.That(ints, Iz.All.GreaterThan(0))
468 Assert.That(ints, Has.All.GreaterThan(0))
469 Assert.That(ints, Has.None.LessThanOrEqualTo(0))
470 Assert.That(strings, Text.All.Contains("a"))
471 Assert.That(strings, Has.All.Contains("a"))
472 Assert.That(strings, Has.Some.StartsWith("ba"))
473 Assert.That(strings, Has.Some.Property("Length").EqualTo(3))
474 Assert.That(strings, Has.Some.StartsWith("BA").IgnoreCase)
475 Assert.That(doubles, Has.Some.EqualTo(1.0).Within(0.05))
476
477 ' Inherited syntax
478 Expect(ints, All.Not.Null)
479 Expect(ints, None.Null)
480 Expect(ints, All.InstanceOfType(GetType(Integer)))
481 Expect(strings, All.InstanceOfType(GetType(String)))
482 Expect(ints, Unique)
483 ' Only available using new syntax
484 Expect(strings, Iz.Not.Unique)
485 Expect(ints, All.GreaterThan(0))
486 Expect(strings, All.Contains("a"))
487 Expect(strings, Some.StartsWith("ba"))
488 Expect(strings, Some.StartsWith("BA").IgnoreCase)
489 Expect(doubles, Some.EqualTo(1.0).Within(0.05))
490 End Sub
491
492 <Test()> _
493 Public Sub SomeItemsTests()
494
495 Dim mixed As Object() = {1, 2, "3", Nothing, "four", 100}
496 Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
497
498 ' Not available using the classic syntax
499
500 ' Helper syntax
501 Assert.That(mixed, Has.Some.Null)
502 Assert.That(mixed, Has.Some.InstanceOfType(GetType(Integer)))
503 Assert.That(mixed, Has.Some.InstanceOfType(GetType(String)))
504 Assert.That(strings, Has.Some.StartsWith("ba"))
505 Assert.That(strings, Has.Some.Not.StartsWith("ba"))
506
507 ' Inherited syntax
508 Expect(mixed, Some.Null)
509 Expect(mixed, Some.InstanceOfType(GetType(Integer)))
510 Expect(mixed, Some.InstanceOfType(GetType(String)))
511 Expect(strings, Some.StartsWith("ba"))
512 Expect(strings, Some.Not.StartsWith("ba"))
513 End Sub
514
515 <Test()> _
516 Public Sub NoItemsTests()
517
518 Dim ints As Object() = {1, 2, 3, 4, 5}
519 Dim strings As Object() = {"abc", "bad", "cab", "bad", "dad"}
520
521 ' Not available using the classic syntax
522
523 ' Helper syntax
524 Assert.That(ints, Has.None.Null)
525 Assert.That(ints, Has.None.InstanceOfType(GetType(String)))
526 Assert.That(ints, Has.None.GreaterThan(99))
527 Assert.That(strings, Has.None.StartsWith("qu"))
528
529 ' Inherited syntax
530 Expect(ints, None.Null)
531 Expect(ints, None.InstanceOfType(GetType(String)))
532 Expect(ints, None.GreaterThan(99))
533 Expect(strings, None.StartsWith("qu"))
534 End Sub
535
536 <Test()> _
537 Public Sub CollectionContainsTests()
538
539 Dim iarray As Integer() = {1, 2, 3}
540 Dim sarray As String() = {"a", "b", "c"}
541
542 ' Classic syntax
543 Assert.Contains(3, iarray)
544 Assert.Contains("b", sarray)
545 CollectionAssert.Contains(iarray, 3)
546 CollectionAssert.Contains(sarray, "b")
547 CollectionAssert.DoesNotContain(sarray, "x")
548 ' Showing that Contains uses NUnit equality
549 CollectionAssert.Contains(iarray, 1.0R)
550
551 ' Helper syntax
552 Assert.That(iarray, Has.Member(3))
553 Assert.That(sarray, Has.Member("b"))
554 Assert.That(sarray, Has.No.Member("x"))
555 ' Showing that Contains uses NUnit equality
556 Assert.That(iarray, Has.Member(1.0R))
557
558 ' Only available using the new syntax
559 ' Note that EqualTo and SameAs do NOT give
560 ' identical results to Contains because
561 ' Contains uses Object.Equals()
562 Assert.That(iarray, Has.Some.EqualTo(3))
563 Assert.That(iarray, Has.Member(3))
564 Assert.That(sarray, Has.Some.EqualTo("b"))
565 Assert.That(sarray, Has.None.EqualTo("x"))
566 Assert.That(iarray, Has.None.SameAs(1.0R))
567 Assert.That(iarray, Has.All.LessThan(10))
568 Assert.That(sarray, Has.All.Length.EqualTo(1))
569 Assert.That(sarray, Has.None.Property("Length").GreaterThan(3))
570
571 ' Inherited syntax
572 Expect(iarray, Contains(3))
573 Expect(sarray, Contains("b"))
574 Expect(sarray, Has.No.Member("x"))
575
576 ' Only available using new syntax
577 ' Note that EqualTo and SameAs do NOT give
578 ' identical results to Contains because
579 ' Contains uses Object.Equals()
580 Expect(iarray, Some.EqualTo(3))
581 Expect(sarray, Some.EqualTo("b"))
582 Expect(sarray, None.EqualTo("x"))
583 Expect(iarray, All.LessThan(10))
584 Expect(sarray, All.Length.EqualTo(1))
585 Expect(sarray, None.Property("Length").GreaterThan(3))
586 End Sub
587
588 <Test()> _
589 Public Sub CollectionEquivalenceTests()
590
591 Dim ints1to5 As Integer() = {1, 2, 3, 4, 5}
592 Dim twothrees As Integer() = {1, 2, 3, 3, 4, 5}
593 Dim twofours As Integer() = {1, 2, 3, 4, 4, 5}
594
595 ' Classic syntax
596 CollectionAssert.AreEquivalent(New Integer() {2, 1, 4, 3, 5}, ints1to5)
597 CollectionAssert.AreNotEquivalent(New Integer() {2, 2, 4, 3, 5}, ints1to5)
598 CollectionAssert.AreNotEquivalent(New Integer() {2, 4, 3, 5}, ints1to5)
599 CollectionAssert.AreNotEquivalent(New Integer() {2, 2, 1, 1, 4, 3, 5}, ints1to5)
600 CollectionAssert.AreNotEquivalent(twothrees, twofours)
601
602 ' Helper syntax
603 Assert.That(New Integer() {2, 1, 4, 3, 5}, Iz.EquivalentTo(ints1to5))
604 Assert.That(New Integer() {2, 2, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
605 Assert.That(New Integer() {2, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
606 Assert.That(New Integer() {2, 2, 1, 1, 4, 3, 5}, Iz.Not.EquivalentTo(ints1to5))
607 Assert.That(twothrees, Iz.Not.EquivalentTo(twofours))
608
609 ' Inherited syntax
610 Expect(New Integer() {2, 1, 4, 3, 5}, EquivalentTo(ints1to5))
611 End Sub
612
613 <Test()> _
614 Public Sub SubsetTests()
615
616 Dim ints1to5 As Integer() = {1, 2, 3, 4, 5}
617
618 ' Classic syntax
619 CollectionAssert.IsSubsetOf(New Integer() {1, 3, 5}, ints1to5)
620 CollectionAssert.IsSubsetOf(New Integer() {1, 2, 3, 4, 5}, ints1to5)
621 CollectionAssert.IsNotSubsetOf(New Integer() {2, 4, 6}, ints1to5)
622 CollectionAssert.IsNotSubsetOf(New Integer() {1, 2, 2, 2, 5}, ints1to5)
623
624 ' Helper syntax
625 Assert.That(New Integer() {1, 3, 5}, Iz.SubsetOf(ints1to5))
626 Assert.That(New Integer() {1, 2, 3, 4, 5}, Iz.SubsetOf(ints1to5))
627 Assert.That(New Integer() {2, 4, 6}, Iz.Not.SubsetOf(ints1to5))
628
629 ' Inherited syntax
630 Expect(New Integer() {1, 3, 5}, SubsetOf(ints1to5))
631 Expect(New Integer() {1, 2, 3, 4, 5}, SubsetOf(ints1to5))
632 Expect(New Integer() {2, 4, 6}, Iz.Not.SubsetOf(ints1to5))
633 End Sub
634#End Region
635
636#Region "Property Tests"
637 <Test()> _
638 Public Sub PropertyTests()
639
640 Dim array As String() = {"abc", "bca", "xyz", "qrs"}
641 Dim array2 As String() = {"a", "ab", "abc"}
642 Dim list As New ArrayList(array)
643
644 ' Not available using the classic syntax
645
646 ' Helper syntax
647 ' Assert.That(list, Has.Property("Count"))
648 ' Assert.That(list, Has.No.Property("Length"))
649
650 Assert.That("Hello", Has.Length.EqualTo(5))
651 Assert.That("Hello", Has.Property("Length").EqualTo(5))
652 Assert.That("Hello", Has.Property("Length").GreaterThan(3))
653
654 Assert.That(array, Has.Property("Length").EqualTo(4))
655 Assert.That(array, Has.Length.EqualTo(4))
656 Assert.That(array, Has.Property("Length").LessThan(10))
657
658 Assert.That(array, Has.All.Property("Length").EqualTo(3))
659 Assert.That(array, Has.All.Length.EqualTo(3))
660 Assert.That(array, Iz.All.Length.EqualTo(3))
661 Assert.That(array, Has.All.Property("Length").EqualTo(3))
662 Assert.That(array, Iz.All.Property("Length").EqualTo(3))
663
664 Assert.That(array2, Iz.Not.Property("Length").EqualTo(4))
665 Assert.That(array2, Iz.Not.Length.EqualTo(4))
666 Assert.That(array2, Has.No.Property("Length").GreaterThan(3))
667
668 ' Inherited syntax
669 ' Expect(list, Has.Property("Count"))
670 ' Expect(list, Has.No.Property("Nada"))
671
672 Expect(array, All.Property("Length").EqualTo(3))
673 Expect(array, All.Length.EqualTo(3))
674 End Sub
675#End Region
676
677#Region "Not Tests"
678 <Test()> _
679 Public Sub NotTests()
680 ' Not available using the classic syntax
681
682 ' Helper syntax
683 Assert.That(42, Iz.Not.Null)
684 Assert.That(42, Iz.Not.True)
685 Assert.That(42, Iz.Not.False)
686 Assert.That(2.5, Iz.Not.NaN)
687 Assert.That(2 + 2, Iz.Not.EqualTo(3))
688 Assert.That(2 + 2, Iz.Not.Not.EqualTo(4))
689 Assert.That(2 + 2, Iz.Not.Not.Not.EqualTo(5))
690
691 ' Inherited syntax
692 Expect(42, Iz.Not.Null)
693 Expect(42, Iz.Not.True)
694 Expect(42, Iz.Not.False)
695 Expect(2.5, Iz.Not.NaN)
696 Expect(2 + 2, Iz.Not.EqualTo(3))
697 Expect(2 + 2, Iz.Not.Not.EqualTo(4))
698 Expect(2 + 2, Iz.Not.Not.Not.EqualTo(5))
699 End Sub
700#End Region
701
702 End Class
703
704End Namespace
705
Note: See TracBrowser for help on using the repository browser.