Skip to content

Commit b02af5a

Browse files
committed
Updates tests to be async
Updates tests to be async to prevent possible deadlocks and improve reliability.
1 parent b33b035 commit b02af5a

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

tests/MaterialDesignThemes.Wpf.Tests/DataGridAssistTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task TestAutoGeneratedCheckBoxStyleProperty()
2828
}
2929

3030
[Test, STAThreadExecutor]
31-
public void TestAutoGeneratedEditingCheckBoxStyleProperty()
31+
public async Task TestAutoGeneratedEditingCheckBoxStyleProperty()
3232
{
3333
// Assert defaults
3434
await Assert.That(DataGridAssist.AutoGeneratedEditingCheckBoxStyleProperty.Name).IsEqualTo("AutoGeneratedEditingCheckBoxStyle");
@@ -41,7 +41,7 @@ public void TestAutoGeneratedEditingCheckBoxStyleProperty()
4141
}
4242

4343
[Test, STAThreadExecutor]
44-
public void TestAutoGeneratedTextStyleProperty()
44+
public async Task TestAutoGeneratedTextStyleProperty()
4545
{
4646
// Assert defaults
4747
await Assert.That(DataGridAssist.AutoGeneratedTextStyleProperty.Name).IsEqualTo("AutoGeneratedTextStyle");
@@ -54,7 +54,7 @@ public void TestAutoGeneratedTextStyleProperty()
5454
}
5555

5656
[Test, STAThreadExecutor]
57-
public void TestAutoGeneratedEditingTextStyleProperty()
57+
public async Task TestAutoGeneratedEditingTextStyleProperty()
5858
{
5959
// Assert defaults
6060
await Assert.That(DataGridAssist.AutoGeneratedEditingTextStyleProperty.Name).IsEqualTo("AutoGeneratedEditingTextStyle");
@@ -67,7 +67,7 @@ public void TestAutoGeneratedEditingTextStyleProperty()
6767
}
6868

6969
[Test, STAThreadExecutor]
70-
public void TestCellPaddingProperty()
70+
public async Task TestCellPaddingProperty()
7171
{
7272
// Assert defaults
7373
var defaultCellPadding = new Thickness(16, 8, 16, 8);
@@ -81,7 +81,7 @@ public void TestCellPaddingProperty()
8181
}
8282

8383
[Test, STAThreadExecutor]
84-
public void TestColumnHeaderPaddingProperty()
84+
public async Task TestColumnHeaderPaddingProperty()
8585
{
8686
// Assert defaults
8787
var defaultColumnHeaderPadding = new Thickness(16, 10, 16, 10);
@@ -95,7 +95,7 @@ public void TestColumnHeaderPaddingProperty()
9595
}
9696

9797
[Test, STAThreadExecutor]
98-
public void TestEnableEditBoxAssistProperty()
98+
public async Task TestEnableEditBoxAssistProperty()
9999
{
100100
// Assert defaults
101101
await Assert.That(DataGridAssist.EnableEditBoxAssistProperty.Name).IsEqualTo("EnableEditBoxAssist");
@@ -107,7 +107,7 @@ public void TestEnableEditBoxAssistProperty()
107107
}
108108

109109
[Test, STAThreadExecutor]
110-
public void TestCornerRadiusProperty()
110+
public async Task TestCornerRadiusProperty()
111111
{
112112
// Assert defaults
113113
var defaultCornerRadius = new CornerRadius(4);

tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public async Task CanOpenAndCloseDialogWithShowMethod()
4141

4242
object? result = await DialogHost.Show("Content", id,
4343
new DialogOpenedEventHandler(((sender, args) => { args.Session.Close(42); })));
44-
4544
await Assert.That(result).IsEqualTo(42);
46-
Assert.False(_dialogHost.IsOpen);
45+
await Assert.That(_dialogHost.IsOpen).IsFalse();
4746
}
4847

4948
[Test, STAThreadExecutor]
@@ -54,9 +53,8 @@ public async Task CanOpenDialogWithShowMethodAndCloseWithIsOpen()
5453

5554
object? result = await DialogHost.Show("Content", id,
5655
new DialogOpenedEventHandler(((sender, args) => { _dialogHost.IsOpen = false; })));
57-
58-
Assert.Null(result);
59-
Assert.False(_dialogHost.IsOpen);
56+
await Assert.That(result).IsNull();
57+
await Assert.That(_dialogHost.IsOpen).IsFalse();
6058
}
6159

