Skip to content

How do you unit test Toast Service using Blazored Toast OnShow #412

Answered by anitagov
anitagov asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a relevant portion of my initial quick fix (moving the Mock to a different .cs file as I have various other Mock files)

using Moq;

// Arrange
var toastMoq = new Mock<IToastService>();
toastMoq.Setup(t => t.ShowToast(It.Is<ToastLevel>(t => t == ToastLevel.Success), It.IsAny<RenderFragment>(), It.IsAny<string>())).Verifiable();
using var ctx = new TestContext();
ctx.Services.AddSingleton<IToastService>(toastMoq.Object);

// Act
......
var cut = ctx.RenderComponent<MyPage>();
// Add Resource Group Name and Owner Name to the Form
cut.Find("input[name=resgroupname]").Change("TestResourceGroup");
cut.Find("input[name=ownername]").Change("TestOwner");

Action<List<AzureResourceGroup>> O…

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
6 replies
@egil
Comment options

egil May 28, 2021
Maintainer

@chrissainty
Comment options

@anitagov
Comment options

@anitagov
Comment options

@chrissainty
Comment options

Comment options

You must be logged in to vote
1 reply
@egil
Comment options

egil Jun 3, 2021
Maintainer

Comment options

You must be logged in to vote
2 replies
@skerr4311
Comment options

@egil
Comment options

egil Sep 13, 2021
Maintainer

Answer selected by anitagov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants