From f764d46674420cfded05ea7488a28989cdd89a2b Mon Sep 17 00:00:00 2001 From: donandren Date: Mon, 1 Aug 2016 22:42:14 +0300 Subject: [PATCH] added failing unit test for issue #637: ListBox not in sync with items after inserted/removed from items --- .../ListBoxTests.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs index aa20e86854..9045abef9b 100644 --- a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs @@ -10,6 +10,7 @@ using Avalonia.Styling; using Avalonia.UnitTests; using Avalonia.VisualTree; using Xunit; +using Avalonia.Collections; namespace Avalonia.Controls.UnitTests { @@ -152,6 +153,40 @@ namespace Avalonia.Controls.UnitTests Assert.False(((ListBoxItem)target.Presenter.Panel.Children[0]).IsSelected); } + [Fact] + public void ListBox_Virt_None_Should_Sync_Items_When_Inserted_Or_Removed() + { + var items = new AvaloniaList(Enumerable.Range(0, 5).Select(x => $"Item {x}")); + var toAdd = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray(); + var target = new ListBox + { + Template = ListBoxTemplate(), + VirtualizationMode = ItemVirtualizationMode.None, + Items = items, + ItemTemplate = new FuncDataTemplate(x => new TextBlock { Height = 10 }), + SelectedIndex = 0, + }; + + Prepare(target); + + Assert.Equal(items.Count, target.Presenter.Panel.Children.Count); + + int addIndex = 1; + foreach(var item in toAdd) + { + items.Insert(addIndex++, item); + } + + Assert.Equal(items.Count, target.Presenter.Panel.Children.Count); + + foreach (var item in toAdd) + { + items.Remove(item); + } + + Assert.Equal(items.Count, target.Presenter.Panel.Children.Count); + } + private FuncControlTemplate ListBoxTemplate() { return new FuncControlTemplate(parent =>