6260
[Test, STAThreadExecutor]
@@ -65,13 +63,13 @@ public async Task CanCloseDialogWithRoutedEvent()
6563
Guid closeParameter = Guid.NewGuid();
6664
Task<object?> showTask = _dialogHost.ShowDialog("Content");
6765
DialogSession? session = _dialogHost.CurrentSession;
68-
Assert.False(session?.IsEnded);
66+
await Assert.That(session?.IsEnded).IsFalse();
6967

7068
DialogHost.CloseDialogCommand.Execute(closeParameter, _dialogHost);
7169

72-
Assert.False(_dialogHost.IsOpen);
73-
Assert.Null(_dialogHost.CurrentSession);
74-
Assert.True(session?.IsEnded);
70+
await Assert.That(_dialogHost.IsOpen).IsFalse();
71+
await Assert.That(_dialogHost.CurrentSession).IsNull();
72+
await Assert.That(session?.IsEnded).IsTrue();
7573
await Assert.That(await showTask).IsEqualTo(closeParameter);
7674
}
7775

@@ -82,11 +80,11 @@ public async Task DialogHostExposesSessionAsProperty()
8280
_dialogHost.Identifier = id;
8381

8482
await DialogHost.Show("Content", id,
85-
new DialogOpenedEventHandler(((sender, args) =>
83+
new DialogOpenedEventHandler(async (sender, args) =>
8684
{
87-
Assert.True(ReferenceEquals(args.Session, _dialogHost.CurrentSession));
85+
await Assert.That(ReferenceEquals(args.Session, _dialogHost.CurrentSession)).IsTrue();
8886
args.Session.Close();
89-
})));
87+
}));
9088
}
9189

9290
[Test, STAThreadExecutor]
@@ -242,12 +240,12 @@ public async Task WhenDoubleClickAwayDialogCloses()
242240

243241
[Test, STAThreadExecutor]
244242
[Description("Issue 1618")]
245-
public void WhenDialogHostIsUnloadedIsOpenRemainsTrue()
243+
public async Task WhenDialogHostIsUnloadedIsOpenRemainsTrue()
246244
{
247245
_dialogHost.IsOpen = true;
248246
_dialogHost.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));
249247

250-
Assert.True(_dialogHost.IsOpen);
248+
await Assert.That(_dialogHost.IsOpen).IsTrue();
251249
}
252250

253251
[Test, STAThreadExecutor]
@@ -297,7 +295,7 @@ public async Task WhenClosingDialogReturnValueCanBeSpecifiedInClosedEventHandler
297295

