Browse Source

Fix failing tests.

Steven Kirk 9 years ago
parent
commit
d7a757385a

+ 10 - 5
src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs

@@ -212,15 +212,20 @@ namespace Avalonia.Controls.Presenters
                 }
 
                 var container = generator.ContainerFromIndex(newItemIndex);
+                var layoutManager = LayoutManager.Instance;
 
                 // We need to do a layout here because it's possible that the container we moved to
                 // is only partially visible due to differing item sizes. If the container is only 
-                // partially visible, scroll again.
-                LayoutManager.Instance?.ExecuteLayoutPass();
-
-                if (!new Rect(panel.Bounds.Size).Contains(container.Bounds))
+                // partially visible, scroll again. Don't do this if there's no layout manager:
+                // it means we're running a unit test.
+                if (layoutManager != null)
                 {
-                    OffsetValue += newItemIndex > itemIndex ? 1 : -1;
+                    layoutManager.ExecuteLayoutPass();
+
+                    if (!new Rect(panel.Bounds.Size).Contains(container.Bounds))
+                    {
+                        OffsetValue += newItemIndex > itemIndex ? 1 : -1;
+                    }
                 }
 
                 return container;

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

@@ -11,6 +11,7 @@ using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Templates;
 using Avalonia.Input;
+using Avalonia.UnitTests;
 using Xunit;
 
 namespace Avalonia.Controls.UnitTests.Presenters