From a3552bc20ad00940da454dff30dd17984fa9c5df Mon Sep 17 00:00:00 2001 From: donandren Date: Mon, 1 Aug 2016 23:07:08 +0300 Subject: [PATCH] added another failing unit test for Listbox items not in sync with the bound collection --- .../ListBoxTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs index 9045abef9b..fad972266d 100644 --- a/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ListBoxTests.cs @@ -187,6 +187,38 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(items.Count, target.Presenter.Panel.Children.Count); } + [Fact] + public void ListBox_Virt_None_Should_Sync_Items_When_Inserted_AtSameIndex_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); + + foreach (var item in toAdd) + { + items.Insert(1, 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 =>