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.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
23 // Brian O'Keefe (zer0keefie@gmail.com)
27 using System.Collections.Generic;
30 using NUnit.Framework;
31 using System.ComponentModel;
32 using System.Collections.Specialized;
34 namespace MonoTests.System.ComponentModel {
36 public class SortDescriptionCollectionTest
38 public SortDescriptionCollectionTest()
43 public void SortDescriptionCollectionAddTest()
45 SortDescriptionCollection sdc = new SortDescriptionCollection ();
46 SortDescription addedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
48 ((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
49 Assert.AreEqual (NotifyCollectionChangedAction.Add, e.Action, "ADD_#0");
50 addedItem = (SortDescription)e.NewItems [0];
51 Assert.AreEqual (true, addedItem.IsSealed, "ADD_#0b");
54 sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
56 Assert.AreEqual ("A", addedItem.PropertyName, "ADD_#1");
57 Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADD_#2");
58 Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");
62 public void SortDescriptionCollectionAddNoHandlerTest()
64 SortDescriptionCollection sdc = new SortDescriptionCollection ();
65 SortDescription addedItem = new SortDescription ("A", ListSortDirection.Ascending);
71 Assert.AreEqual ("A", addedItem.PropertyName, "ADDN_#1");
72 Assert.AreEqual (ListSortDirection.Ascending, addedItem.Direction, "ADDN_#2");
73 Assert.AreEqual (true, addedItem.IsSealed, "ADDN_#3");
77 public void SortDescriptionCollectionRemoveTest()
79 SortDescriptionCollection sdc = new SortDescriptionCollection ();
80 SortDescription removedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
82 sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
84 ((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
85 Assert.AreEqual (NotifyCollectionChangedAction.Remove, e.Action, "REM_#0");
86 removedItem = (SortDescription)e.OldItems [0];
87 Assert.AreEqual (true, removedItem.IsSealed, "REM_#0b");
92 Assert.AreEqual ("A", removedItem.PropertyName, "REM_#1");
93 Assert.AreEqual (ListSortDirection.Ascending, removedItem.Direction, "REM_#2");
94 Assert.AreEqual (true, removedItem.IsSealed, "REM_#3");
98 public void SortDescriptionCollectionClearTest()
100 SortDescriptionCollection sdc = new SortDescriptionCollection ();
101 bool eventFired = false;
103 sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
105 ((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
106 Assert.AreEqual (NotifyCollectionChangedAction.Reset, e.Action, "CLR_#0");
112 Assert.IsTrue (eventFired, "CLR_#1");
116 public void SortDescriptionCollectionSetTest()
118 SortDescriptionCollection sdc = new SortDescriptionCollection ();
119 int addEvent = 0, removeEvent = 0;
121 SortDescription addedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
122 SortDescription removedItem = new SortDescription ("NONE", ListSortDirection.Ascending);
124 sdc.Add (new SortDescription ("A", ListSortDirection.Ascending));
126 ((INotifyCollectionChanged)sdc).CollectionChanged += delegate (object sender, NotifyCollectionChangedEventArgs e) {
128 case NotifyCollectionChangedAction.Add:
130 addedItem = (SortDescription)e.NewItems [0];
132 case NotifyCollectionChangedAction.Remove:
134 removedItem = (SortDescription)e.OldItems [0];
137 Assert.Fail ("SET_#0");
142 sdc [0] = new SortDescription ("B", ListSortDirection.Descending);
144 Assert.AreEqual (1, addEvent, "SET_#1");
145 Assert.AreEqual (1, removeEvent, "SET_#2");
147 Assert.AreEqual ("A", removedItem.PropertyName, "REM_#1");
148 Assert.AreEqual (ListSortDirection.Ascending, removedItem.Direction, "REM_#2");
149 Assert.AreEqual (true, removedItem.IsSealed, "REM_#3");
151 Assert.AreEqual ("B", addedItem.PropertyName, "ADD_#1");
152 Assert.AreEqual (ListSortDirection.Descending, addedItem.Direction, "ADD_#2");
153 Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");