Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2017-11-01 22:54:29 +0300
committerEric Maupin <ermaup@microsoft.com>2017-11-15 22:44:05 +0300
commit0791544cd10862159bf45851b25510ff4a3b35a3 (patch)
tree05bc745e4103a3739081c584a0997dd697c04408 /Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs
parent3bace18a2c51208779e8753f2f69ad14efb170b3 (diff)
[Core] Fix ObservableLookup events
Because the groups are IList implementers, the IList overload was being executed, giving out the wrong items in the old/new items in the change event. Now we ensure groupings are treated as the item changed which fixes issues in the WPF frontend bindings.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs')
-rw-r--r--Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs b/Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs
new file mode 100644
index 0000000..f88b9b5
--- /dev/null
+++ b/Xamarin.PropertyEditing.Tests/ObservableLookupTests.cs
@@ -0,0 +1,71 @@
+using System.Collections.Specialized;
+using System.Linq;
+using NUnit.Framework;
+
+namespace Xamarin.PropertyEditing.Tests
+{
+ [TestFixture]
+ internal class ObservableLookupTests
+ {
+ [TestCase ("key")]
+ [TestCase (null)]
+ public void RemoveGroup (string key)
+ {
+ const string value = "value";
+ var lookup = new ObservableLookup<string, string> ();
+ lookup.Add (key, value);
+ Assume.That (lookup.Contains (key), Is.True);
+ Assume.That (lookup[key], Contains.Item (value));
+
+ bool groupRemoved = false;
+ lookup.CollectionChanged += (sender, args) => {
+ if (args.Action == NotifyCollectionChangedAction.Remove) {
+ var g = args.OldItems[0] as IGrouping<string, string>;
+ if (g != null && g.Key == key)
+ groupRemoved = true;
+ }
+ };
+
+ var grouping = lookup[key];
+ lookup.Remove (key);
+
+ Assert.That (groupRemoved, Is.True);
+ Assert.That (lookup, Does.Not.Contain (grouping));
+ }
+
+ [TestCase ("key")]
+ [TestCase (null)] // The reality is that null as a key receives special treatment
+ public void RemoveLastItemInGroup (string key)
+ {
+ const string value = "value";
+ var lookup = new ObservableLookup<string, string> ();
+ lookup.Add (key, value);
+ Assume.That (lookup.Contains (key), Is.True);
+ Assume.That (lookup[key], Contains.Item (value));
+
+ bool itemRemoved = false, groupRemoved = false;
+ lookup.CollectionChanged += (sender, args) => {
+ if (args.Action == NotifyCollectionChangedAction.Remove) {
+ var g = args.OldItems[0] as IGrouping<string, string>;
+ if (g != null && g.Key == key)
+ groupRemoved = true;
+ }
+ };
+
+ var grouping = lookup[key];
+ ((INotifyCollectionChanged) grouping).CollectionChanged += (sender, args) => {
+ if (args.Action == NotifyCollectionChangedAction.Remove) {
+ if (args.OldItems[0] == value)
+ itemRemoved = true;
+ }
+ };
+
+ lookup.Remove (key, value);
+
+ Assert.That (itemRemoved, Is.True);
+ Assert.That (groupRemoved, Is.True);
+ Assert.That (grouping, Does.Not.Contains (value));
+ Assert.That (lookup, Does.Not.Contain (grouping));
+ }
+ }
+}