-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f721769
commit 3ab739d
Showing
5 changed files
with
105 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Blazored.Toast.Services; | ||
using Bunit; | ||
using Bunit.TestDoubles; | ||
using FluentAssertions; | ||
using LinkDotNet.Blog.Web.Shared.Admin; | ||
using LinkDotNet.Infrastructure.Persistence; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared.Admin | ||
{ | ||
public class BlogPostAdminActionsTests | ||
{ | ||
[Fact] | ||
public void ShouldDeleteBlogPostWhenOkClicked() | ||
{ | ||
const string blogPostId = "2"; | ||
var repositoryMock = new Mock<IRepository>(); | ||
using var ctx = new TestContext(); | ||
ctx.AddTestAuthorization().SetAuthorized("s"); | ||
ctx.Services.AddSingleton(repositoryMock.Object); | ||
ctx.Services.AddSingleton(new Mock<IToastService>().Object); | ||
var cut = ctx.RenderComponent<BlogPostAdminActions>(s => s.Add(p => p.BlogPostId, blogPostId)); | ||
cut.Find("#delete-blogpost").Click(); | ||
|
||
cut.Find("#ok").Click(); | ||
|
||
repositoryMock.Verify(r => r.DeleteAsync(blogPostId), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotDeleteBlogPostWhenCancelClicked() | ||
{ | ||
const string blogPostId = "2"; | ||
var repositoryMock = new Mock<IRepository>(); | ||
using var ctx = new TestContext(); | ||
ctx.AddTestAuthorization().SetAuthorized("s"); | ||
ctx.Services.AddSingleton(repositoryMock.Object); | ||
ctx.Services.AddSingleton(new Mock<IToastService>().Object); | ||
var cut = ctx.RenderComponent<BlogPostAdminActions>(s => s.Add(p => p.BlogPostId, blogPostId)); | ||
cut.Find("#delete-blogpost").Click(); | ||
|
||
cut.Find("#cancel").Click(); | ||
|
||
repositoryMock.Verify(r => r.DeleteAsync(blogPostId), Times.Never); | ||
} | ||
|
||
[Fact] | ||
public void ShouldGoToEditPageOnEditClick() | ||
{ | ||
const string blogPostId = "2"; | ||
var repositoryMock = new Mock<IRepository>(); | ||
using var ctx = new TestContext(); | ||
ctx.AddTestAuthorization().SetAuthorized("s"); | ||
ctx.Services.AddSingleton(repositoryMock.Object); | ||
ctx.Services.AddSingleton(new Mock<IToastService>().Object); | ||
var navigationManager = ctx.Services.GetRequiredService<NavigationManager>(); | ||
var cut = ctx.RenderComponent<BlogPostAdminActions>(s => s.Add(p => p.BlogPostId, blogPostId)); | ||
|
||
cut.Find("#edit-blogpost").Click(); | ||
|
||
navigationManager.Uri.Should().EndWith($"update/{blogPostId}"); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Bunit; | ||
using FluentAssertions; | ||
using LinkDotNet.Blog.Web.Shared; | ||
using Xunit; | ||
|
||
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared | ||
{ | ||
public class ConfirmDialogTests | ||
{ | ||
[Fact] | ||
public void ShouldInvokeEventOnOkClick() | ||
{ | ||
var okWasClicked = false; | ||
using var ctx = new TestContext(); | ||
var cut = ctx.RenderComponent<ConfirmDialog>( | ||
b => b | ||
.Add(p => p.OnYesPressed, _ => okWasClicked = true)); | ||
cut.Instance.Open(); | ||
|
||
cut.Find("#ok").Click(); | ||
|
||
okWasClicked.Should().BeTrue(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters