OLD | NEW |
| (Empty) |
1 /* | |
2 Copyright 2010 Google Inc | |
3 | |
4 Licensed under the Apache License, Version 2.0 (the "License"); | |
5 you may not use this file except in compliance with the License. | |
6 You may obtain a copy of the License at | |
7 | |
8 http://www.apache.org/licenses/LICENSE-2.0 | |
9 | |
10 Unless required by applicable law or agreed to in writing, software | |
11 distributed under the License is distributed on an "AS IS" BASIS, | |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 See the License for the specific language governing permissions and | |
14 limitations under the License. | |
15 */ | |
16 | |
17 using System.Collections; | |
18 using System.Collections.Generic; | |
19 | |
20 using NUnit.Framework; | |
21 | |
22 namespace Google.Apis.Testing | |
23 { | |
24 /// <summary> Assertion helper methods </summary> | |
25 public class MoreAsserts | |
26 { | |
27 /// <summary> | |
28 /// Asserts whether both enumerables have the equal content, and whether
it is in the same order | |
29 /// </summary> | |
30 public static void ContentsEqualAndInOrder(IEnumerable expected, IEnumer
able actual) | |
31 { | |
32 var expectedEnum = expected.GetEnumerator(); | |
33 var actualEnum = actual.GetEnumerator(); | |
34 int index = 0; | |
35 while (expectedEnum.MoveNext()) | |
36 { | |
37 if (actualEnum.MoveNext() == false) | |
38 { | |
39 Assert.Fail("Actual has less items then Expected at index "
index); | |
40 } | |
41 Assert.AreEqual(expectedEnum.Current, actualEnum.Current, "Found
different elements at index " index); | |
42 index ; | |
43 } | |
44 if (actualEnum.MoveNext()) | |
45 { | |
46 Assert.Fail("Actual has more items then Expected at index " in
dex); | |
47 } | |
48 } | |
49 | |
50 /// <summary> Asserts that the list is empty </summary> | |
51 public static void IsEmpty<T>(IList<T> list) | |
52 { | |
53 if (list == null) | |
54 { | |
55 Assert.Fail("List Was null"); | |
56 } | |
57 if (list.Count > 0) | |
58 { | |
59 Assert.Fail("List had a count of " list.Count " and was expe
cted to be empty."); | |
60 } | |
61 } | |
62 | |
63 /// <summary> Asserts that the enumerable is empty </summary> | |
64 public static void IsEmpty<T>(IEnumerable<T> collection) | |
65 { | |
66 if (collection == null) | |
67 { | |
68 Assert.Fail("Collection was null"); | |
69 } | |
70 | |
71 Assert.False(collection.GetEnumerator().MoveNext(), "Collection had
an element as was expected to be empty"); | |
72 } | |
73 } | |
74 } | |
OLD | NEW |