From 111233f51c8c56d7841a3c224dc225e353d73f85 Mon Sep 17 00:00:00 2001 From: Harshita Mohite Date: Mon, 17 Feb 2025 12:39:53 +0530 Subject: [PATCH 1/2] Window Tests --- .../ControlTests/Data/WindowTests.xaml | 101 ++++++++++ .../ControlTests/WindowTests.cs | 177 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml create mode 100644 tests/Fluent.UITests/ControlTests/WindowTests.cs diff --git a/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml b/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml new file mode 100644 index 0000000..2f1fccd --- /dev/null +++ b/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + Right + Bottom + Collapsed + False + + + + Visible + + + + + + + + + + + + + + + + + + + + + + + Right + Bottom + Collapsed + False + + + + Visible + + + + + + + + + + + + + + + + + + + + + + Right + Bottom + Collapsed + False + + + + Visible + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Fluent.UITests/ControlTests/WindowTests.cs b/tests/Fluent.UITests/ControlTests/WindowTests.cs new file mode 100644 index 0000000..f64c834 --- /dev/null +++ b/tests/Fluent.UITests/ControlTests/WindowTests.cs @@ -0,0 +1,177 @@ +using Fluent.UITests.FluentAssertions; +using Fluent.UITests.TestUtilities; +using FluentAssertions.Execution; +using System.Drawing.Imaging; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using Xunit.Abstractions; + +namespace Fluent.UITests.ControlTests +{ + public class WindowTests :BaseControlTests + { + public WindowTests(ITestOutputHelper outputHelper) + { + _outputHelper = outputHelper; + SetupWindow(); + } + + [WpfTheory] + [MemberData(nameof(ColorModes_TestData))] + public void Window_Initialization_Test(ColorMode colorMode) + { + SetColorMode(TestWindow, colorMode); + TestWindow.Show(); + + ResourceDictionary rd = GetTestDataDictionary(colorMode, ""); + VerifyControlProperties(TestWindow, rd); + } + + [WpfTheory] + [MemberData(nameof(ColorModes_TestData))] + public void Window_ResizeMode_Test(ColorMode colorMode) + { + SetColorMode(TestWindow, colorMode); + TestWindow.ResizeMode = ResizeMode.CanResizeWithGrip; + TestWindow.WindowState = WindowState.Minimized; + TestWindow.Show(); + + ResourceDictionary rd = GetTestDataDictionary(colorMode, ""); + VerifyControlProperties(TestWindow, rd); + } + [WpfTheory] + [MemberData(nameof(ColorModes_TestData))] + public void Window_ResizeMode_Test2(ColorMode colorMode) + { + SetColorMode(TestWindow, colorMode); + TestWindow.ResizeMode = ResizeMode.CanResizeWithGrip; + TestWindow.WindowState = WindowState.Normal; + TestWindow.Show(); + + ResourceDictionary rd = GetTestDataDictionary(colorMode, "CanResizeGrip_NormalWindow"); + VerifyControlProperties(TestWindow, rd); + } + + [WpfTheory] + [MemberData(nameof(ColorModes_TestData))] + public void Window_Disabled_Test(ColorMode colorMode) + { + SetColorMode(TestWindow, colorMode); + TestWindow.IsEnabled = false; + TestWindow.Show(); + + ResourceDictionary rd = GetTestDataDictionary(colorMode, "Disabled"); + VerifyControlProperties(TestWindow, rd); + } + + #region Override Methods + + public override List GetStyleParts(Control element) + { + List templateParts = new List(); + templateParts.Add(element); + + //ContentPresenter? contentPresenter = element.Template.FindName("ContentPresenter", element) as ContentPresenter; + //contentPresenter.Should().NotBeNull(); + //templateParts.Add(contentPresenter); + + ResizeGrip? windowResizeGrip = element.Template.FindName("WindowResizeGrip", element) as ResizeGrip; + if (windowResizeGrip != null) { + windowResizeGrip.Should().NotBeNull(); + templateParts.Add(windowResizeGrip); + } + return templateParts; + } + + public override void VerifyControlProperties(FrameworkElement element, ResourceDictionary expectedProperties) + { + Window? window = element as Window; + if (window is null) return; + + List parts = GetStyleParts(window); + + Window? part_Window = parts[0] as Window; + ResizeGrip? part_ResizeGrip = null; + //ContentPresenter? part_ContentPresenter = parts[1] as ContentPresenter; + if (parts.Count > 1) { + part_ResizeGrip = parts[1] as ResizeGrip; + } + using (new AssertionScope()) + { + + //validate window properties + VerifyWindowProperties(part_Window, expectedProperties); + + if(part_ResizeGrip != null) + { + //validate window resize grip properties + VerifyWindowResizeGripProperties(part_ResizeGrip, expectedProperties); + } + } + } + + public static void VerifyWindowProperties(Window part_Window, ResourceDictionary expectedProperties) + { + part_Window.Should().NotBeNull(); + BrushComparer.Equal(part_Window.Background, (Brush)expectedProperties["Window_Background"]).Should().BeTrue(); + if (!BrushComparer.Equal(part_Window.Background, (Brush)expectedProperties["Window_Background"])) + { + Console.WriteLine("part_Window.Background does not match expected value"); + BrushComparer.LogBrushDifference(part_Window.Background, (Brush)expectedProperties["Window_Background"]); + } + + BrushComparer.Equal(part_Window.Foreground, (Brush)expectedProperties["Window_Foreground"]).Should().BeTrue(); + if (!BrushComparer.Equal(part_Window.Foreground, (Brush)expectedProperties["Window_Foreground"])) + { + Console.WriteLine("part_Window.Foreground does not match expected value"); + BrushComparer.LogBrushDifference(part_Window.Foreground, (Brush)expectedProperties["Window_Foreground"]); + } + // part_Window.BorderThickness.Should().Be((Thickness)expectedProperties["Button_BorderThickness"]); + } + + public static void VerifyWindowResizeGripProperties(ResizeGrip part_ResizeGrip, ResourceDictionary expectedProperties) + { + part_ResizeGrip.Should().NotBeNull(); + BrushComparer.Equal(part_ResizeGrip.Background, (Brush)expectedProperties["Window_Background"]).Should().BeTrue(); + if (!BrushComparer.Equal(part_ResizeGrip.Background, (Brush)expectedProperties["Window_Background"])) + { + Console.WriteLine("part_Window.Background does not match expected value"); + BrushComparer.LogBrushDifference(part_ResizeGrip.Background, (Brush)expectedProperties["Window_Background"]); + } + BrushComparer.Equal(part_ResizeGrip.Foreground, (Brush)expectedProperties["Window_Foreground"]).Should().BeTrue(); + if (!BrushComparer.Equal(part_ResizeGrip.Foreground, (Brush)expectedProperties["Window_Foreground"])) + { + Console.WriteLine("part_Window.Foreground does not match expected value"); + BrushComparer.LogBrushDifference(part_ResizeGrip.Foreground, (Brush)expectedProperties["Window_Foreground"]); + } + part_ResizeGrip.Visibility.Should().Be((Visibility)expectedProperties["WindowResizeGrip_Visibility"]); + part_ResizeGrip.IsTabStop.Should().Be((bool)expectedProperties["WindowResizeGrip_IsTabStop"]); + part_ResizeGrip.HorizontalAlignment.Should().Be((HorizontalAlignment)expectedProperties["WindowResizeGrip_HorizontalAlignment"]); + part_ResizeGrip.VerticalAlignment.Should().Be((VerticalAlignment)expectedProperties["WindowResizeGrip_VerticalAlignment"]); + } + #endregion + + #region Private Methods + + private void SetupWindow() + { + TestWindow = new Window() { Content = "TestWindow" }; + // Window = new Window() { Content = "Hello" }; + //AddControlToView1(TestWindow, Window); + } + + #endregion + + #region Private Properties + + //private Window Window { get; set; } + // private Dictionary Windows { get; set; } = new Dictionary(); + protected override string TestDataDictionaryPath => @"/Fluent.UITests;component/ControlTests/Data/WindowTests.xaml"; + + #endregion + private ITestOutputHelper _outputHelper; + } +} From c5c1faafd528a02dbd7e4969b3ed3305cbd47a16 Mon Sep 17 00:00:00 2001 From: Harshita Mohite Date: Mon, 17 Feb 2025 12:42:59 +0530 Subject: [PATCH 2/2] Update tests and remove unnecessary usings --- .../ControlTests/Data/WindowTests.xaml | 40 +++-------- .../ControlTests/WindowTests.cs | 72 +++++-------------- 2 files changed, 26 insertions(+), 86 deletions(-) diff --git a/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml b/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml index 2f1fccd..655d8fb 100644 --- a/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml +++ b/tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml @@ -10,8 +10,7 @@ - - + @@ -24,14 +23,9 @@ - Visible - - - - - - + Visible + @@ -41,10 +35,9 @@ - - + + 11,5,11,6--> @@ -55,14 +48,9 @@ - Visible - - - - - - + Visible + @@ -71,8 +59,7 @@ - - + @@ -85,15 +72,8 @@ - Visible - - - - - - - - + Visible + diff --git a/tests/Fluent.UITests/ControlTests/WindowTests.cs b/tests/Fluent.UITests/ControlTests/WindowTests.cs index f64c834..d0ff5d9 100644 --- a/tests/Fluent.UITests/ControlTests/WindowTests.cs +++ b/tests/Fluent.UITests/ControlTests/WindowTests.cs @@ -1,11 +1,6 @@ -using Fluent.UITests.FluentAssertions; -using Fluent.UITests.TestUtilities; +using Fluent.UITests.TestUtilities; using FluentAssertions.Execution; -using System.Drawing.Imaging; -using System.Windows.Controls; using System.Windows.Controls.Primitives; -using System.Windows.Documents; -using System.Windows.Input; using System.Windows.Media; using Xunit.Abstractions; @@ -29,22 +24,10 @@ public void Window_Initialization_Test(ColorMode colorMode) ResourceDictionary rd = GetTestDataDictionary(colorMode, ""); VerifyControlProperties(TestWindow, rd); } - + [WpfTheory] [MemberData(nameof(ColorModes_TestData))] public void Window_ResizeMode_Test(ColorMode colorMode) - { - SetColorMode(TestWindow, colorMode); - TestWindow.ResizeMode = ResizeMode.CanResizeWithGrip; - TestWindow.WindowState = WindowState.Minimized; - TestWindow.Show(); - - ResourceDictionary rd = GetTestDataDictionary(colorMode, ""); - VerifyControlProperties(TestWindow, rd); - } - [WpfTheory] - [MemberData(nameof(ColorModes_TestData))] - public void Window_ResizeMode_Test2(ColorMode colorMode) { SetColorMode(TestWindow, colorMode); TestWindow.ResizeMode = ResizeMode.CanResizeWithGrip; @@ -53,36 +36,21 @@ public void Window_ResizeMode_Test2(ColorMode colorMode) ResourceDictionary rd = GetTestDataDictionary(colorMode, "CanResizeGrip_NormalWindow"); VerifyControlProperties(TestWindow, rd); - } - - [WpfTheory] - [MemberData(nameof(ColorModes_TestData))] - public void Window_Disabled_Test(ColorMode colorMode) - { - SetColorMode(TestWindow, colorMode); - TestWindow.IsEnabled = false; - TestWindow.Show(); - - ResourceDictionary rd = GetTestDataDictionary(colorMode, "Disabled"); - VerifyControlProperties(TestWindow, rd); - } + } #region Override Methods public override List GetStyleParts(Control element) { List templateParts = new List(); - templateParts.Add(element); - - //ContentPresenter? contentPresenter = element.Template.FindName("ContentPresenter", element) as ContentPresenter; - //contentPresenter.Should().NotBeNull(); - //templateParts.Add(contentPresenter); + templateParts.Add(element); ResizeGrip? windowResizeGrip = element.Template.FindName("WindowResizeGrip", element) as ResizeGrip; - if (windowResizeGrip != null) { - windowResizeGrip.Should().NotBeNull(); - templateParts.Add(windowResizeGrip); - } + if (windowResizeGrip != null) + { + windowResizeGrip.Should().NotBeNull(); + templateParts.Add(windowResizeGrip); + } return templateParts; } @@ -95,16 +63,14 @@ public override void VerifyControlProperties(FrameworkElement element, ResourceD Window? part_Window = parts[0] as Window; ResizeGrip? part_ResizeGrip = null; - //ContentPresenter? part_ContentPresenter = parts[1] as ContentPresenter; + if (parts.Count > 1) { part_ResizeGrip = parts[1] as ResizeGrip; } using (new AssertionScope()) - { - + { //validate window properties - VerifyWindowProperties(part_Window, expectedProperties); - + VerifyWindowProperties(part_Window, expectedProperties); if(part_ResizeGrip != null) { //validate window resize grip properties @@ -113,7 +79,7 @@ public override void VerifyControlProperties(FrameworkElement element, ResourceD } } - public static void VerifyWindowProperties(Window part_Window, ResourceDictionary expectedProperties) + public static void VerifyWindowProperties(Window? part_Window, ResourceDictionary expectedProperties) { part_Window.Should().NotBeNull(); BrushComparer.Equal(part_Window.Background, (Brush)expectedProperties["Window_Background"]).Should().BeTrue(); @@ -128,8 +94,7 @@ public static void VerifyWindowProperties(Window part_Window, ResourceDictionary { Console.WriteLine("part_Window.Foreground does not match expected value"); BrushComparer.LogBrushDifference(part_Window.Foreground, (Brush)expectedProperties["Window_Foreground"]); - } - // part_Window.BorderThickness.Should().Be((Thickness)expectedProperties["Button_BorderThickness"]); + } } public static void VerifyWindowResizeGripProperties(ResizeGrip part_ResizeGrip, ResourceDictionary expectedProperties) @@ -158,17 +123,12 @@ public static void VerifyWindowResizeGripProperties(ResizeGrip part_ResizeGrip, private void SetupWindow() { - TestWindow = new Window() { Content = "TestWindow" }; - // Window = new Window() { Content = "Hello" }; - //AddControlToView1(TestWindow, Window); + TestWindow = new Window() { Content = "TestWindow" }; } #endregion - #region Private Properties - - //private Window Window { get; set; } - // private Dictionary Windows { get; set; } = new Dictionary(); + #region Private Properties protected override string TestDataDictionaryPath => @"/Fluent.UITests;component/ControlTests/Data/WindowTests.xaml"; #endregion