From c0ad447c3fed978c6328cfaae8cd26022d7073a6 Mon Sep 17 00:00:00 2001 From: David Oliver Date: Thu, 28 Oct 2021 10:31:42 -0400 Subject: [PATCH] chore: Add test helpers --- .../Extensions/FrameworkElementExtensions.cs | 6 +++++ .../Helpers/TestsResourceHelper.cs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Uno.UI.RuntimeTests/Helpers/TestsResourceHelper.cs diff --git a/src/Uno.UI.RuntimeTests/Extensions/FrameworkElementExtensions.cs b/src/Uno.UI.RuntimeTests/Extensions/FrameworkElementExtensions.cs index 07003d9ab6e2..a02082afca83 100644 --- a/src/Uno.UI.RuntimeTests/Extensions/FrameworkElementExtensions.cs +++ b/src/Uno.UI.RuntimeTests/Extensions/FrameworkElementExtensions.cs @@ -15,5 +15,11 @@ internal static class FrameworkElementExtensions /// public static Rect GetOnScreenBounds(this FrameworkElement element) => element.TransformToVisual(null).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight)); + + /// + /// Get bounds of relative to . + /// + public static Rect GetRelativeBounds(this FrameworkElement element, FrameworkElement relativeTo) + => element.TransformToVisual(relativeTo).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight)); } } diff --git a/src/Uno.UI.RuntimeTests/Helpers/TestsResourceHelper.cs b/src/Uno.UI.RuntimeTests/Helpers/TestsResourceHelper.cs new file mode 100644 index 000000000000..4a022e528f7e --- /dev/null +++ b/src/Uno.UI.RuntimeTests/Helpers/TestsResourceHelper.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Uno.Disposables; +using Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls; + +namespace Uno.UI.RuntimeTests.Helpers +{ + internal static class TestsResourceHelper + { + private static TestsResources _testsResources; + + /// + /// Get resource defined in TestsResources.xaml (templates, styles etc) + /// + public static T GetResource(string resourceName) + { + _testsResources ??= new TestsResources(); + return (T)_testsResources[resourceName]; + } + } +}