Skip to content

Commit a391d2a

Browse files
committed
Updates dependencies and refactors test utilities
Upgrades core packages including TUnit, System.CommandLine, and XAMLTest. Refactors `CommandLineOptions` for `System.CommandLine` API updates. Adapts TUnit assertion extensions and test execution context usage. Adds `ModuleInitializerAttribute` for NET472 support.
1 parent a009be9 commit a391d2a

28 files changed

Lines changed: 207 additions & 191 deletions

Directory.packages.props

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
<!-- https://learn.microsoft.com/nuget/consume-packages/Central-Package-Management?WT.mc_id=DT-MVP-5003472#transitive-pinning -->
55
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
66
</PropertyGroup>
7-
87
<ItemGroup>
98
<PackageVersion Include="BluwolfIcons" Version="1.0.1" />
109
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
1110
<PackageVersion Include="Dragablz" Version="0.0.3.234" />
12-
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
11+
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.1" />
1312
<PackageVersion Include="Humanizer" Version="2.14.1" />
1413
<PackageVersion Include="MahApps.Metro" Version="2.4.11" />
1514
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
@@ -21,7 +20,7 @@
2120
<PackageVersion Include="Microsoft.Composition" Version="1.0.31" />
2221
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
2322
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
24-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
23+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
2524
<PackageVersion Include="Microsoft.Toolkit.MVVM" Version="7.1.2" />
2625
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
2726
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
@@ -32,10 +31,16 @@
3231
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
3332
<PackageVersion Include="System.CommandLine" Version="2.0.2" />
3433
<PackageVersion Include="System.Memory" Version="4.6.3" />
34+
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
3535
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
3636
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
37-
<PackageVersion Include="TUnit" Version="0.25.21" />
37+
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
38+
<PackageVersion Include="TUnit" Version="1.9.45" />
3839
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
3940
<PackageVersion Include="XAMLTest" Version="1.3.1-ci662" />
41+
<PackageVersion Include="System.Memory" Version="4.6.3" />
42+
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
43+
<PackageVersion Include="Polyfill" Version="8.8.1" />
44+
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
4045
</ItemGroup>
41-
</Project>
46+
</Project>

tests/MaterialColorUtilities.Tests/MaterialColorUtilities.Tests.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@
1818
<ProjectReference Include="..\..\src\MaterialDesign3.MaterialColorUtilities\MaterialColorUtilities.csproj" />
1919
</ItemGroup>
2020
<ItemGroup>
21-
<PackageReference Include="GitHubActionsTestLogger">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24-
</PackageReference>
2521
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2622
<PackageReference Include="TUnit" />
2723
<PackageReference Include="Shouldly" />
2824
</ItemGroup>
2925
<ItemGroup>
30-
<Using Include="TUnit.Assertions.AssertConditions.Throws" />
3126
<Using Include="TUnit.Core.Executors" />
3227
<Using Include="TUnit.Assertions" />
3328
<Using Include="Shouldly" />

tests/MaterialDesignColors.Wpf.Tests/MaterialDesignColors.Wpf.Tests.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>net472;net8.0-windows;net10.0-windows</TargetFrameworks>
@@ -25,10 +25,7 @@
2525
</ItemGroup>
2626
<ItemGroup>
2727
<PackageReference Include="GitHubActionsTestLogger">
28-
<PrivateAssets>all</PrivateAssets>
29-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
30-
</PackageReference>
3128
<PackageReference Include="System.Private.Uri" />
3229
<PackageReference Include="TUnit" />
3330
</ItemGroup>
34-
</Project>
31+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#if NET472
2+
namespace System.Runtime.CompilerServices;
3+
4+
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
5+
internal sealed class ModuleInitializerAttribute : Attribute
6+
{
7+
}
8+
#endif

tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="CommunityToolkit.Mvvm" />
17-
<PackageReference Include="GitHubActionsTestLogger">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20-
</PackageReference>
2117
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2218
<PackageReference Include="XAMLTest" />
2319
<PackageReference Include="TUnit" />
@@ -32,4 +28,4 @@
3228
<ItemGroup>
3329
<ProjectReference Include="..\..\src\MaterialDesignThemes.Wpf\MaterialDesignThemes.Wpf.csproj" />
3430
</ItemGroup>
35-
</Project>
31+
</Project>
Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
11
using System.Numerics;
22
using System.Runtime.CompilerServices;
3-
using TUnit.Assertions.AssertConditions;
4-
using TUnit.Assertions.AssertConditions.Interfaces;
5-
using TUnit.Assertions.AssertionBuilders;
3+
using TUnit.Assertions.Core;
64

75
namespace MaterialDesignThemes.Tests.TUnit;
86

97
public static class IsCloseToExtensions
108
{
11-
public static IsCloseToWrapper<double> IsCloseTo(this IValueSource<double> valueSource, double expected, double precision, [CallerArgumentExpression(nameof(expected))] string? doNotPopulateThisValue1 = null, [CallerArgumentExpression(nameof(precision))] string? doNotPopulateThisValue2 = null)
9+
public static IsCloseToAssertion<double> IsCloseTo(
10+
this IAssertionSource<double> source, double expected, double precision,
11+
[CallerArgumentExpression(nameof(expected))] string? expectedExpression = null,
12+
[CallerArgumentExpression(nameof(precision))] string? precisionExpression = null)
1213
{
13-
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<double>(expected, precision)
14-
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);
15-
16-
return new IsCloseToWrapper<double>(assertionBuilder);
14+
source.Context.ExpressionBuilder.Append(".IsCloseTo(");
15+
source.Context.ExpressionBuilder.Append(expectedExpression);
16+
source.Context.ExpressionBuilder.Append(", ");
17+
source.Context.ExpressionBuilder.Append(precisionExpression);
18+
source.Context.ExpressionBuilder.Append(')');
19+
return new IsCloseToAssertion<double>(source.Context, expected, precision);
1720
}
1821

19-
public static IsCloseToWrapper<float> IsCloseTo(this IValueSource<float> valueSource, float expected, float precision, [CallerArgumentExpression(nameof(expected))] string? doNotPopulateThisValue1 = null, [CallerArgumentExpression(nameof(precision))] string? doNotPopulateThisValue2 = null)
22+
public static IsCloseToAssertion<float> IsCloseTo(
23+
this IAssertionSource<float> source, float expected, float precision,
24+
[CallerArgumentExpression(nameof(expected))] string? expectedExpression = null,
25+
[CallerArgumentExpression(nameof(precision))] string? precisionExpression = null)
2026
{
21-
var assertionBuilder = valueSource.RegisterAssertion(new IsCloseToCondition<float>(expected, precision)
22-
, [doNotPopulateThisValue1, doNotPopulateThisValue2]);
23-
24-
return new IsCloseToWrapper<float>(assertionBuilder);
27+
source.Context.ExpressionBuilder.Append(".IsCloseTo(");
28+
source.Context.ExpressionBuilder.Append(expectedExpression);
29+
source.Context.ExpressionBuilder.Append(", ");
30+
source.Context.ExpressionBuilder.Append(precisionExpression);
31+
source.Context.ExpressionBuilder.Append(')');
32+
return new IsCloseToAssertion<float>(source.Context, expected, precision);
2533
}
2634
}
2735

28-
public class IsCloseToWrapper<TActual>(InvokableAssertionBuilder<TActual> invokableAssertionBuilder)
29-
: InvokableValueAssertionBuilder<TActual>(invokableAssertionBuilder);
30-
31-
file class IsCloseToCondition<TActual>(TActual expected, TActual tolerance) : BaseAssertCondition<TActual>
32-
where TActual :
33-
IFloatingPoint<TActual>,
34-
INumberBase<TActual>
36+
public class IsCloseToAssertion<TValue>(AssertionContext<TValue> context, TValue expected, TValue precision) : Assertion<TValue>(context)
37+
where TValue : IFloatingPoint<TValue>, INumberBase<TValue>
3538
{
36-
protected override string GetExpectation() => $"to be within {tolerance} of {expected}";
39+
protected override string GetExpectation()
40+
{
41+
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new(15, 1);
42+
defaultInterpolatedStringHandler.AppendLiteral("to be within ");
43+
defaultInterpolatedStringHandler.AppendFormatted($"\"{precision}\"");
44+
defaultInterpolatedStringHandler.AppendLiteral(" of ");
45+
defaultInterpolatedStringHandler.AppendFormatted($"\"{expected}\"");
46+
return defaultInterpolatedStringHandler.ToStringAndClear();
47+
}
3748

38-
protected override ValueTask<AssertionResult> GetResult(
39-
TActual? actualValue, Exception? exception,
40-
AssertionMetadata assertionMetadata
41-
)
49+
protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<TValue> metadata)
4250
{
43-
if(actualValue is null)
44-
return AssertionResult.Fail("received null");
51+
TValue? actualValue = metadata.Value;
52+
Exception? exception = metadata.Exception;
53+
if (exception != null)
54+
{
55+
return Task.FromResult(AssertionResult.Failed("threw " + exception.GetType().FullName));
56+
}
57+
if (actualValue is null)
58+
{
59+
return Task.FromResult(AssertionResult.Failed($"found <null>"));
60+
}
61+
62+
TValue difference = actualValue - expected;
63+
TValue absoluteDifference = TValue.Abs(difference);
64+
bool isInRange = absoluteDifference <= precision;
4565

46-
TActual difference = actualValue - expected;
47-
TActual absoluteDifference = TActual.Abs(difference);
48-
bool isInRange = absoluteDifference <= tolerance;
49-
return AssertionResult.FailIf(!isInRange, $"received {actualValue}");
66+
if (isInRange)
67+
{
68+
return Task.FromResult(AssertionResult.Passed);
69+
}
70+
return Task.FromResult(AssertionResult.Failed($"found {actualValue}"));
5071
}
5172
}

tests/MaterialDesignThemes.UITests/WPF/AutoSuggestBoxes/AutoSuggestTextBoxTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ await Wait.For(async () =>
6363
lastHeight = currentHeight;
6464
if (!rv)
6565
{
66-
await Task.Delay(100, TestContext.Current!.CancellationToken);
66+
await Task.Delay(100, TestContext.Current!.Execution.CancellationToken);
6767
}
6868
return rv;
6969
});
@@ -74,7 +74,7 @@ await Wait.For(async () =>
7474
await bananas.LeftClick();
7575

7676
// Wait for the text to be updated
77-
await Task.Delay(50, TestContext.Current!.CancellationToken);
77+
await Task.Delay(50, TestContext.Current!.Execution.CancellationToken);
7878

7979
var suggestBoxText = await suggestBox.GetText();
8080
//Validate that the current text is the same as the selected item
@@ -128,13 +128,13 @@ public async Task AutoSuggestBox_MovesFocusToNextElement_WhenPopupIsClosed()
128128

129129
// Act
130130
await suggestBox.MoveKeyboardFocus();
131-
await Task.Delay(50, TestContext.Current!.CancellationToken);
131+
await Task.Delay(50, TestContext.Current!.Execution.CancellationToken);
132132
await suggestBox.SendInput(new KeyboardInput("B")); // Open the popup
133-
await Task.Delay(50, TestContext.Current.CancellationToken);
133+
await Task.Delay(50, TestContext.Current.Execution.CancellationToken);
134134
await suggestBox.SendInput(new KeyboardInput(Key.Escape)); // Close the popup
135-
await Task.Delay(50, TestContext.Current.CancellationToken);
135+
await Task.Delay(50, TestContext.Current.Execution.CancellationToken);
136136
await suggestBox.SendInput(new KeyboardInput(Key.Tab)); // Press TAB to focus the next element
137-
await Task.Delay(50, TestContext.Current.CancellationToken);
137+
await Task.Delay(50, TestContext.Current.Execution.CancellationToken);
138138

139139
// Assert
140140
await Assert.That(await suggestBox.GetIsFocused()).IsFalse();
@@ -155,7 +155,7 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
155155
//Act & Assert
156156
await suggestBox.MoveKeyboardFocus();
157157
await suggestBox.SendInput(new KeyboardInput("e"));
158-
await Task.Delay(delay, TestContext.Current!.CancellationToken);
158+
await Task.Delay(delay, TestContext.Current!.Execution.CancellationToken);
159159

160160
static int? GetSuggestionCount(AutoSuggestBox autoSuggestBox)
161161
{
@@ -168,12 +168,12 @@ public async Task AutoSuggestBox_KeysUpAndDown_WrapAround()
168168
//Assert that initially the first item is selected
169169
int selectedIndex = await suggestionListBox.GetSelectedIndex();
170170
await Assert.That(selectedIndex).IsEqualTo(0);
171-
await Task.Delay(delay, TestContext.Current.CancellationToken);
171+
await Task.Delay(delay, TestContext.Current.Execution.CancellationToken);
172172

173173
//Assert that the last item is selected after pressing ArrowUp
174174
await suggestBox.SendInput(new KeyboardInput(Key.Up));
175175
await Assert.That(await suggestionListBox.GetSelectedIndex()).IsEqualTo(itemCount - 1);
176-
await Task.Delay(delay, TestContext.Current.CancellationToken);
176+
await Task.Delay(delay, TestContext.Current.Execution.CancellationToken);
177177

178178
//Assert that the first item is selected after pressing ArrowDown
179179
await suggestBox.SendInput(new KeyboardInput(Key.Down));
@@ -219,15 +219,15 @@ public async Task AutoSuggestBox_ClickingButtonInInteractiveItemTemplate_DoesNot
219219
// Act
220220
await suggestBox.MoveKeyboardFocus();
221221
await suggestBox.SendInput(new KeyboardInput("a"));
222-
await Task.Delay(500, TestContext.Current!.CancellationToken);
222+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
223223

224224
// Find the button in the first suggestion item
225225
var thirdListBoxItem = await suggestionListBox.GetElement<ListBoxItem>("/ListBoxItem[2]");
226226
var button = await thirdListBoxItem.GetElement<Button>();
227227

228228
// Click the button
229229
await button.LeftClick();
230-
await Task.Delay(500, TestContext.Current!.CancellationToken);
230+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
231231

232232
// Assert
233233
await Assert.That(await suggestBox.GetIsSuggestionOpen()).IsTrue();
@@ -254,7 +254,7 @@ public async Task AutoSuggestBox_ClickingButtonForcingNonInteractive_SelectsItem
254254
// Act
255255
await suggestBox.MoveKeyboardFocus();
256256
await suggestBox.SendInput(new KeyboardInput("a"));
257-
await Task.Delay(500, TestContext.Current!.CancellationToken);
257+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
258258

259259
// Find the button in the first suggestion item
260260
var thirdListBoxItem = await suggestionListBox.GetElement<ListBoxItem>("/ListBoxItem[2]");
@@ -266,7 +266,7 @@ static void SetNonInteractive(Button button)
266266

267267
// Click the button
268268
await button.LeftClick();
269-
await Task.Delay(500, TestContext.Current!.CancellationToken);
269+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
270270

271271
// Assert
272272
await Assert.That(await suggestBox.GetIsSuggestionOpen()).IsFalse();
@@ -283,7 +283,7 @@ public async Task AutoSuggestBox_ClickingTextblockThatIsInteractive_DoesNotSelec
283283
// Act
284284
await suggestBox.MoveKeyboardFocus();
285285
await suggestBox.SendInput(new KeyboardInput("a"));
286-
await Task.Delay(500, TestContext.Current!.CancellationToken);
286+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
287287

288288
// Find the button in the first suggestion item
289289
var thirdListBoxItem = await suggestionListBox.GetElement<ListBoxItem>("/ListBoxItem[2]");
@@ -295,7 +295,7 @@ static void SetInteractive(TextBlock textBlock)
295295

296296
// Click the button
297297
await textBlock.LeftClick();
298-
await Task.Delay(500, TestContext.Current!.CancellationToken);
298+
await Task.Delay(500, TestContext.Current!.Execution.CancellationToken);
299299

300300
// Assert
301301
await Assert.That(await suggestBox.GetIsSuggestionOpen()).IsTrue();

tests/MaterialDesignThemes.UITests/WPF/ColorPickerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
2222
await thumb.SendInput(MouseInput.MoveRelative(xOffset: -5, yOffset: -10));
2323
await thumb.SendInput(MouseInput.LeftDown());
2424
await thumb.SendInput(MouseInput.MoveRelative(yOffset: 25));
25-
await Task.Delay(100, TestContext.Current!.CancellationToken);
25+
await Task.Delay(100, TestContext.Current!.Execution.CancellationToken);
2626
await thumb.SendInput(MouseInput.LeftUp());
2727

2828

tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ public async Task OnEditableComboBox_ClickInTextArea_FocusesTextBox()
125125

126126
// Open the ComboBox initially
127127
await comboBox.LeftClick(Position.RightCenter);
128-
await Task.Delay(50, TestContext.Current!.CancellationToken); // Allow a little time for the drop-down to open (and property to change)
128+
await Task.Delay(50, TestContext.Current!.Execution.CancellationToken); // Allow a little time for the drop-down to open (and property to change)
129129
bool wasOpenAfterClickOnToggleButton = await comboBox.GetIsDropDownOpen();
130130

131131
// Focus (i.e. click) another element
132132
await button.LeftClick();
133133

134134
// Click the editable TextBox of the ComboBox
135135
await editableTextBox.LeftClick();
136-
await Task.Delay(50, TestContext.Current.CancellationToken); // Allow a little time for the drop-down to open (and property to change)
136+
await Task.Delay(50, TestContext.Current.Execution.CancellationToken); // Allow a little time for the drop-down to open (and property to change)
137137
bool wasOpenAfterClickOnEditableTextBox = await comboBox.GetIsDropDownOpen();
138138
bool textBoxHasFocus = await editableTextBox.GetIsFocused();
139139
bool textBoxHasKeyboardFocus = await editableTextBox.GetIsKeyboardFocused();

0 commit comments

Comments
 (0)