From 6ebc1a8a425db8be291f4c54ccd1021682cba5ba Mon Sep 17 00:00:00 2001
From: Oliver Back <70009318+OliverBack@users.noreply.github.com>
Date: Fri, 8 Oct 2021 17:20:19 +0100
Subject: [PATCH] Adds ability to clear all toasts or all toast types (#137)
---
samples/BlazorServer/Pages/Index.razor | 23 +++-
samples/BlazorWebAssembly/Pages/Index.razor | 23 +++-
.../InMemoryToastService.cs | 24 ++++
src/Blazored.Toast/BlazoredToasts.razor.cs | 40 +++++-
.../Configuration/ToastSettings.cs | 4 +
src/Blazored.Toast/Services/IToastService.cs | 51 ++++++++
src/Blazored.Toast/Services/ToastService.cs | 115 +++++++++++-------
.../ToastServiceTests/ClearAll.cs | 29 +++++
.../ToastServiceTests/ClearCustomToasts.cs | 29 +++++
.../ToastServiceTests/ClearErrorToasts.cs | 43 +++++++
.../ToastServiceTests/ClearInfoToasts.cs | 43 +++++++
.../ToastServiceTests/ClearSuccessToasts.cs | 43 +++++++
.../ToastServiceTests/ClearToasts.cs | 43 +++++++
.../ToastServiceTests/ClearWarningToasts.cs | 43 +++++++
14 files changed, 504 insertions(+), 49 deletions(-)
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearAll.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearCustomToasts.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearErrorToasts.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearInfoToasts.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearSuccessToasts.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearToasts.cs
create mode 100644 tests/Blazored.Toast.Tests/ToastServiceTests/ClearWarningToasts.cs
diff --git a/samples/BlazorServer/Pages/Index.razor b/samples/BlazorServer/Pages/Index.razor
index b92876b..f874c52 100644
--- a/samples/BlazorServer/Pages/Index.razor
+++ b/samples/BlazorServer/Pages/Index.razor
@@ -18,6 +18,14 @@
+
+
+Blazored Toasts - Remove Toasts
+
+
+
+
+
@code
{
@@ -32,7 +40,20 @@
private void OnShowHtml()
{
- RenderFragment message =@I'm an INFO message with some bold text;
+ RenderFragment message =@I'm an INFO message with some bold text
+ ;
toastService.ShowToast(ToastLevel.Info, message);
}
+
+ private void ClearAll()
+ => toastService.ClearAll();
+
+ private void ClearWarnings()
+ => toastService.ClearToasts(ToastLevel.Warning);
+
+ private void ClearInfos()
+ => toastService.ClearInfoToasts();
+
+ private void ClearCustom()
+ => toastService.ClearCustomToasts();
}
diff --git a/samples/BlazorWebAssembly/Pages/Index.razor b/samples/BlazorWebAssembly/Pages/Index.razor
index beeb9cc..687db20 100644
--- a/samples/BlazorWebAssembly/Pages/Index.razor
+++ b/samples/BlazorWebAssembly/Pages/Index.razor
@@ -18,6 +18,14 @@
+
+
+Blazored Toasts - Remove Toasts
+
+
+
+
+
@code
{
@@ -32,7 +40,20 @@
private void OnShowHtml()
{
- RenderFragment message =@I'm an INFO message with some bold text;
+ RenderFragment message =@I'm an INFO message with some bold text
+ ;
toastService.ShowToast(ToastLevel.Info, message);
}
+
+ private void ClearAll()
+ => toastService.ClearAll();
+
+ private void ClearWarnings()
+ => toastService.ClearToasts(ToastLevel.Warning);
+
+ private void ClearInfos()
+ => toastService.ClearInfoToasts();
+
+ private void ClearCustom()
+ => toastService.ClearCustomToasts();
}
diff --git a/src/Blazored.Toast.TestExtensions/InMemoryToastService.cs b/src/Blazored.Toast.TestExtensions/InMemoryToastService.cs
index 0be43b7..a354a0d 100644
--- a/src/Blazored.Toast.TestExtensions/InMemoryToastService.cs
+++ b/src/Blazored.Toast.TestExtensions/InMemoryToastService.cs
@@ -13,6 +13,9 @@ public class InMemoryToastService : IToastService
public event Action OnShow;
public event Action OnShowComponent;
+ public event Action OnClearAll;
+ public event Action OnClearToasts;
+ public event Action OnClearCustomToasts;
public void ShowToast() where TComponent : IComponent
{
@@ -77,5 +80,26 @@ private string GetHeading(ToastLevel level, string heading)
_ => throw new InvalidOperationException(),
};
}
+
+ public void ClearAll()
+ => toasts.Clear();
+
+ public void ClearToasts(ToastLevel toastLevel)
+ => toasts.RemoveAll(x => x.ToastType == typeof(Configuration.ToastInstance) && x.ToastLevel == toastLevel);
+
+ public void ClearWarningToasts()
+ => toasts.RemoveAll(x => x.ToastType == typeof(Configuration.ToastInstance) && x.ToastLevel == ToastLevel.Warning);
+
+ public void ClearInfoToasts()
+ => toasts.RemoveAll(x => x.ToastType == typeof(Configuration.ToastInstance) && x.ToastLevel == ToastLevel.Info);
+
+ public void ClearSuccessToasts()
+ => toasts.RemoveAll(x => x.ToastType == typeof(Configuration.ToastInstance) && x.ToastLevel == ToastLevel.Success);
+
+ public void ClearErrorToasts()
+ => toasts.RemoveAll(x => x.ToastType == typeof(Configuration.ToastInstance) && x.ToastLevel == ToastLevel.Error);
+
+ public void ClearCustomToasts()
+ => toasts.RemoveAll(x => x.ToastType != typeof(Configuration.ToastInstance));
}
}
diff --git a/src/Blazored.Toast/BlazoredToasts.razor.cs b/src/Blazored.Toast/BlazoredToasts.razor.cs
index 885a7bd..d65c8b5 100644
--- a/src/Blazored.Toast/BlazoredToasts.razor.cs
+++ b/src/Blazored.Toast/BlazoredToasts.razor.cs
@@ -41,6 +41,9 @@ protected override void OnInitialized()
{
ToastService.OnShow += ShowToast;
ToastService.OnShowComponent += ShowToast;
+ ToastService.OnClearAll += ClearAll;
+ ToastService.OnClearToasts += ClearToasts;
+ ToastService.OnClearCustomToasts += ClearCustomToasts;
if (RemoveToastsOnNavigation)
@@ -60,6 +63,8 @@ protected override void OnInitialized()
}
}
+
+
public void RemoveToast(Guid toastId)
{
InvokeAsync(() =>
@@ -94,19 +99,19 @@ private ToastSettings BuildToastSettings(ToastLevel level, RenderFragment messag
switch (level)
{
case ToastLevel.Error:
- return new ToastSettings(string.IsNullOrWhiteSpace(heading) ? "Error" : heading, message, IconType,
+ return new ToastSettings(ToastLevel.Error, string.IsNullOrWhiteSpace(heading) ? "Error" : heading, message, IconType,
"blazored-toast-error", ErrorClass, ErrorIcon, ShowProgressBar, MaxToastCount, onclick);
case ToastLevel.Info:
- return new ToastSettings(string.IsNullOrWhiteSpace(heading) ? "Info" : heading, message, IconType,
+ return new ToastSettings(ToastLevel.Info, string.IsNullOrWhiteSpace(heading) ? "Info" : heading, message, IconType,
"blazored-toast-info", InfoClass, InfoIcon, ShowProgressBar, MaxToastCount, onclick);
case ToastLevel.Success:
- return new ToastSettings(string.IsNullOrWhiteSpace(heading) ? "Success" : heading, message, IconType,
+ return new ToastSettings(ToastLevel.Success, string.IsNullOrWhiteSpace(heading) ? "Success" : heading, message, IconType,
"blazored-toast-success", SuccessClass, SuccessIcon, ShowProgressBar, MaxToastCount, onclick);
case ToastLevel.Warning:
- return new ToastSettings(string.IsNullOrWhiteSpace(heading) ? "Warning" : heading, message, IconType,
+ return new ToastSettings(ToastLevel.Warning, string.IsNullOrWhiteSpace(heading) ? "Warning" : heading, message, IconType,
"blazored-toast-warning", WarningClass, WarningIcon, ShowProgressBar, MaxToastCount, onclick);
}
@@ -181,5 +186,32 @@ private void ShowToast(Type contentComponent, ToastParameters parameters, ToastI
StateHasChanged();
});
}
+
+ private void ClearAll()
+ {
+ InvokeAsync(() =>
+ {
+ ToastList.Clear();
+ StateHasChanged();
+ });
+ }
+
+ private void ClearToasts(ToastLevel toastLevel)
+ {
+ InvokeAsync(() =>
+ {
+ ToastList.RemoveAll(x => x.BlazoredToast == null && x.ToastSettings.ToastLevel == toastLevel);
+ StateHasChanged();
+ });
+ }
+
+ private void ClearCustomToasts()
+ {
+ InvokeAsync(() =>
+ {
+ ToastList.RemoveAll(x => x.BlazoredToast is object);
+ StateHasChanged();
+ });
+ }
}
}
diff --git a/src/Blazored.Toast/Configuration/ToastSettings.cs b/src/Blazored.Toast/Configuration/ToastSettings.cs
index f309781..7768153 100644
--- a/src/Blazored.Toast/Configuration/ToastSettings.cs
+++ b/src/Blazored.Toast/Configuration/ToastSettings.cs
@@ -1,4 +1,5 @@
using System;
+using Blazored.Toast.Services;
using Microsoft.AspNetCore.Components;
namespace Blazored.Toast.Configuration
@@ -6,6 +7,7 @@ namespace Blazored.Toast.Configuration
public class ToastSettings
{
public ToastSettings(
+ ToastLevel toastLevel,
string heading,
RenderFragment message,
IconType? iconType,
@@ -16,6 +18,7 @@ public ToastSettings(
int maxItemsShown,
Action? onClick)
{
+ ToastLevel = toastLevel;
Heading = heading;
Message = message;
IconType = iconType;
@@ -31,6 +34,7 @@ public ToastSettings(
}
}
+ public ToastLevel ToastLevel { get; set; }
public string Heading { get; set; }
public RenderFragment Message { get; set; }
public string BaseClass { get; set; }
diff --git a/src/Blazored.Toast/Services/IToastService.cs b/src/Blazored.Toast/Services/IToastService.cs
index 3b5822b..6328822 100644
--- a/src/Blazored.Toast/Services/IToastService.cs
+++ b/src/Blazored.Toast/Services/IToastService.cs
@@ -10,6 +10,21 @@ public interface IToastService
///
event Action OnShow;
+ ///
+ /// A event that will be invoked to clear all toasts
+ ///
+ event Action OnClearAll;
+
+ ///
+ /// A event that will be invoked to clear toast of specified level
+ ///
+ event Action OnClearToasts;
+
+ ///
+ /// A event that will be invoked to clear custom toast components
+ ///
+ event Action OnClearCustomToasts;
+
///
/// A event that will be invoked when showing a toast with a custom comonent
///
@@ -110,5 +125,41 @@ public interface IToastService
/// Key/Value collection of parameters to pass to component being displayed
/// Key/Settings to pass to component being displayed
void ShowToast(ToastParameters parameters, ToastInstanceSettings settings) where TComponent : IComponent;
+
+ ///
+ /// Removes all toasts
+ ///
+ void ClearAll();
+
+ ///
+ /// Removes all toasts with a specified .
+ ///
+ void ClearToasts(ToastLevel toastLevel);
+
+ ///
+ /// Removes all toasts with toast level warning
+ ///
+ void ClearWarningToasts();
+
+ ///
+ /// Removes all toasts with toast level Info
+ ///
+ void ClearInfoToasts();
+
+ ///
+ /// Removes all toasts with toast level Success
+ ///
+ void ClearSuccessToasts();
+
+ ///
+ /// Removes all toasts with toast level Error
+ ///
+ void ClearErrorToasts();
+
+ ///
+ /// Removes all custom toast components
+ ///
+ void ClearCustomToasts();
+
}
}
diff --git a/src/Blazored.Toast/Services/ToastService.cs b/src/Blazored.Toast/Services/ToastService.cs
index b680e2a..9baf3f6 100644
--- a/src/Blazored.Toast/Services/ToastService.cs
+++ b/src/Blazored.Toast/Services/ToastService.cs
@@ -10,10 +10,25 @@ public class ToastService : IToastService
///
public event Action OnShow;
+ ///
+ /// A event that will be invoked when clearing all toasts
+ ///
+ public event Action OnClearAll;
+
///
/// A event that will be invoked when showing a toast with a custom comonent
///
- public event Action OnShowComponent;
+ public event Action OnShowComponent;
+
+ ///
+ /// A event that will be invoked when clearing toasts
+ ///
+ public event Action OnClearToasts;
+
+ ///
+ /// A event that will be invoked when clearing custom toast components
+ ///
+ public event Action OnClearCustomToasts;
///
/// Shows a information toast
@@ -22,9 +37,7 @@ public class ToastService : IToastService
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowInfo(string message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Info, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Info, message, heading, onClick);
///
/// Shows a information toast
@@ -33,9 +46,7 @@ public void ShowInfo(string message, string heading = "", Action? onClick = null
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowInfo(RenderFragment message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Info, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Info, message, heading, onClick);
///
/// Shows a success toast
@@ -44,9 +55,7 @@ public void ShowInfo(RenderFragment message, string heading = "", Action? onClic
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowSuccess(string message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Success, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Success, message, heading, onClick);
///
/// Shows a success toast
@@ -55,9 +64,7 @@ public void ShowSuccess(string message, string heading = "", Action? onClick = n
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowSuccess(RenderFragment message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Success, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Success, message, heading, onClick);
///
/// Shows a warning toast
@@ -66,9 +73,7 @@ public void ShowSuccess(RenderFragment message, string heading = "", Action? onC
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowWarning(string message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Warning, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Warning, message, heading, onClick);
///
/// Shows a warning toast
@@ -77,9 +82,7 @@ public void ShowWarning(string message, string heading = "", Action? onClick = n
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowWarning(RenderFragment message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Warning, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Warning, message, heading, onClick);
///
/// Shows a error toast
@@ -88,9 +91,7 @@ public void ShowWarning(RenderFragment message, string heading = "", Action? onC
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowError(string message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Error, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Error, message, heading, onClick);
///
/// Shows a error toast
@@ -99,9 +100,7 @@ public void ShowError(string message, string heading = "", Action? onClick = nul
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowError(RenderFragment message, string heading = "", Action? onClick = null)
- {
- ShowToast(ToastLevel.Error, message, heading, onClick);
- }
+ => ShowToast(ToastLevel.Error, message, heading, onClick);
///
/// Shows a toast using the supplied settings
@@ -111,9 +110,7 @@ public void ShowError(RenderFragment message, string heading = "", Action? onCli
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowToast(ToastLevel level, string message, string heading = "", Action? onClick = null)
- {
- ShowToast(level, builder => builder.AddContent(0, message), heading, onClick);
- }
+ => ShowToast(level, builder => builder.AddContent(0, message), heading, onClick);
///
@@ -124,17 +121,13 @@ public void ShowToast(ToastLevel level, string message, string heading = "", Act
/// The text to display as the toasts heading
/// Action to be executed on click
public void ShowToast(ToastLevel level, RenderFragment message, string heading = "", Action? onClick = null)
- {
- OnShow?.Invoke(level, message, heading, onClick);
- }
+ => OnShow?.Invoke(level, message, heading, onClick);
///
/// Shows the toast with the component type
///
public void ShowToast() where TComponent : IComponent
- {
- ShowToast(typeof(TComponent), new ToastParameters(), null);
- }
+ => ShowToast(typeof(TComponent), new ToastParameters(), null);
///
/// Shows the toast with the component type />,
@@ -158,18 +151,14 @@ public void ShowToast(Type contentComponent, ToastParameters parameters, ToastIn
///
/// Key/Value collection of parameters to pass to component being displayed.
public void ShowToast(ToastParameters parameters) where TComponent : IComponent
- {
- ShowToast(typeof(TComponent), parameters, null);
- }
+ => ShowToast(typeof(TComponent), parameters, null);
///
/// Shows a toast using the supplied settings
///
/// Toast settings to be used
public void ShowToast(ToastInstanceSettings settings) where TComponent : IComponent
- {
- ShowToast(typeof(TComponent), null, settings);
- }
+ => ShowToast(typeof(TComponent), null, settings);
///
/// Shows a toast using the supplied parameter and settings
@@ -177,8 +166,48 @@ public void ShowToast(ToastInstanceSettings settings) where TCompone
/// Key/Value collection of parameters to pass to component being displayed.
/// Toast settings to be used
public void ShowToast(ToastParameters parameters, ToastInstanceSettings settings) where TComponent : IComponent
- {
- ShowToast(typeof(TComponent), parameters, settings);
- }
+ => ShowToast(typeof(TComponent), parameters, settings);
+
+ ///
+ /// Removes all toasts
+ ///
+ public void ClearAll()
+ => OnClearAll?.Invoke();
+
+ ///
+ /// Removes all toasts with a specified .
+ ///
+ public void ClearToasts(ToastLevel toastLevel)
+ => OnClearToasts?.Invoke(toastLevel);
+
+ ///
+ /// Removes all toasts with toast level warning
+ ///
+ public void ClearWarningToasts()
+ => OnClearToasts?.Invoke(ToastLevel.Warning);
+
+ ///
+ /// Removes all toasts with toast level info
+ ///
+ public void ClearInfoToasts()
+ => OnClearToasts?.Invoke(ToastLevel.Info);
+
+ ///
+ /// Removes all toasts with toast level success
+ ///
+ public void ClearSuccessToasts()
+ => OnClearToasts?.Invoke(ToastLevel.Success);
+
+ ///
+ /// Removes all toasts with toast level error
+ ///
+ public void ClearErrorToasts()
+ => OnClearToasts?.Invoke(ToastLevel.Error);
+
+ ///
+ /// Removes all custom component toasts
+ ///
+ public void ClearCustomToasts()
+ => OnClearCustomToasts?.Invoke();
}
}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearAll.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearAll.cs
new file mode 100644
index 0000000..fe6804b
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearAll.cs
@@ -0,0 +1,29 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearAll
+ {
+ private readonly ToastService _sut;
+
+ public ClearAll()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearAllInvoked_When_ClearAllCalled()
+ {
+ // arrange
+ var OnClearAllCalled = false;
+ _sut.OnClearAll += () => OnClearAllCalled = true;
+
+ // act
+ _sut.ClearAll();
+
+ // assert
+ Assert.True(OnClearAllCalled);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearCustomToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearCustomToasts.cs
new file mode 100644
index 0000000..50945ef
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearCustomToasts.cs
@@ -0,0 +1,29 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearCustomToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearCustomToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearCustomToastsInnvoked_When_ClearCustomToastsCalled()
+ {
+ // arrange
+ var OnClearCustomToastsCalled = false;
+ _sut.OnClearCustomToasts += () => OnClearCustomToastsCalled = true;
+
+ // act
+ _sut.ClearCustomToasts();
+
+ // assert
+ Assert.True(OnClearCustomToastsCalled);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearErrorToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearErrorToasts.cs
new file mode 100644
index 0000000..87ef03c
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearErrorToasts.cs
@@ -0,0 +1,43 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearErrorToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearErrorToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearToastsInnvoked_When_ClearErrorToastsCalled()
+ {
+ // arrange
+ var OnClearToastsCalled = false;
+ _sut.OnClearToasts += (_) => OnClearToastsCalled = true;
+
+ // act
+ _sut.ClearErrorToasts();
+
+ // assert
+ Assert.True(OnClearToastsCalled);
+ }
+
+ [Fact]
+ public void OnClearToastsContainsToastLevelWarning_When_ClearErrorToastsCalled()
+ {
+ // arrange
+ var toastLevel = "";
+ _sut.OnClearToasts += (argToastlevel) => toastLevel = argToastlevel.ToString();
+
+ // act
+ _sut.ClearErrorToasts();
+
+ // assert
+ Assert.Equal(ToastLevel.Error.ToString(), toastLevel);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearInfoToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearInfoToasts.cs
new file mode 100644
index 0000000..7511be7
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearInfoToasts.cs
@@ -0,0 +1,43 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearInfoToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearInfoToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearToastsInnvoked_When_ClearInfoToastsCalled()
+ {
+ // arrange
+ var OnClearToastsCalled = false;
+ _sut.OnClearToasts += (_) => OnClearToastsCalled = true;
+
+ // act
+ _sut.ClearInfoToasts();
+
+ // assert
+ Assert.True(OnClearToastsCalled);
+ }
+
+ [Fact]
+ public void OnClearToastsContainsToastLevelWarning_When_ClearInfoToastsCalled()
+ {
+ // arrange
+ var toastLevel = "";
+ _sut.OnClearToasts += (argToastlevel) => toastLevel = argToastlevel.ToString();
+
+ // act
+ _sut.ClearInfoToasts();
+
+ // assert
+ Assert.Equal(ToastLevel.Info.ToString(), toastLevel);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearSuccessToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearSuccessToasts.cs
new file mode 100644
index 0000000..435b331
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearSuccessToasts.cs
@@ -0,0 +1,43 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearSuccessToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearSuccessToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearToastsInnvoked_When_ClearSuccessToastsCalled()
+ {
+ // arrange
+ var OnClearToastsCalled = false;
+ _sut.OnClearToasts += (_) => OnClearToastsCalled = true;
+
+ // act
+ _sut.ClearSuccessToasts();
+
+ // assert
+ Assert.True(OnClearToastsCalled);
+ }
+
+ [Fact]
+ public void OnClearToastsContainsToastLevelWarning_When_ClearSuccessToastsCalled()
+ {
+ // arrange
+ var toastLevel = "";
+ _sut.OnClearToasts += (argToastlevel) => toastLevel = argToastlevel.ToString();
+
+ // act
+ _sut.ClearSuccessToasts();
+
+ // assert
+ Assert.Equal(ToastLevel.Success.ToString(), toastLevel);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearToasts.cs
new file mode 100644
index 0000000..df751b3
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearToasts.cs
@@ -0,0 +1,43 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearToastsInnvoked_When_ClearToastsCalled()
+ {
+ // arrange
+ var OnClearToastsCalled = false;
+ _sut.OnClearToasts += (_) => OnClearToastsCalled = true;
+
+ // act
+ _sut.ClearToasts(ToastLevel.Warning);
+
+ // assert
+ Assert.True(OnClearToastsCalled);
+ }
+
+ [Fact]
+ public void OnClearToastsContainsToastLevelWarning_When_ClearToastsCalled()
+ {
+ // arrange
+ var toastLevel = "";
+ _sut.OnClearToasts += (argToastlevel) => toastLevel = argToastlevel.ToString();
+
+ // act
+ _sut.ClearToasts(ToastLevel.Warning);
+
+ // assert
+ Assert.Equal(ToastLevel.Warning.ToString(), toastLevel);
+ }
+ }
+}
diff --git a/tests/Blazored.Toast.Tests/ToastServiceTests/ClearWarningToasts.cs b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearWarningToasts.cs
new file mode 100644
index 0000000..f047459
--- /dev/null
+++ b/tests/Blazored.Toast.Tests/ToastServiceTests/ClearWarningToasts.cs
@@ -0,0 +1,43 @@
+using Blazored.Toast.Services;
+using Xunit;
+
+namespace Blazored.Toast.Tests.ToastServiceTests
+{
+ public class ClearWarningToasts
+ {
+ private readonly ToastService _sut;
+
+ public ClearWarningToasts()
+ {
+ _sut = new ToastService();
+ }
+
+ [Fact]
+ public void OnClearToastsInnvoked_When_ClearWarningToastsCalled()
+ {
+ // arrange
+ var OnClearToastsCalled = false;
+ _sut.OnClearToasts += (_) => OnClearToastsCalled = true;
+
+ // act
+ _sut.ClearWarningToasts();
+
+ // assert
+ Assert.True(OnClearToastsCalled);
+ }
+
+ [Fact]
+ public void OnClearToastsContainsToastLevelWarning_When_ClearWarningToastsCalled()
+ {
+ // arrange
+ var toastLevel = "";
+ _sut.OnClearToasts += (argToastlevel) => toastLevel = argToastlevel.ToString();
+
+ // act
+ _sut.ClearWarningToasts();
+
+ // assert
+ Assert.Equal(ToastLevel.Warning.ToString(), toastLevel);
+ }
+ }
+}