Repository: unoplatform/uno
File: src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs (C#)

Code before:
		[Ignore("Hittesting is only accurate in this case on skia.")]
#endif
		[CombinatorialData]
		public async Task When_ScaleTransform_HitTest(bool addClip)
		{
			var sut = new Rectangle
			{
				Width = 100,
				Height = 100,
				Fill = new SolidColorBrush(Microsoft.UI.Colors.Blue),
				RenderTransform = new ScaleTransform
				{
					ScaleX = 2,
					ScaleY = 2
				},
				// adding the clip here should do nothing since the clip matches the size of the drawing
				Clip = addClip ? new RectangleGeometry { Rect = new Rect(0, 0, 100, 100) } : null
			};

			var rect = await UITestHelper.Load(sut);

			var (element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 50, rect.Y + 50), sut.XamlRoot);
			Assert.AreEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 150, rect.Y + 150), sut.XamlRoot);
			Assert.AreEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 50, rect.Y + 150), sut.XamlRoot);
			Assert.AreEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 150, rect.Y + 150), sut.XamlRoot);
			Assert.AreEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 201, rect.Y + 201), sut.XamlRoot);
			Assert.AreNotEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X, rect.Y - 1), sut.XamlRoot);
			Assert.AreNotEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X - 1, rect.Y), sut.XamlRoot);
			Assert.AreNotEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 200, rect.Y - 1), sut.XamlRoot);
			Assert.AreNotEqual(sut, element);
			(element, _) = VisualTreeHelper.HitTest(new Windows.Foundation.Point(rect.X + 201, rect.Y), sut.XamlRoot);
			Assert.AreNotEqual(sut, element);
		}
#endif

#if HAS_UNO
		#region Drag and Drop

		[TestMethod]
		[RunsOnUIThread]
		[GitHubWorkItem("https://github.com/unoplatform/uno/issues/18770")]
		[CombinatorialData]
#if !HAS_INPUT_INJECTOR
		[Ignore("InputInjector is not supported on this platform.")]

Review comment (bug):
We need to validate with WinUI, but I suspect we should have this:

```suggestion
			var tappedCount = 0;
			var tappedPos = new Windows.Foundation.Point(0, 0);
			var tappedSource = default(UIElement);
			outer.Tapped += (_, e) =>
			{
				tappedCount++;
				tappedPos = e.GetPosition(null);
				tappedSource = e.OriginalSource;
			};

			await UITestHelper.Load(outer);

			var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector");
			using var finger = injector.GetFinger();

			finger.Tap(inner.GetAbsoluteBoundsRect().GetCenter());
			await TestServices.WindowHelper.WaitForIdle();

			Assert.AreEqual(1, tappedCount);
			Assert.IsTrue(outer.GetAbsoluteBoundsRect().Contains(tappedPos), $"tappedPos: {tappedPos}, outer absolute bounds: {outer.GetAbsoluteBoundsRect()}");
			Assert.AreEqual(inner, tappedSource);
```

Code after:
			outer.RightTapped += (_, e) =>
			{
				rightTappedCount++;
				rightTappedPos = e.GetPosition(null);
				rightTappedOriginalSource = e.OriginalSource as UIElement;
			};
			outer.Holding += (_, e) =>
			{
				holdingCount++;
				holdingPos = e.GetPosition(null);
				holdingOriginalSource = e.OriginalSource as UIElement;
			};

			await UITestHelper.Load(outer);

			var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector");
			using var mouse = injector.GetMouse();
			using var finger = injector.GetFinger(); // for Holding

			mouse.Tap(inner.GetAbsoluteBoundsRect().GetCenter());
			await TestServices.WindowHelper.WaitForIdle();

			Assert.AreEqual(1, tappedCount);
			Assert.AreEqual(0, doubleTappedCount);
			Assert.AreEqual(inner, tappedOriginalSource);
			Assert.IsTrue(outer.GetAbsoluteBoundsRect().Contains(tappedPos), $"tappedPos: {tappedPos}, outer absolute bounds: {outer.GetAbsoluteBoundsRect()}");

			// to prevent double tap on next tap
			await Task.Delay(TimeSpan.FromMicroseconds(GestureRecognizer.MultiTapMaxDelayMicroseconds));

			mouse.Tap(inner.GetAbsoluteBoundsRect().GetCenter());
			await TestServices.WindowHelper.WaitForIdle();
			mouse.Tap(inner.GetAbsoluteBoundsRect().GetCenter());
			await TestServices.WindowHelper.WaitForIdle();

			Assert.AreEqual(2, tappedCount);
			Assert.AreEqual(1, doubleTappedCount);
			Assert.AreEqual(inner, tappedOriginalSource);
			Assert.IsTrue(outer.GetAbsoluteBoundsRect().Contains(tappedPos), $"tappedPos: {tappedPos}, outer absolute bounds: {outer.GetAbsoluteBoundsRect()}");
			Assert.AreEqual(inner, doubleTappedOriginalSource);
			Assert.IsTrue(outer.GetAbsoluteBoundsRect().Contains(doubleTappedPos), $"doubleTappedPos: {doubleTappedPos}, outer absolute bounds: {outer.GetAbsoluteBoundsRect()}");

			mouse.RightTap(inner.GetAbsoluteBoundsRect().GetCenter());
			await TestServices.WindowHelper.WaitForIdle();

			Assert.AreEqual(2, tappedCount);
			Assert.AreEqual(1, rightTappedCount);
			Assert.AreEqual(inner, rightTappedOriginalSource);
			Assert.IsTrue(outer.GetAbsoluteBoundsRect().Contains(rightTappedPos), $"rightTappedPos: {rightTappedPos}, outer absolute bounds: {outer.GetAbsoluteBoundsRect()}");

			finger.Press(inner.GetAbsoluteBoundsRect().GetCenter());