Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions tests/Fluent.UITests/ControlTests/Data/WindowTests.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
xmlns:ut="clr-namespace:Fluent.UITests.TestUtilities">
<ResourceDictionary.MergedDictionaries>

<ut:TestDictionary Name="Light">
<ut:TestDictionary.MergedDictionaries>
<ut:TestDictionary Source="/Fluent.UITests;component/ResourceTests/Data/Light.Test.xaml" />

<ut:TestDictionary Name="Default">
<!-- Window Control Properties -->
<SolidColorBrush x:Key="Window_Background" Color="Transparent" />
<!--<SolidColorBrush x:Key="Window_BorderBrush" Color="{StaticResource TextFillColorPrimary}"/>
<Thickness x:Key="Window_BorderThickness">11,5,11,6</Thickness>-->
<SolidColorBrush x:Key="Window_Foreground" Color="{StaticResource TextFillColorPrimary}"/>

<!-- Window ResizeGrip Properties -->
<HorizontalAlignment x:Key="WindowResizeGrip_HorizontalAlignment">Right</HorizontalAlignment>
<VerticalAlignment x:Key="WindowResizeGrip_VerticalAlignment">Bottom</VerticalAlignment>
<Visibility x:Key="WindowResizeGrip_Visibility">Collapsed</Visibility>
<sys:Boolean x:Key="WindowResizeGrip_IsTabStop">False</sys:Boolean>
</ut:TestDictionary>

<ut:TestDictionary Name="CanResizeGrip_NormalWindow">
<Visibility x:Key="WindowResizeGrip_Visibility">Visible</Visibility>
</ut:TestDictionary>

</ut:TestDictionary.MergedDictionaries>
</ut:TestDictionary>

<ut:TestDictionary Name="Dark">
<ut:TestDictionary.MergedDictionaries>
<ut:TestDictionary Source="/Fluent.UITests;component/ResourceTests/Data/Dark.Test.xaml" />

<ut:TestDictionary Name="Default">
<!-- Window Control Properties -->
<SolidColorBrush x:Key="Window_Background" Color="Transparent" />
<!--<SolidColorBrush x:Key="Window_BorderBrush" Color="{StaticResource TextFillColorPrimary}"/>
<Thickness x:Key="Window_BorderThickness">11,5,11,6</Thickness>-->
<SolidColorBrush x:Key="Window_Foreground" Color="{StaticResource TextFillColorPrimary}"/>

<!-- Window ResizeGrip Properties -->
<HorizontalAlignment x:Key="WindowResizeGrip_HorizontalAlignment">Right</HorizontalAlignment>
<VerticalAlignment x:Key="WindowResizeGrip_VerticalAlignment">Bottom</VerticalAlignment>
<Visibility x:Key="WindowResizeGrip_Visibility">Collapsed</Visibility>
<sys:Boolean x:Key="WindowResizeGrip_IsTabStop">False</sys:Boolean>
</ut:TestDictionary>

<ut:TestDictionary Name="CanResizeGrip_NormalWindow">
<Visibility x:Key="WindowResizeGrip_Visibility">Visible</Visibility>
</ut:TestDictionary>

</ut:TestDictionary.MergedDictionaries>
</ut:TestDictionary>

<ut:TestDictionary Name="HC">
<ut:TestDictionary.MergedDictionaries>
<ut:TestDictionary Source="/Fluent.UITests;component/ResourceTests/Data/HC.Test.xaml" />
<ut:TestDictionary Name="Default">
<!-- Window Control Properties -->
<SolidColorBrush x:Key="Window_Background" Color="Transparent" />
<!--<SolidColorBrush x:Key="Window_BorderBrush" Color="{StaticResource TextFillColorPrimary}"/>
<Thickness x:Key="Window_BorderThickness">11,5,11,6</Thickness>-->
<SolidColorBrush x:Key="Window_Foreground" Color="{StaticResource SystemColorWindowTextColor}"/>

<!-- Window ResizeGrip Properties -->
<HorizontalAlignment x:Key="WindowResizeGrip_HorizontalAlignment">Right</HorizontalAlignment>
<VerticalAlignment x:Key="WindowResizeGrip_VerticalAlignment">Bottom</VerticalAlignment>
<Visibility x:Key="WindowResizeGrip_Visibility">Collapsed</Visibility>
<sys:Boolean x:Key="WindowResizeGrip_IsTabStop">False</sys:Boolean>
</ut:TestDictionary>

<ut:TestDictionary Name="CanResizeGrip_NormalWindow">
<Visibility x:Key="WindowResizeGrip_Visibility">Visible</Visibility>
</ut:TestDictionary>

</ut:TestDictionary.MergedDictionaries>
</ut:TestDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
137 changes: 137 additions & 0 deletions tests/Fluent.UITests/ControlTests/WindowTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using Fluent.UITests.TestUtilities;
using FluentAssertions.Execution;
using System.Windows.Controls.Primitives;
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.Normal;
TestWindow.Show();

ResourceDictionary rd = GetTestDataDictionary(colorMode, "CanResizeGrip_NormalWindow");
VerifyControlProperties(TestWindow, rd);
}

#region Override Methods

public override List<FrameworkElement> GetStyleParts(Control element)
{
List<FrameworkElement> templateParts = new List<FrameworkElement>();
templateParts.Add(element);

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<FrameworkElement> parts = GetStyleParts(window);

Window? part_Window = parts[0] as Window;
ResizeGrip? part_ResizeGrip = null;

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"]);
}
}

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" };
}

#endregion

#region Private Properties
protected override string TestDataDictionaryPath => @"/Fluent.UITests;component/ControlTests/Data/WindowTests.xaml";

#endregion
private ITestOutputHelper _outputHelper;
}
}