From e3d34f2eb8519da32ab2bbd8ae2703b4b9076d7e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 14 Oct 2017 17:01:26 +0200 Subject: [PATCH] Added a failing test for #1221 --- .../VisualExtensions_GetVisualsAt.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/Avalonia.Visuals.UnitTests/VisualTree/VisualExtensions_GetVisualsAt.cs diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/VisualExtensions_GetVisualsAt.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/VisualExtensions_GetVisualsAt.cs new file mode 100644 index 0000000000..867d4d7450 --- /dev/null +++ b/tests/Avalonia.Visuals.UnitTests/VisualTree/VisualExtensions_GetVisualsAt.cs @@ -0,0 +1,103 @@ +using System; +using System.Linq; +using Avalonia.Controls; +using Avalonia.Media; +using Avalonia.Rendering; +using Avalonia.UnitTests; +using Avalonia.VisualTree; +using Xunit; + +namespace Avalonia.Visuals.UnitTests.VisualTree +{ + public class VisualExtensions_GetVisualsAt + { + [Fact] + public void Should_Find_Control() + { + using (TestApplication()) + { + Border target; + var root = new TestRoot + { + Width = 200, + Height = 200, + Child = new StackPanel + { + Background = Brushes.White, + Children = + { + (target = new Border + { + Width = 100, + Height = 200, + Background = Brushes.Red, + }), + new Border + { + Width = 100, + Height = 200, + Background = Brushes.Green, + } + }, + Orientation = Orientation.Horizontal, + } + }; + + root.Renderer = new DeferredRenderer(root, null); + root.Measure(Size.Infinity); + root.Arrange(new Rect(root.DesiredSize)); + + var result = target.GetVisualsAt(new Point(50, 50)); + + Assert.Same(target, result.Single()); + } + } + + [Fact] + public void Should_Not_Find_Sibling_Control() + { + using (TestApplication()) + { + Border target; + var root = new TestRoot + { + Width = 200, + Height = 200, + Child = new StackPanel + { + Background = Brushes.White, + Children = + { + (target = new Border + { + Width = 100, + Height = 200, + Background = Brushes.Red, + }), + new Border + { + Width = 100, + Height = 200, + Background = Brushes.Green, + } + }, + Orientation = Orientation.Horizontal, + } + }; + + root.Renderer = new DeferredRenderer(root, null); + root.Measure(Size.Infinity); + root.Arrange(new Rect(root.DesiredSize)); + + var result = target.GetVisualsAt(new Point(150, 50)); + + Assert.Empty(result); + } + } + + private IDisposable TestApplication() + { + return UnitTestApplication.Start(TestServices.MockPlatformRenderInterface); + } + } +}