298296
[Test, STAThreadExecutor]
299297
[Description("Pull Request 2029")]
300-
public void WhenClosingDialogItThrowsWhenNoInstancesLoaded()
298+
public async Task WhenClosingDialogItThrowsWhenNoInstancesLoaded()
301299
{
302300
_dialogHost.RaiseEvent(new RoutedEventArgs(FrameworkElement.UnloadedEvent));
303301

@@ -307,23 +305,23 @@ public void WhenClosingDialogItThrowsWhenNoInstancesLoaded()
307305

308306
[Test, STAThreadExecutor]
309307
[Description("Pull Request 2029")]
310-
public void WhenClosingDialogWithInvalidIdentifierItThrowsWhenNoMatchingInstances()
308+
public async Task WhenClosingDialogWithInvalidIdentifierItThrowsWhenNoMatchingInstances()
311309
{
312310
object id = Guid.NewGuid();
313311
var ex = Assert.Throws<InvalidOperationException>(() => DialogHost.Close(id));
314-
await Assert.That(ex.Message).IsEqualTo($"No loaded DialogHost have an Identifier property matching dialogIdentifier ('{id}') argument.");
312+
await Assert.That(ex.Message).IsEqualTo("No loaded DialogHost have an Identifier property matching dialogIdentifier ('{id}') argument.");
315313
}
316314

317315
[Test, STAThreadExecutor]
318316
[Description("Pull Request 2029")]
319-
public void WhenClosingDialogWithMultipleDialogHostsItThrowsTooManyMatchingInstances()
317+
public async Task WhenClosingDialogWithMultipleDialogHostsItThrowsTooManyMatchingInstances()
320318
{
321319
var secondInstance = new DialogHost();
322320
try
323321
{
324322
secondInstance.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
325323
var ex = Assert.Throws<InvalidOperationException>(() => DialogHost.Close(null!));
326-
await Assert.That(especially where multiple Windows are a concern.", ex.Message).IsEqualTo("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost);
324+
await Assert.That(ex.Message).IsEqualTo("Multiple viable DialogHosts. Specify a unique Identifier on each DialogHost especially where multiple Windows are a concern.");
327325
}
328326
finally
329327
{
@@ -333,15 +331,15 @@ public void WhenClosingDialogWithMultipleDialogHostsItThrowsTooManyMatchingInsta
333331

334332
[Test, STAThreadExecutor]
335333
[Description("Pull Request 2029")]
336-
public void WhenClosingDialogThatIsNotOpenItThrowsDialogNotOpen()
334+
public async Task WhenClosingDialogThatIsNotOpenItThrowsDialogNotOpen()
337335
{
338336
var ex = Assert.Throws<InvalidOperationException>(() => DialogHost.Close(null!));
339337
await Assert.That(ex.Message).IsEqualTo("DialogHost is not open.");
340338
}
341339

342340
[Test, STAThreadExecutor]
343341
[Description("Pull Request 2029")]
344-
public void WhenClosingDialogWithParameterItPassesParameterToHandlers()
342+
public async Task WhenClosingDialogWithParameterItPassesParameterToHandlers()
345343
{
346344
object parameter = Guid.NewGuid();
347345
object? closingParameter = null;
@@ -367,18 +365,18 @@ void DialogClosed(object sender, DialogClosedEventArgs eventArgs)
367365
}
368366

369367
[Test, STAThreadExecutor]
370-
public void WhenOpenDialogsAreOpenIsExist()
368+
public async Task WhenOpenDialogsAreOpenIsExist()
371369
{
372370
object id = Guid.NewGuid();
373371
_dialogHost.Identifier = id;
374372
bool isExist = false;
375-
_ = _dialogHost.ShowDialog("Content", new DialogOpenedEventHandler((sender, arg) =>
373+
await _dialogHost.ShowDialog("Content", new DialogOpenedEventHandler((sender, arg) =>
376374
{
377375
isExist = DialogHost.IsDialogOpen(id);
378376
}));
379-
Assert.True(isExist);
377+
await Assert.That(isExist).IsTrue();
380378
DialogHost.Close(id);
381-
Assert.False(DialogHost.IsDialogOpen(id));
379+
await Assert.That(DialogHost.IsDialogOpen(id)).IsFalse();
382380
}
383381

384382
[Test, STAThreadExecutor]
@@ -393,8 +391,8 @@ public async Task WhenOnlySingleDialogHostIdentifierIsNullItShowsDialog()
393391
{
394392
dialogHost2.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));
395393
Task showTask = DialogHost.Show("Content");
396-
Assert.True(DialogHost.IsDialogOpen(null));
397-
Assert.False(DialogHost.IsDialogOpen(dialogHost2.Identifier));
394+
await Assert.That(DialogHost.IsDialogOpen(null)).IsTrue();
395+
await Assert.That(DialogHost.IsDialogOpen(dialogHost2.Identifier)).IsFalse();
398396
DialogHost.Close(null);
399397
await showTask;
400398
}
@@ -405,8 +403,7 @@ public async Task WhenOnlySingleDialogHostIdentifierIsNullItShowsDialog()
405403
}
406404

407405
[Test, STAThreadExecutor]
408-
[Description("Issue 2844")]
409-
public void GetDialogSession_ShouldAllowAccessFromMultipleUIThreads()
406+
public async Task GetDialogSession_ShouldAllowAccessFromMultipleUIThreads()
410407
{
411408
DialogHost? dialogHost = null;
412409
DialogHost? dialogHostOnOtherUiThread = null;

tests/MaterialDesignThemes.Wpf.Tests/RatingBarTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void TextBlockForegroundConverter_ShouldReturnHorizontalLinearGradientBru
190190
// Assert
191191
Assert.IsAssignableFrom<LinearGradientBrush>(result);
192192
LinearGradientBrush resultBrush = (LinearGradientBrush)result!;
193-
await Assert.That(0.5), resultBrush.StartPoint).IsEqualTo(new Point(0);
193+
await Assert.That(resultBrush.StartPoint).IsEqualTo(new Point(0, 0.5));
194194
await Assert.That(0.5), resultBrush.EndPoint).IsEqualTo(new Point(1);
195195
}
196196

0 commit comments

Comments
 (0)