Browse Source

Moved tests to correct place.

@donandren correctly identified a problem with the `ItemsPresenter` but
he put the tests in the `ListBox` tests. Moved them to the correct
place. Also tweak formatting in `ItemContainerGenerator.InsertSpace`.
Steven Kirk 9 years ago
parent
commit
209713e820

+ 2 - 1
src/Avalonia.Controls/Generators/ItemContainerGenerator.cs

@@ -87,7 +87,8 @@ namespace Avalonia.Controls.Generators
             if (count > 0)
             {
                 var toMove = _containers.Where(x => x.Key >= index)
-                                .OrderByDescending(x => x.Key).ToList();
+                    .OrderByDescending(x => x.Key)
+                    .ToList();
 
                 foreach (var i in toMove)
                 {

+ 0 - 66
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@@ -153,72 +153,6 @@ 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<string>(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<string>(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);
-        }
-
-        [Fact]
-        public void ListBox_Virt_None_Should_Sync_Items_When_Inserted_AtSameIndex_Or_Removed()
-        {
-            var items = new AvaloniaList<string>(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<string>(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<ListBox>(parent => 

+ 31 - 0
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs

@@ -211,6 +211,37 @@ namespace Avalonia.Controls.UnitTests.Presenters
             Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(1));
         }
 
+        [Fact]
+        public void Inserting_Then_Removing_Should_Add_Remove_Containers()
+        {
+            var items = new AvaloniaList<string>(Enumerable.Range(0, 5).Select(x => $"Item {x}"));
+            var toAdd = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray();
+            var target = new ItemsPresenter
+            {
+                VirtualizationMode = ItemVirtualizationMode.None,
+                Items = items,
+                ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Height = 10 }),
+            };
+
+            target.ApplyTemplate();
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+
+            foreach (var item in toAdd)
+            {
+                items.Insert(1, item);
+            }
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+
+            foreach (var item in toAdd)
+            {
+                items.Remove(item);
+            }
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+        }
+
         [Fact]
         public void Should_Handle_Duplicate_Items()
         {

+ 32 - 0
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

@@ -434,6 +434,38 @@ namespace Avalonia.Controls.UnitTests.Presenters
             Assert.Equal(expected, actual);
         }
 
+        [Fact]
+        public void Inserting_Then_Removing_Should_Add_Remove_Containers()
+        {
+            var items = new AvaloniaList<string>(Enumerable.Range(0, 5).Select(x => $"Item {x}"));
+            var toAdd = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray();
+            var target = new ItemsPresenter
+            {
+                VirtualizationMode = ItemVirtualizationMode.None,
+                Items = items,
+                ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Height = 10 }),
+            };
+
+            target.ApplyTemplate();
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+
+            int addIndex = 1;
+            foreach (var item in toAdd)
+            {
+                items.Insert(addIndex++, item);
+            }
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+
+            foreach (var item in toAdd)
+            {
+                items.Remove(item);
+            }
+
+            Assert.Equal(items.Count, target.Panel.Children.Count);
+        }
+
         [Fact]
         public void Reassigning_Items_Should_Remove_Containers()
         {