From 3ae53a6819594cc0f7decc8e87aa36c8a6feb592 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 16 Oct 2023 11:27:13 -0400 Subject: [PATCH] chore: Fix access modifiers and file exclusions --- .../Engine/UnitTestEngineConfig.cs | 2 +- .../Engine/UnitTestFilter.cs | 2 +- .../Library/Helpers/HotReloadHelper.cs | 29 ++++++++++--- .../Helpers/ImageAssert.ExpectedPixels.cs | 9 ++-- .../Helpers/ImageAssert.Validations.cs | 4 ++ .../Library/Helpers/ImageAssert.cs | 4 +- .../Library/Helpers/TestBitmap.cs | 12 +++++- .../Library/Helpers/UIHelper.cs | 8 ++-- .../build/Uno.UI.RuntimeTests.Engine.props | 41 +++++++++++++------ 9 files changed, 79 insertions(+), 32 deletions(-) diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestEngineConfig.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestEngineConfig.cs index 6607611..86d2ab0 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestEngineConfig.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestEngineConfig.cs @@ -6,7 +6,7 @@ namespace Uno.UI.RuntimeTests; -#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_RC +#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER public record UnitTestEngineConfig { diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestFilter.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestFilter.cs index faf44c5..2043d31 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestFilter.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UnitTestFilter.cs @@ -1,4 +1,4 @@ -#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_RC +#if !UNO_RUNTIMETESTS_DISABLE_UI || !UNO_RUNTIMETESTS_DISABLE_EMBEDDEDRUNNER using System; using System.Linq; using System.Reflection; diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/HotReloadHelper.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/HotReloadHelper.cs index 41c6201..72860da 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/HotReloadHelper.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/HotReloadHelper.cs @@ -1,4 +1,10 @@ -#if !UNO_RUNTIMETESTS_DISABLE_LIBRARY +// ********************************************************************************************************************* +// ********************************************************************************************************************* +// Be aware that this file is referenced only if the package Uno.[Win]UI.DevServer is referenced. +// ********************************************************************************************************************* +// ********************************************************************************************************************* + +#if !UNO_RUNTIMETESTS_DISABLE_LIBRARY #nullable enable #if !IS_UNO_RUNTIMETEST_PROJECT @@ -28,12 +34,23 @@ namespace Uno.UI.RuntimeTests; -public static class HotReloadHelper +public static partial class HotReloadHelper { - public static async ValueTask UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, CancellationToken ct) - => await UpdateServerFile(filPathRelativeToProject, originalText, replacementText, true, ct); - - public static async ValueTask UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, bool waitForMetadataUpdate, CancellationToken ct) + public static async ValueTask UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, CancellationToken ct) + => await UpdateServerFile(filPathRelativeToProject, originalText, replacementText, true, ct); + + /// + /// Update the + /// + /// The type that is expected to be altered + /// + /// + /// + /// + /// + /// + /// + public static async ValueTask UpdateServerFile(string filPathRelativeToProject, string originalText, string replacementText, bool waitForMetadataUpdate, CancellationToken ct) { var projectFile = typeof(HotReloadHelper).Assembly.GetCustomAttribute()?.ProjectFullPath; if (projectFile is null or { Length: 0 }) diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.ExpectedPixels.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.ExpectedPixels.cs index 8749f60..2162095 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.ExpectedPixels.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.ExpectedPixels.cs @@ -15,6 +15,7 @@ using Windows.UI; #if HAS_UNO_WINUI || WINDOWS_WINUI +using Microsoft.UI; using Microsoft.UI.Xaml.Markup; #else using Windows.UI.Xaml.Markup; @@ -22,7 +23,7 @@ namespace Uno.UI.RuntimeTests; -internal record struct ExpectedPixels +public record struct ExpectedPixels { #region Fluent declaration public static ExpectedPixels At(string name, float x, float y) @@ -193,7 +194,7 @@ private static Color GetColorFromString(string colorCode) => : (Color)XamlBindingHelper.ConvertValue(typeof(Color), colorCode); } -internal struct PixelTolerance +public struct PixelTolerance { #region Fluent declaration public static PixelTolerance None => default; @@ -247,7 +248,7 @@ public override string ToString() => : "No color tolerance"; } -internal enum ColorToleranceKind +public enum ColorToleranceKind { /// /// Each component of the pixel (i.e. a, r, g and b) might differ by the provided color tolerance @@ -260,7 +261,7 @@ internal enum ColorToleranceKind Cumulative } -internal enum LocationToleranceKind +public enum LocationToleranceKind { /// /// The offset applies to all pixel in at once diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.Validations.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.Validations.cs index 1bdccb7..3e2bfdf 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.Validations.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.Validations.cs @@ -13,6 +13,10 @@ using Windows.UI; using Windows.Foundation; +#if HAS_UNO_WINUI || WINDOWS_WINUI +using Microsoft.UI; +#endif + namespace Uno.UI.RuntimeTests; /// diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.cs index da986be..4159b63 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/ImageAssert.cs @@ -25,7 +25,7 @@ namespace Uno.UI.RuntimeTests; /// /// Screen shot based assertions, to validate individual colors of an image /// -internal static partial class ImageAssert +public static partial class ImageAssert { #region HasColorAt public static void HasColorAt(TestBitmap screenshot, Windows.Foundation.Point location, string expectedColorCode, byte tolerance = 0, [CallerLineNumber] int line = 0) @@ -144,7 +144,7 @@ private static void DoesNotHaveColorAtImpl(TestBitmap screenshot, int x, int y, { Assert.Fail(WithContext(builder: builder => builder .AppendLine($"Color at ({x},{y}) is not expected") - .AppendLine($"excluded: {ToArgbCode(excludedColor)} {ColorHelper.ToDisplayName(excludedColor)}") + .AppendLine($"excluded: {ToArgbCode(excludedColor)}") .AppendLine($"actual : {ToArgbCode(pixel)} {pixel}") .AppendLine($"tolerance: {tolerance}") .AppendLine($"difference: {difference}") diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/TestBitmap.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/TestBitmap.cs index e3eac25..055afea 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/TestBitmap.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/TestBitmap.cs @@ -14,16 +14,24 @@ using Windows.Graphics.Display; using Windows.Storage.Streams; using Windows.UI; + +#if HAS_UNO_WINUI || WINDOWS_WINUI +using Microsoft.UI; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +#else using Windows.UI.Xaml; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; +#endif namespace Uno.UI.RuntimeTests; /// /// Represents a to be tested against. /// -internal partial class TestBitmap +public partial class TestBitmap { private readonly RenderTargetBitmap _bitmap; private readonly UIElement _renderedElement; // Allow access through partial implementation @@ -42,7 +50,7 @@ private TestBitmap(RenderTargetBitmap bitmap, UIElement renderedElement, double /// /// Prefer using UIHelper.Screenshot() instead. /// - public static async Task From(RenderTargetBitmap bitmap, UIElement renderedElement, double? implicitScaling = null) + internal static async Task From(RenderTargetBitmap bitmap, UIElement renderedElement, double? implicitScaling = null) { implicitScaling ??= DisplayInformation.GetForCurrentView()?.RawPixelsPerViewPixel ?? 1; var raw = new TestBitmap(bitmap, renderedElement, implicitScaling.Value); diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/UIHelper.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/UIHelper.cs index 03cd712..cdffe5c 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/UIHelper.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Library/Helpers/UIHelper.cs @@ -12,9 +12,11 @@ using System.Threading.Tasks; using Windows.Foundation; using Windows.Graphics.Display; +using Windows.UI; using Windows.System; #if HAS_UNO_WINUI || WINDOWS_WINUI +using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; @@ -33,7 +35,7 @@ namespace Uno.UI.RuntimeTests; /// /// Set of helpers to interact with the UI during tests. /// -internal static class UIHelper +public static partial class UIHelper { /// /// Gets or sets the content of the current test area. @@ -216,9 +218,9 @@ public static async ValueTask Show(TestBitmap bitmap) { new Border { - BorderBrush = new SolidColorBrush(Windows.UI.Colors.Black), + BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = new Thickness(1), - Background = new SolidColorBrush(Windows.UI.Colors.Gray), + Background = new SolidColorBrush(Colors.Gray), Width = bitmap.Width * bitmap.ImplicitScaling + 2, Height = bitmap.Height * bitmap.ImplicitScaling + 2, Child = img = new Image diff --git a/src/Uno.UI.RuntimeTests.Engine.Package/build/Uno.UI.RuntimeTests.Engine.props b/src/Uno.UI.RuntimeTests.Engine.Package/build/Uno.UI.RuntimeTests.Engine.props index d08b7d4..38ac0fb 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Package/build/Uno.UI.RuntimeTests.Engine.props +++ b/src/Uno.UI.RuntimeTests.Engine.Package/build/Uno.UI.RuntimeTests.Engine.props @@ -1,19 +1,34 @@  - - + + <_Parameter1>$(MSBuildProjectFullPath) + + + + + + + + + - - + - + \ No newline at end of file