From 2336f85d02b2b8909d0b7a0ebe3b740c6239eb88 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 29 Jan 2020 21:48:14 +0100 Subject: [PATCH] Added some failing tests. That demonstrate some problems with the `SelectionModel` change notifications found so far. --- .../SelectionModelTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs b/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs index 3e908681e6..b9149bf42b 100644 --- a/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs +++ b/tests/Avalonia.Controls.UnitTests/SelectionModelTests.cs @@ -1360,6 +1360,38 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(3, target.SelectedItems.Count); } + [Fact] + public void Not_Enumerating_Changes_Does_Not_Prevent_Further_Operations() + { + var data = new[] { "foo", "bar", "baz" }; + var target = new SelectionModel { Source = data }; + + target.SelectionChanged += (s, e) => { }; + + target.SelectAll(); + target.ClearSelection(); + } + + [Fact] + public void Can_Change_Selection_From_SelectionChanged() + { + var data = new[] { "foo", "bar", "baz" }; + var target = new SelectionModel { Source = data }; + var raised = 0; + + target.SelectionChanged += (s, e) => + { + if (raised++ == 0) + { + target.ClearSelection(); + } + }; + + target.SelectAll(); + + Assert.Equal(2, raised); + } + private int GetSubscriberCount(AvaloniaList list) { return ((INotifyCollectionChangedDebug)list).GetCollectionChangedSubscribers()?.Length ?? 0;