Skip to content

Commit ed8bbf6

Browse files
zjdanggeKeboo
andauthored
Fix some functions with wrong parameters in SnackBarMessageQueue.cs (#2367)
* Fix some functions with wrong parameters in SnackBarMessageQueue.cs * Adding unit test * Clean up some UI tests that were producing artifacts Fix naming of artifacts to allow for easier rerun Co-authored-by: Kevin Bost <[email protected]>
1 parent 18e7a14 commit ed8bbf6

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

MaterialDesignThemes.UITests/WPF/DialogHost/DialogHostTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public async Task ClosingDialogWithIsOpenProperty_ShouldRaiseDialogClosingEvent(
6464
await closeButton.Click();
6565

6666
await Wait.For(async () => Assert.Equal("1", await resultTextBlock.GetText()));
67+
recorder.Success();
6768
}
6869
}
6970
}

MaterialDesignThemes.UITests/WPF/Theme/ColorAdjustTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public async Task PrimaryColor_AdjustToTheme(PrimaryColor primary)
3535
await App.InitialzeWithMaterialDesign(BaseTheme.Light, primary, colorAdjustment:new ColorAdjustment());
3636

3737
IWindow window = await App.CreateWindow<ColorAdjustWindow>();
38-
await recorder.SaveScreenshot();
3938

4039
Color windowBackground = await window.GetBackgroundColor();
4140

MaterialDesignThemes.Wpf.Tests/SnackbarMessageQueueTests.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
namespace MaterialDesignThemes.Wpf.Tests
99
{
10-
public class SnackbarMessageQueueTests
10+
public sealed class SnackbarMessageQueueTests : IDisposable
1111
{
1212
private readonly SnackbarMessageQueue _snackbarMessageQueue;
1313
private readonly Dispatcher _dispatcher;
14+
private bool _isDisposed;
1415

1516
public SnackbarMessageQueueTests()
1617
{
@@ -22,10 +23,10 @@ public SnackbarMessageQueueTests()
2223
[Description("Ensures that GetSnackbarMessage raises an exception on null values")]
2324
public void GetSnackbarMessageNullValues()
2425
{
25-
Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!));
26-
Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue("", null, null));
27-
Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!, "", null));
28-
Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!, null, new Action(() => { })));
26+
_ = Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!));
27+
_ = Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue("", null, null));
28+
_ = Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!, "", null));
29+
_ = Assert.Throws<ArgumentNullException>(() => _snackbarMessageQueue.Enqueue(null!, null, new Action(() => { })));
2930
}
3031

3132
[StaFact]
@@ -81,5 +82,37 @@ public void GetSnackbarMessageSimpleQueue(object content, object actionContent)
8182
Assert.Equal(content, messages[0].Content);
8283
Assert.Equal(actionContent, messages[0].ActionContent);
8384
}
85+
86+
[Fact]
87+
[Description("Pull Request 2367")]
88+
public void Enqueue_ProperlySetsPromote()
89+
{
90+
_snackbarMessageQueue.Enqueue("Content", "Action Content", actionHandler: null, promote: true);
91+
92+
IReadOnlyList<SnackbarMessageQueueItem> messages = _snackbarMessageQueue.QueuedMessages;
93+
Assert.Equal(1, messages.Count);
94+
Assert.Equal("Content", messages[0].Content);
95+
Assert.Equal("Action Content", messages[0].ActionContent);
96+
Assert.True(messages[0].IsPromoted);
97+
}
98+
99+
private void Dispose(bool disposing)
100+
{
101+
if (!_isDisposed)
102+
{
103+
if (disposing)
104+
{
105+
_snackbarMessageQueue.Dispose();
106+
}
107+
108+
_isDisposed = true;
109+
}
110+
}
111+
112+
public void Dispose()
113+
{
114+
Dispose(disposing: true);
115+
GC.SuppressFinalize(this);
116+
}
84117
}
85118
}

MaterialDesignThemes.Wpf/SnackbarMessageQueue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ public void Enqueue(object content, object? actionContent, Action? actionHandler
172172
=> Enqueue(content, actionContent, actionHandler, false);
173173

174174
public void Enqueue(object content, object? actionContent, Action? actionHandler, bool promote)
175-
=> Enqueue(content, actionContent, _ => actionHandler?.Invoke(), promote, false, false);
175+
=> Enqueue(content, actionContent, _ => actionHandler?.Invoke(), false, promote, false);
176176

177177
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
178178
TArgument? actionArgument)
179179
=> Enqueue(content, actionContent, actionHandler, actionArgument, false, false);
180180

181181
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
182182
TArgument? actionArgument, bool promote) =>
183-
Enqueue(content, actionContent, actionHandler, actionArgument, promote, promote);
183+
Enqueue(content, actionContent, actionHandler, actionArgument, promote, false);
184184

185185
public void Enqueue<TArgument>(object content, object? actionContent, Action<TArgument?>? actionHandler,
186186
TArgument? actionArgument, bool promote, bool neverConsiderToBeDuplicate, TimeSpan? durationOverride = null)

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ steps:
4646
- task: PublishPipelineArtifact@1
4747
name: "PublishUITestsScreenshots"
4848
inputs:
49-
artifact: 'Screenshots'
49+
artifact: 'Screenshots-$(Build.BuildNumber)'
5050
targetPath: 'MaterialDesignThemes.UITests/bin/$(buildConfiguration)/net5.0-windows/Screenshots'
5151
publishLocation: 'pipeline'
5252
condition: always()

0 commit comments

Comments
 (0)