Skip to content

Commit be922a3

Browse files
authored
Updating XAMLTest to the latest type safe release (#2371)
* Updating XAMLTest to the latest type safe release * Clean up warnings * SDK update * Update azure-pipelines.yml for Azure Pipelines * Revert SDK to 5.0 * Update azure-pipelines.yml for Azure Pipelines * Using package references * Adding blame for test run Skipping failing tests * Setting Topmost on windows to prevent ADO provisioner for getting on top * Re-enabling the skipped tests
1 parent 8a118ac commit be922a3

20 files changed

+270
-249
lines changed

Directory.packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />
2121
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
2222
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.3" />
23-
<PackageVersion Include="XAMLTest" Version="0.0.9" />
23+
<PackageVersion Include="XAMLTest" Version="0.1.0" />
2424
<PackageVersion Include="xunit" Version="2.4.1" />
2525
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
2626
<PackageVersion Include="Xunit.StaFact" Version="1.0.37" />

MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<IsPackable>false</IsPackable>
55
<SignAssembly>false</SignAssembly>
66
<UseWPF>true</UseWPF>
7+
<NoWarn>$(NoWarn);CA1707</NoWarn>
8+
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
79
</PropertyGroup>
810

911
<ItemGroup>

MaterialDesignThemes.UITests/TestBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
using System.Threading.Tasks;
33
using System.Windows.Controls;
44
using System.Windows.Media;
5-
using MaterialDesignColors;
65
using MaterialDesignThemes.Wpf;
76
using XamlTest;
87
using Xunit;
98
using Xunit.Abstractions;
109

1110
[assembly: CollectionBehavior(DisableTestParallelization = true)]
11+
[assembly: GenerateHelpers(typeof(SmartHint))]
12+
[assembly: GenerateHelpers(typeof(TimePicker))]
1213

1314
namespace MaterialDesignThemes.UITests
1415
{
@@ -31,10 +32,10 @@ protected async Task<Color> GetThemeColor(string name)
3132
return resource.GetAs<Color?>() ?? throw new Exception($"Failed to convert resource '{name}' to color");
3233
}
3334

34-
protected async Task<IVisualElement> LoadXaml(string xaml)
35+
protected async Task<IVisualElement<T>> LoadXaml<T>(string xaml)
3536
{
3637
await App.InitialzeWithMaterialDesign();
37-
return await App.CreateWindowWith(xaml);
38+
return await App.CreateWindowWith<T>(xaml);
3839
}
3940

4041
protected async Task<IVisualElement> LoadUserControl<TControl>()

MaterialDesignThemes.UITests/WPF/Button/OutlineButtonTests.cs renamed to MaterialDesignThemes.UITests/WPF/Buttons/OutlineButtonTests.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
using XamlTest;
66
using Xunit;
77
using Xunit.Abstractions;
8-
using WpfButton=System.Windows.Controls.Button;
98

10-
namespace MaterialDesignThemes.UITests.WPF.Button
9+
namespace MaterialDesignThemes.UITests.WPF.Buttons
1110
{
1211
public class OutlineButtonTests : TestBase
1312
{
@@ -21,14 +20,14 @@ public async Task OutlinedButton_UsesThemeColorForBorder()
2120
await using var recorder = new TestRecorder(App);
2221

2322
//Arrange
24-
IVisualElement button = await LoadXaml(
23+
IVisualElement<Button> button = await LoadXaml<Button>(
2524
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
2625
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
27-
IVisualElement? internalBorder = await button.GetElement("border");
26+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
2827

2928
//Act
30-
Color? borderColor = await button.GetProperty<Color?>(nameof(WpfButton.BorderBrush));
31-
Color? internalBorderColor = await internalBorder.GetProperty<Color?>(nameof(Border.BorderBrush));
29+
Color? borderColor = await button.GetBorderBrushColor();
30+
Color? internalBorderColor = await internalBorder.GetBorderBrushColor();
3231

3332
//Assert
3433
Assert.Equal(midColor, borderColor);
@@ -43,22 +42,22 @@ public async Task OutlinedButton_BorderCanBeOverridden()
4342
await using var recorder = new TestRecorder(App);
4443

4544
//Arrange
46-
IVisualElement button = await LoadXaml(
45+
var button = await LoadXaml<Button>(
4746
@"<Button Content=""Button""
4847
Style=""{StaticResource MaterialDesignOutlinedButton}""
4948
BorderThickness=""5""
5049
BorderBrush=""Red""
5150
/>");
5251
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
53-
IVisualElement? internalBorder = await button.GetElement("border");
52+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
5453

5554
//Act
56-
Thickness borderThickness = await internalBorder.GetProperty<Thickness>(nameof(Border.BorderThickness));
57-
SolidColorBrush borderBrush = await internalBorder.GetProperty<SolidColorBrush>(nameof(Border.BorderBrush));
55+
Thickness borderThickness = await internalBorder.GetBorderThickness();
56+
SolidColorBrush? borderBrush = (await internalBorder.GetBorderBrush()) as SolidColorBrush;
5857

5958
//Assert
6059
Assert.Equal(new Thickness(5), borderThickness);
61-
Assert.Equal(Colors.Red, borderBrush.Color);
60+
Assert.Equal(Colors.Red, borderBrush?.Color);
6261

6362
recorder.Success();
6463
}
@@ -69,19 +68,19 @@ public async Task OutlinedButton_OnMouseOver_UsesThemeBrush()
6968
await using var recorder = new TestRecorder(App);
7069

7170
//Arrange
72-
IVisualElement button = await LoadXaml(
71+
IVisualElement<Button> button = await LoadXaml<Button>(
7372
@"<Button Content=""Button"" Style=""{StaticResource MaterialDesignOutlinedButton}""/>");
7473
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
75-
IVisualElement? internalBorder = await button.GetElement("border");
74+
IVisualElement<Border> internalBorder = await button.GetElement<Border>("border");
7675

7776
//Act
78-
await button.MoveCursorToElement(Position.Center);
77+
await button.MoveCursorTo(Position.Center);
7978
await Wait.For(async () =>
8079
{
81-
SolidColorBrush internalBorderBackground = await internalBorder.GetProperty<SolidColorBrush>(nameof(Border.Background));
80+
SolidColorBrush? internalBorderBackground = (await internalBorder.GetBackground()) as SolidColorBrush;
8281

8382
//Assert
84-
Assert.Equal(midColor, internalBorderBackground.Color);
83+
Assert.Equal(midColor, internalBorderBackground?.Color);
8584
});
8685

8786
recorder.Success();

MaterialDesignThemes.UITests/WPF/Button/RaisedButtonTests.cs renamed to MaterialDesignThemes.UITests/WPF/Buttons/RaisedButtonTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System.Threading.Tasks;
2+
using System.Windows.Controls;
23
using System.Windows.Media;
34
using XamlTest;
45
using Xunit;
56
using Xunit.Abstractions;
67

7-
namespace MaterialDesignThemes.UITests.WPF.Button
8+
namespace MaterialDesignThemes.UITests.WPF.Buttons
89
{
910
public class RaisedButtonTests : TestBase
1011
{
@@ -18,7 +19,7 @@ public async Task OnLoad_ThemeBrushesSet()
1819
await using var recorder = new TestRecorder(App);
1920

2021
//Arrange
21-
IVisualElement button = await LoadXaml(@"<Button Content=""Button"" />");
22+
IVisualElement<Button> button = await LoadXaml<Button>(@"<Button Content=""Button"" />");
2223
Color midColor = await GetThemeColor("PrimaryHueMidBrush");
2324

2425
//Act

MaterialDesignThemes.UITests/WPF/ColorZone/ColorZoneTests.cs renamed to MaterialDesignThemes.UITests/WPF/ColorZones/ColorZoneTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit;
66
using Xunit.Abstractions;
77

8-
namespace MaterialDesignThemes.UITests.WPF.ColorZone
8+
namespace MaterialDesignThemes.UITests.WPF.ColorZones
99
{
1010
public class ColorZoneTests : TestBase
1111
{
@@ -30,7 +30,7 @@ public async Task Mode_SetsThemeColors(ColorZoneMode mode, string backgroundBrus
3030
{
3131
await using var recorder = new TestRecorder(App);
3232

33-
IVisualElement colorZone = await LoadXaml(@$"
33+
IVisualElement<ColorZone> colorZone = await LoadXaml<ColorZone>(@$"
3434
<materialDesign:ColorZone Mode=""{mode}""/>
3535
");
3636
Color background = await GetThemeColor(backgroundBrush);

MaterialDesignThemes.UITests/WPF/ComboBox/ComboBoxTests.cs renamed to MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit;
66
using Xunit.Abstractions;
77

8-
namespace MaterialDesignThemes.UITests.WPF.ComboBox
8+
namespace MaterialDesignThemes.UITests.WPF.ComboBoxes
99
{
1010
public class ComboBoxTests : TestBase
1111
{
@@ -20,15 +20,15 @@ public async Task OnComboBoxHelperTextFontSize_ChangesHelperTextFontSize()
2020
{
2121
await using var recorder = new TestRecorder(App);
2222

23-
var stackPanel = await LoadXaml(@"
23+
var stackPanel = await LoadXaml<StackPanel>(@"
2424
<StackPanel>
2525
<ComboBox
2626
materialDesign:HintAssist.HelperTextFontSize=""20""/>
2727
</StackPanel>");
28-
var comboBox = await stackPanel.GetElement("/ComboBox");
29-
IVisualElement helpTextBlock = await comboBox.GetElement("/Grid/Canvas/TextBlock");
28+
var comboBox = await stackPanel.GetElement<ComboBox>("/ComboBox");
29+
var helpTextBlock = await comboBox.GetElement<TextBlock>("/Grid/Canvas/TextBlock");
3030

31-
double fontSize = await helpTextBlock.GetProperty<double>(TextBlock.FontSizeProperty.Name);
31+
double fontSize = await helpTextBlock.GetFontSize();
3232

3333
Assert.Equal(20, fontSize);
3434
recorder.Success();
@@ -40,16 +40,16 @@ public async Task OnFilledComboBoxHelperTextFontSize_ChangesHelperTextFontSize()
4040
{
4141
await using var recorder = new TestRecorder(App);
4242

43-
var stackPanel = await LoadXaml(@"
43+
var stackPanel = await LoadXaml<StackPanel>(@"
4444
<StackPanel>
4545
<ComboBox
4646
Style=""{StaticResource MaterialDesignFilledComboBox}""
4747
materialDesign:HintAssist.HelperTextFontSize=""20""/>
4848
</StackPanel>");
49-
var comboBox = await stackPanel.GetElement("/ComboBox");
50-
IVisualElement helpTextBlock = await comboBox.GetElement("/Grid/Canvas/TextBlock");
49+
var comboBox = await stackPanel.GetElement<ComboBox>("/ComboBox");
50+
var helpTextBlock = await comboBox.GetElement<TextBlock>("/Grid/Canvas/TextBlock");
5151

52-
double fontSize = await helpTextBlock.GetProperty<double>(TextBlock.FontSizeProperty.Name);
52+
double fontSize = await helpTextBlock.GetFontSize();
5353

5454
Assert.Equal(20, fontSize);
5555
recorder.Success();

MaterialDesignThemes.UITests/WPF/DatePicker/DatePickerTests.cs renamed to MaterialDesignThemes.UITests/WPF/DatePickers/DatePickerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit;
66
using Xunit.Abstractions;
77

8-
namespace MaterialDesignThemes.UITests.WPF.DatePicker
8+
namespace MaterialDesignThemes.UITests.WPF.DatePickers
99
{
1010
public class DatePickerTests : TestBase
1111
{
@@ -20,15 +20,15 @@ public async Task OnDatePickerHelperTextFontSize_ChangesHelperTextFontSize()
2020
{
2121
await using var recorder = new TestRecorder(App);
2222

23-
var stackPanel = await LoadXaml(@"
23+
var stackPanel = await LoadXaml<StackPanel>(@"
2424
<StackPanel>
2525
<DatePicker materialDesign:HintAssist.HelperTextFontSize=""20""/>
2626
</StackPanel>");
27-
var timePicker = await stackPanel.GetElement("/DatePicker");
28-
IVisualElement datePickerTextBox = await timePicker.GetElement("PART_TextBox");
29-
IVisualElement helpTextBlock = await datePickerTextBox.GetElement("/Grid/Canvas/TextBlock");
27+
var datePicker = await stackPanel.GetElement<DatePicker>("/DatePicker");
28+
var datePickerTextBox = await datePicker.GetElement<TextBox>("PART_TextBox");
29+
var helpTextBlock = await datePickerTextBox.GetElement<TextBlock>("/Grid/Canvas/TextBlock");
3030

31-
double fontSize = await helpTextBlock.GetProperty<double>(TextBlock.FontSizeProperty.Name);
31+
double fontSize = await helpTextBlock.GetFontSize();
3232

3333
Assert.Equal(20, fontSize);
3434
recorder.Success();

MaterialDesignThemes.UITests/WPF/DialogHost/DialogHostTests.cs renamed to MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
using System.ComponentModel;
33
using System.Threading.Tasks;
44
using System.Windows;
5+
using System.Windows.Controls;
56
using MaterialDesignThemes.UITests.Samples.DialogHost;
6-
using MaterialDesignThemes.UITests.WPF.TimePicker;
77
using XamlTest;
88
using Xunit;
99
using Xunit.Abstractions;
1010

11-
namespace MaterialDesignThemes.UITests.WPF.DialogHost
11+
namespace MaterialDesignThemes.UITests.WPF.DialogHosts
1212
{
1313
public class DialogHostTests : TestBase
14-
{
14+
{
1515
public DialogHostTests(ITestOutputHelper output) : base(output)
1616
{
1717
}
@@ -22,28 +22,28 @@ public async Task OnOpenDialog_OverlayCoversContent()
2222
await using var recorder = new TestRecorder(App);
2323

2424
IVisualElement dialogHost = await LoadUserControl<WithCounter>();
25-
IVisualElement overlay = await dialogHost.GetElement("PART_ContentCoverGrid");
25+
var overlay = await dialogHost.GetElement<Grid>("PART_ContentCoverGrid");
2626

27-
IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock");
27+
var resultTextBlock = await dialogHost.GetElement<TextBlock>("ResultTextBlock");
2828
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 0");
2929

30-
IVisualElement testOverlayButton = await dialogHost.GetElement("TestOverlayButton");
31-
await testOverlayButton.Click();
30+
var testOverlayButton = await dialogHost.GetElement<Button>("TestOverlayButton");
31+
await testOverlayButton.LeftClick();
3232
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 1");
3333

34-
IVisualElement showDialogButton = await dialogHost.GetElement("ShowDialogButton");
35-
await showDialogButton.Click();
34+
var showDialogButton = await dialogHost.GetElement<Button>("ShowDialogButton");
35+
await showDialogButton.LeftClick();
3636

37-
IVisualElement closeDialogButton = await dialogHost.GetElement("CloseDialogButton");
37+
var closeDialogButton = await dialogHost.GetElement<Button>("CloseDialogButton");
3838
await Wait.For(async () => await closeDialogButton.GetIsVisible() == true);
3939

40-
await testOverlayButton.Click();
40+
await testOverlayButton.LeftClick();
4141
await Wait.For(async () => await resultTextBlock.GetText() == "Clicks: 1");
42-
await closeDialogButton.Click();
42+
await closeDialogButton.LeftClick();
4343

4444
var retry = new Retry(5, TimeSpan.FromSeconds(5));
4545
await Wait.For(async () => await overlay.GetVisibility() != Visibility.Visible, retry);
46-
await testOverlayButton.Click();
46+
await testOverlayButton.LeftClick();
4747
await Wait.For(async () => Assert.Equal("Clicks: 2", await resultTextBlock.GetText()), retry);
4848
}
4949

@@ -54,14 +54,14 @@ public async Task ClosingDialogWithIsOpenProperty_ShouldRaiseDialogClosingEvent(
5454
await using var recorder = new TestRecorder(App);
5555

5656
IVisualElement dialogHost = await LoadUserControl<ClosingEventCounter>();
57-
IVisualElement showButton = await dialogHost.GetElement("ShowDialogButton");
58-
IVisualElement closeButton = await dialogHost.GetElement("CloseButton");
59-
IVisualElement resultTextBlock = await dialogHost.GetElement("ResultTextBlock");
57+
var showButton = await dialogHost.GetElement<Button>("ShowDialogButton");
58+
var closeButton = await dialogHost.GetElement<Button>("CloseButton");
59+
var resultTextBlock = await dialogHost.GetElement<TextBlock>("ResultTextBlock");
6060

61-
await showButton.Click();
61+
await showButton.LeftClick();
6262
await Wait.For(async () => await closeButton.GetIsVisible());
6363
await Task.Delay(300);
64-
await closeButton.Click();
64+
await closeButton.LeftClick();
6565

6666
await Wait.For(async () => Assert.Equal("1", await resultTextBlock.GetText()));
6767
recorder.Success();

0 commit comments

Comments
 (0)