1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 // Brian O'Keefe (zer0keefie@gmail.com)
25 using System.Collections;
26 using NUnit.Framework;
27 using System.Collections.Specialized;
28 namespace MonoTests.System.Collections.Specialized {
30 internal static class CollectionChangedEventValidators {
33 internal static void AssertEquivalentLists(IList expected, IList actual, string message)
35 if (expected == null) {
36 Assert.IsNull (actual, "LISTEQ_1A::" + message);
39 Assert.IsNotNull (actual, "LISTEQ_1B::" + message);
41 Assert.AreEqual (expected.Count, actual.Count, "LISTEQ_2::" + message);
43 for (int i = 0; i < expected.Count; i++)
44 Assert.AreEqual (expected [i], actual [i], "LISTEQ_3::" + message);
47 private static void ValidateCommon(NotifyCollectionChangedEventArgs args, NotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex, string message)
49 Assert.IsNotNull (args, "NCCVAL_1::" + message);
51 Assert.AreEqual (action, args.Action, "NCCVAL_2::" + message);
53 AssertEquivalentLists (newItems, args.NewItems, "NCCVAL_3::" + message);
54 AssertEquivalentLists (oldItems, args.OldItems, "NCCVAL_4::" + message);
56 Assert.AreEqual (newIndex, args.NewStartingIndex, "NCCVAL_5::" + message);
57 Assert.AreEqual (oldIndex, args.OldStartingIndex, "NCCVAL_6::" + message);
60 internal static void ValidateResetOperation(NotifyCollectionChangedEventArgs args, string message)
62 ValidateCommon (args, NotifyCollectionChangedAction.Reset, null, null, -1, -1, message);
65 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, string message)
67 ValidateAddOperation (args, newItems, -1, message);
70 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, int startIndex, string message)
72 ValidateCommon (args, NotifyCollectionChangedAction.Add, newItems, null, startIndex, -1, message);
75 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, string message)
77 ValidateRemoveOperation (args, oldItems, -1, message);
80 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, int startIndex, string message)
82 ValidateCommon (args, NotifyCollectionChangedAction.Remove, null, oldItems, -1, startIndex, message);
85 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, string message)
87 ValidateReplaceOperation (args, oldItems, newItems, -1, message);
90 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, int startIndex, string message)
92 ValidateCommon (args, NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex, startIndex, message);
95 internal static void ValidateMoveOperation(NotifyCollectionChangedEventArgs args, IList changedItems, int newIndex, int oldIndex, string message)
97 ValidateCommon (args, NotifyCollectionChangedAction.Move, changedItems, changedItems, newIndex, oldIndex, message);