diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index a2ddd952..6caebd49 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -6,8 +6,8 @@ - - + + diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/AboutMe/Components/TalksTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/AboutMe/Components/TalksTests.cs index ad83245a..056b5fc6 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/AboutMe/Components/TalksTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/AboutMe/Components/TalksTests.cs @@ -10,7 +10,7 @@ namespace LinkDotNet.Blog.IntegrationTests.Web.Features.AboutMe.Components; public sealed class TalksTests : SqlDatabaseTestBase, IDisposable { - private readonly TestContext ctx = new(); + private readonly BunitContext ctx = new(); public TalksTests() { @@ -20,7 +20,7 @@ public TalksTests() [Fact] public void WhenAddingTalkThenDisplayedToUser() { - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(s => s.ShowAdminActions, true)); cut.Find("#add-talk").Click(); cut.Find("#talk-title").Change("title"); @@ -42,7 +42,7 @@ public async Task LoadEarlierSavedTalks() await Repository.StoreAsync(new TalkBuilder().Build()); await Repository.StoreAsync(new TalkBuilder().Build()); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForComponents().Count.Should().Be(2); } @@ -51,7 +51,7 @@ public async Task LoadEarlierSavedTalks() public async Task WhenUserClickDeleteButtonThenDeleted() { await Repository.StoreAsync(new TalkBuilder().Build()); - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(s => s.ShowAdminActions, true)); cut.WaitForComponent().Find("#talk-delete").Click(); @@ -67,7 +67,7 @@ public async Task TalksAreOrderFromNewestToLatest() await Repository.StoreAsync(new TalkBuilder().WithPublishedDate(new DateTime(2021, 1, 1)).Build()); await Repository.StoreAsync(new TalkBuilder().WithPublishedDate(new DateTime(2022, 1, 1)).Build()); - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(s => s.ShowAdminActions, true)); var talks = cut.WaitForComponents(); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/CreateNewBlogPostPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/CreateNewBlogPostPageTests.cs index fc297ba0..e2fa6244 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/CreateNewBlogPostPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/CreateNewBlogPostPageTests.cs @@ -15,15 +15,15 @@ public class CreateNewBlogPostPageTests : SqlDatabaseTestBase [Fact] public async Task ShouldSaveBlogPostOnSave() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); var toastService = Substitute.For(); ctx.JSInterop.SetupVoid("hljs.highlightAll"); - ctx.AddTestAuthorization().SetAuthorized("some username"); + ctx.AddAuthorization().SetAuthorized("some username"); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => toastService); ctx.ComponentFactories.AddStub(); ctx.Services.AddScoped(_ => Substitute.For()); - using var cut = ctx.RenderComponent(); + using var cut = ctx.Render(); var newBlogPost = cut.FindComponent(); TriggerNewBlogPost(newBlogPost); @@ -37,14 +37,14 @@ public async Task ShouldSaveBlogPostOnSave() [Fact] public async Task ShouldSetContentFromFile() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); const string contentFromFile = "content"; ctx.JSInterop.SetupVoid("hljs.highlightAll"); - ctx.AddTestAuthorization().SetAuthorized("some username"); + ctx.AddAuthorization().SetAuthorized("some username"); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); var args = SetupUploadFile(contentFromFile, ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); var uploadFile = cut.FindComponent(); await uploadFile.InvokeAsync(() => cut.FindComponent().Instance.OnChange.InvokeAsync(args)); @@ -52,7 +52,7 @@ public async Task ShouldSetContentFromFile() cut.Find("#content").TextContent.Should().Be(contentFromFile); } - private static void TriggerNewBlogPost(IRenderedComponent cut) + private static void TriggerNewBlogPost(RenderedComponent cut) { cut.Find("#title").Input("My Title"); cut.Find("#short").Input("My short Description"); @@ -64,7 +64,7 @@ private static void TriggerNewBlogPost(IRenderedComponent cut cut.Find("form").Submit(); } - private static InputFileChangeEventArgs SetupUploadFile(string contentFromFile, TestContext ctx) + private static InputFileChangeEventArgs SetupUploadFile(string contentFromFile, BunitContext ctx) { var file = Substitute.For(); var fileProcessor = Substitute.For(); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/UpdateBlogPostPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/UpdateBlogPostPageTests.cs index 72850d7c..b2f55f2e 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/UpdateBlogPostPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/UpdateBlogPostPageTests.cs @@ -15,16 +15,16 @@ public class UpdateBlogPostPageTests : SqlDatabaseTestBase [Fact] public async Task ShouldSaveBlogPostOnSave() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.SetupVoid("hljs.highlightAll"); var toastService = Substitute.For(); var blogPost = new BlogPostBuilder().WithTitle("Title").WithShortDescription("Sub").Build(); await Repository.StoreAsync(blogPost); - ctx.AddTestAuthorization().SetAuthorized("some username"); + ctx.AddAuthorization().SetAuthorized("some username"); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => toastService); ctx.ComponentFactories.AddStub(); - using var cut = ctx.RenderComponent( + using var cut = ctx.Render( p => p.Add(s => s.BlogPostId, blogPost.Id)); var newBlogPost = cut.FindComponent(); @@ -39,18 +39,18 @@ public async Task ShouldSaveBlogPostOnSave() [Fact] public void ShouldThrowWhenNoIdProvided() { - using var ctx = new TestContext(); - ctx.AddTestAuthorization().SetAuthorized("some username"); + using var ctx = new BunitContext(); + ctx.AddAuthorization().SetAuthorized("some username"); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - Action act = () => ctx.RenderComponent( + Action act = () => ctx.Render( p => p.Add(s => s.BlogPostId, null)); act.Should().ThrowExactly(); } - private static void TriggerUpdate(IRenderedFragment cut) + private static void TriggerUpdate(RenderedFragment cut) { cut.Find("#short").Input("My new Description"); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/Dashboard/Components/VisitCountPerPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/Dashboard/Components/VisitCountPerPageTests.cs index 0006cd13..0163ef43 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/Dashboard/Components/VisitCountPerPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/Dashboard/Components/VisitCountPerPageTests.cs @@ -19,11 +19,11 @@ public async Task ShouldShowCounts() { var blogPost = new BlogPostBuilder().WithTitle("I was clicked").WithLikes(2).Build(); await Repository.StoreAsync(blogPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterRepositories(ctx); await SaveBlogPostArticleClicked(blogPost.Id, 10); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); var elements = cut.WaitForElements("td"); elements.Count.Should().Be(3); @@ -52,10 +52,10 @@ public async Task ShouldFilterByDate() { BlogPostId = blogPost1.Id, DateClicked = new DateOnly(2021, 1, 1), Clicks = 1 }; await DbContext.BlogPostRecords.AddRangeAsync(clicked1, clicked2, clicked3, clicked4); await DbContext.SaveChangesAsync(); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.ComponentFactories.AddStub(); RegisterRepositories(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); var filter = new Filter { StartDate = new DateOnly(2019, 1, 1), EndDate = new DateOnly(2020, 12, 31) }; await cut.InvokeAsync(() => cut.FindComponent().Instance.FilterChanged.InvokeAsync(filter)); @@ -84,16 +84,16 @@ public async Task ShouldShowTotalClickCount() { BlogPostId = blogPost2.Id, DateClicked = DateOnly.MinValue, Clicks = 1 }; await DbContext.BlogPostRecords.AddRangeAsync(clicked1, clicked2, clicked3); await DbContext.SaveChangesAsync(); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterRepositories(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement("td"); cut.Find("#total-clicks").TextContent.Should().Be("4 clicks in total"); } - private void RegisterRepositories(TestContextBase ctx) + private void RegisterRepositories(BunitContext ctx) { ctx.Services.AddScoped>(_ => new Repository(DbContextFactory, Substitute.For>>())); ctx.Services.AddScoped>(_ => new Repository(DbContextFactory, Substitute.For>>())); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/DraftBlogPost/DraftBlogPostPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/DraftBlogPost/DraftBlogPostPageTests.cs index f526e5e1..3f610ad8 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/DraftBlogPost/DraftBlogPostPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/DraftBlogPost/DraftBlogPostPageTests.cs @@ -17,10 +17,10 @@ public async Task ShouldOnlyShowPublishedPosts() var unpublishedPost = new BlogPostBuilder().WithTitle("Not published").IsPublished(false).Build(); await Repository.StoreAsync(publishedPost); await Repository.StoreAsync(unpublishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; ctx.Services.AddScoped(_ => Repository); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement(".blog-card"); var blogPosts = cut.FindComponents(); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Archive/ArchivePageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Archive/ArchivePageTests.cs index 801264be..5c8c28a4 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Archive/ArchivePageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Archive/ArchivePageTests.cs @@ -18,13 +18,13 @@ public class ArchivePageTests : SqlDatabaseTestBase [Fact] public async Task ShouldDisplayAllBlogPosts() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); await Repository.StoreAsync(CreateBlogPost(new DateTime(2021, 1, 1), "Blog Post 1")); await Repository.StoreAsync(CreateBlogPost(new DateTime(2021, 2, 1), "Blog Post 2")); await Repository.StoreAsync(CreateBlogPost(new DateTime(2022, 1, 1), "Blog Post 3")); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElements("h2"); var yearHeader = cut.FindAll("h2"); @@ -41,14 +41,14 @@ public async Task ShouldDisplayAllBlogPosts() [Fact] public async Task ShouldOnlyShowPublishedBlogPosts() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); var publishedBlogPost = new BlogPostBuilder().WithUpdatedDate(new DateTime(2022, 1, 1)).IsPublished().Build(); var unPublishedBlogPost = new BlogPostBuilder().WithUpdatedDate(new DateTime(2022, 1, 1)).IsPublished(false).Build(); await Repository.StoreAsync(publishedBlogPost); await Repository.StoreAsync(unPublishedBlogPost); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElements("h2"); cut.FindAll("h2").Should().HaveCount(1); @@ -57,12 +57,12 @@ public async Task ShouldOnlyShowPublishedBlogPosts() [Fact] public async Task ShouldShowTotalAmountOfBlogPosts() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); await Repository.StoreAsync(CreateBlogPost(new DateTime(2021, 1, 1), "Blog Post 1")); await Repository.StoreAsync(CreateBlogPost(new DateTime(2021, 2, 1), "Blog Post 2")); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElements("h2"); cut.Find("h3").TextContent.Should().Be("Archive (2 posts)"); @@ -71,10 +71,10 @@ public async Task ShouldShowTotalAmountOfBlogPosts() [Fact] public void ShouldShowLoading() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped>(_ => new SlowRepository()); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.FindComponents().Count.Should().Be(1); } @@ -82,10 +82,10 @@ public void ShouldShowLoading() [Fact] public void ShouldSetOgData() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); var ogData = cut.FindComponent().Instance; ogData.Title.Should().Contain("Archive"); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Home/IndexTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Home/IndexTests.cs index 54a19ebd..e6ceff65 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Home/IndexTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Home/IndexTests.cs @@ -20,10 +20,10 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst() var newestBlogPost = new BlogPostBuilder().WithTitle("New").Build(); await Repository.StoreAsync(oldestBlogPost); await Repository.StoreAsync(newestBlogPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement(".blog-card"); var blogPosts = cut.FindComponents(); @@ -40,10 +40,10 @@ public async Task ShouldOnlyShowPublishedPosts() var unpublishedPost = new BlogPostBuilder().WithTitle("Not published").IsPublished(false).Build(); await Repository.StoreAsync(publishedPost); await Repository.StoreAsync(unpublishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement(".blog-card"); var blogPosts = cut.FindComponents(); @@ -56,10 +56,10 @@ public async Task ShouldOnlyShowPublishedPosts() public async Task ShouldOnlyLoadTenEntities() { await CreatePublishedBlogPosts(11); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement(".blog-card"); var blogPosts = cut.FindComponents(); @@ -71,11 +71,11 @@ public async Task ShouldOnlyLoadTenEntities() public async Task ShouldLoadOnlyItemsInPage() { await CreatePublishedBlogPosts(11); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(s => s.Page, 2)); cut.WaitForElement(".blog-card"); @@ -92,10 +92,10 @@ public async Task ShouldLoadTags() .WithTags("C Sharp", "Tag2") .Build(); await Repository.StoreAsync(publishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForElement(".blog-card"); var tags = cut.FindComponent().FindAll(".goto-tag"); @@ -112,10 +112,10 @@ public async Task ShouldLoadTags() [InlineData("http://localhost/relative/url", "http://localhost/relative/url")] public void ShouldSetAbsoluteUriForOgData(string givenUri, string expectedUri) { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterComponents(ctx, givenUri); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.WaitForComponent().Instance.AbsolutePreviewImageUrl.Should().Be(expectedUri); } @@ -127,11 +127,11 @@ public void ShouldSetAbsoluteUriForOgData(string givenUri, string expectedUri) public async Task ShouldSetPageToFirstIfOutOfRange(int? page) { await CreatePublishedBlogPosts(11); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(p => p.Add( + var cut = ctx.Render(p => p.Add( i => i.Page, page)); cut.WaitForElement(".blog-card"); @@ -162,7 +162,7 @@ private async Task CreatePublishedBlogPosts(int amount) } } - private void RegisterComponents(TestContextBase ctx, string profilePictureUri = null) + private void RegisterComponents(BunitContext ctx, string profilePictureUri = null) { ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Options.Create(CreateSampleAppConfiguration(profilePictureUri).ApplicationConfiguration)); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Search/SearchPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Search/SearchPageTests.cs index d3171739..f6ff655a 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Search/SearchPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Search/SearchPageTests.cs @@ -18,10 +18,10 @@ public async Task ShouldFindBlogPostWhenTitleMatches() var blogPost2 = new BlogPostBuilder().WithTitle("Title 2").Build(); await Repository.StoreAsync(blogPost1); await Repository.StoreAsync(blogPost2); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterServices(ctx); - var cut = ctx.RenderComponent(p => p.Add(s => s.SearchTerm, "Title 1")); + var cut = ctx.Render(p => p.Add(s => s.SearchTerm, "Title 1")); var blogPosts = cut.WaitForComponent(); blogPosts.Find(".description h1").TextContent.Should().Be("Title 1"); @@ -34,10 +34,10 @@ public async Task ShouldFindBlogPostWhenTagMatches() var blogPost2 = new BlogPostBuilder().WithTitle("Title 2").WithTags("Dog").Build(); await Repository.StoreAsync(blogPost1); await Repository.StoreAsync(blogPost2); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterServices(ctx); - var cut = ctx.RenderComponent(p => p.Add(s => s.SearchTerm, "Cat")); + var cut = ctx.Render(p => p.Add(s => s.SearchTerm, "Cat")); var blogPost = cut.WaitForComponent(); blogPost.Find(".description h1").TextContent.Should().Be("Title 1"); @@ -48,16 +48,16 @@ public async Task ShouldUnescapeQuery() { var blogPost1 = new BlogPostBuilder().WithTitle("Title 1").Build(); await Repository.StoreAsync(blogPost1); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); RegisterServices(ctx); - var cut = ctx.RenderComponent(p => p.Add(s => s.SearchTerm, "Title%201")); + var cut = ctx.Render(p => p.Add(s => s.SearchTerm, "Title%201")); var blogPosts = cut.WaitForComponent(); blogPosts.Find(".description h1").TextContent.Should().Be("Title 1"); } - private void RegisterServices(TestContext ctx) + private void RegisterServices(BunitContext ctx) { ctx.Services.AddScoped(_ => Repository); } diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs index 12f9131e..7bd19058 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs @@ -15,13 +15,13 @@ public class SearchByTagTests : SqlDatabaseTestBase [Fact] public async Task ShouldOnlyDisplayTagsGivenByParameter() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); await AddBlogPostWithTagAsync("Tag 1"); await AddBlogPostWithTagAsync("Tag 1"); await AddBlogPostWithTagAsync("Tag 1", isPublished: false); await AddBlogPostWithTagAsync("Tag 2"); RegisterServices(ctx); - var cut = ctx.RenderComponent(p => p.Add(s => s.Tag, "Tag 1")); + var cut = ctx.Render(p => p.Add(s => s.Tag, "Tag 1")); cut.WaitForElement(".blog-card"); var tags = cut.FindAll(".blog-card"); @@ -32,10 +32,10 @@ public async Task ShouldOnlyDisplayTagsGivenByParameter() [Fact] public async Task ShouldHandleSpecialCharacters() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); await AddBlogPostWithTagAsync("C#"); RegisterServices(ctx); - var cut = ctx.RenderComponent(p => p.Add(s => s.Tag, Uri.EscapeDataString("C#"))); + var cut = ctx.Render(p => p.Add(s => s.Tag, Uri.EscapeDataString("C#"))); cut.WaitForElement(".blog-card"); var tags = cut.FindAll(".blog-card"); @@ -46,11 +46,11 @@ public async Task ShouldHandleSpecialCharacters() [Fact] public void ShouldSetTitleToTag() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); ctx.ComponentFactories.AddStub(); - var cut = ctx.RenderComponent(p => p.Add(s => s.Tag, "Tag")); + var cut = ctx.Render(p => p.Add(s => s.Tag, "Tag")); var pageTitleStub = cut.FindComponent(); var pageTitle = ctx.Render(pageTitleStub.Instance.ChildContent!); @@ -64,7 +64,7 @@ private async Task AddBlogPostWithTagAsync(string tag, bool isPublished = true) await DbContext.SaveChangesAsync(); } - private void RegisterServices(TestContext ctx) + private void RegisterServices(BunitContext ctx) { ctx.Services.AddScoped(_ => Repository); } diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs index cd5f1aec..0bd38c2a 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs @@ -21,14 +21,14 @@ public async Task ShouldAddLikeOnEvent() { var publishedPost = new BlogPostBuilder().WithLikes(2).IsPublished().Build(); await Repository.StoreAsync(publishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - ctx.AddTestAuthorization().SetAuthorized("s"); - var cut = ctx.RenderComponent( + ctx.AddAuthorization().SetAuthorized("s"); + var cut = ctx.Render( p => p.Add(b => b.BlogPostId, publishedPost.Id)); var likeComponent = cut.FindComponent(); - likeComponent.SetParametersAndRender(c => c.Add(p => p.BlogPost, publishedPost)); + likeComponent.Render(c => c.Add(p => p.BlogPost, publishedPost)); likeComponent.Find("span").Click(); @@ -41,18 +41,18 @@ public async Task ShouldSubtractLikeOnEvent() { var publishedPost = new BlogPostBuilder().WithLikes(2).IsPublished().Build(); await Repository.StoreAsync(publishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); var localStorage = Substitute.For(); var hasLikedStorage = $"hasLiked/{publishedPost.Id}"; localStorage.ContainKeyAsync(hasLikedStorage).Returns(true); localStorage.GetItemAsync(hasLikedStorage).Returns(true); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx, localStorage); - ctx.AddTestAuthorization().SetAuthorized("s"); - var cut = ctx.RenderComponent( + ctx.AddAuthorization().SetAuthorized("s"); + var cut = ctx.Render( p => p.Add(b => b.BlogPostId, publishedPost.Id)); var likeComponent = cut.FindComponent(); - likeComponent.SetParametersAndRender(c => c.Add(p => p.BlogPost, publishedPost)); + likeComponent.Render(c => c.Add(p => p.BlogPost, publishedPost)); likeComponent.Find("span").Click(); @@ -65,11 +65,11 @@ public async Task ShouldSetTagsWhenAvailable() { var publishedPost = new BlogPostBuilder().IsPublished().WithTags("Tag1,Tag2").Build(); await Repository.StoreAsync(publishedPost); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; - ctx.AddTestAuthorization(); + ctx.AddAuthorization(); RegisterComponents(ctx); - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(b => b.BlogPostId, publishedPost.Id)); var ogData = cut.FindComponent(); @@ -86,12 +86,12 @@ public async Task ShouldSetStructuredData() .WithPreviewImageUrlFallback("image2") .Build(); await Repository.StoreAsync(post); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; - ctx.AddTestAuthorization(); + ctx.AddAuthorization(); RegisterComponents(ctx); ctx.ComponentFactories.AddStub(ps => ps.Get(p => p.ChildContent)); - var cut = ctx.RenderComponent( + var cut = ctx.Render( p => p.Add(b => b.BlogPostId, post.Id)); var structuredData = cut.FindComponent(); @@ -104,17 +104,17 @@ public async Task ShouldSetStructuredData() [Fact] public void ShouldShowErrorPageWhenBlogPostNotFound() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; RegisterComponents(ctx); - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); cut.FindAll(".blogpost-content").Should().HaveCount(0); cut.FindAll("#no-blog-post-error").Should().HaveCount(1); } - private void RegisterComponents(TestContextBase ctx, ILocalStorageService localStorageService = null) + private void RegisterComponents(BunitContext ctx, ILocalStorageService localStorageService = null) { ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => localStorageService ?? Substitute.For()); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs index 69e716ef..50983c38 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Admin/BlogPostAdminActionsTests.cs @@ -15,11 +15,11 @@ public async Task ShouldDeleteBlogPostWhenOkClicked() { const string blogPostId = "2"; var repositoryMock = Substitute.For>(); - using var ctx = new TestContext(); - ctx.AddTestAuthorization().SetAuthorized("s"); + using var ctx = new BunitContext(); + ctx.AddAuthorization().SetAuthorized("s"); ctx.Services.AddSingleton(repositoryMock); ctx.Services.AddSingleton(Substitute.For()); - var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + var cut = ctx.Render(s => s.Add(p => p.BlogPostId, blogPostId)); cut.Find("#delete-blogpost").Click(); cut.Find("#ok").Click(); @@ -32,11 +32,11 @@ public async Task ShouldNotDeleteBlogPostWhenCancelClicked() { const string blogPostId = "2"; var repositoryMock = Substitute.For>(); - using var ctx = new TestContext(); - ctx.AddTestAuthorization().SetAuthorized("s"); + using var ctx = new BunitContext(); + ctx.AddAuthorization().SetAuthorized("s"); ctx.Services.AddSingleton(repositoryMock); ctx.Services.AddSingleton(Substitute.For()); - var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + var cut = ctx.Render(s => s.Add(p => p.BlogPostId, blogPostId)); cut.Find("#delete-blogpost").Click(); cut.Find("#cancel").Click(); @@ -49,12 +49,12 @@ public void ShouldGoToEditPageOnEditClick() { const string blogPostId = "2"; var repositoryMock = Substitute.For>(); - using var ctx = new TestContext(); - ctx.AddTestAuthorization().SetAuthorized("s"); + using var ctx = new BunitContext(); + ctx.AddAuthorization().SetAuthorized("s"); ctx.Services.AddSingleton(repositoryMock); ctx.Services.AddSingleton(Substitute.For()); var navigationManager = ctx.Services.GetRequiredService(); - var cut = ctx.RenderComponent(s => s.Add(p => p.BlogPostId, blogPostId)); + var cut = ctx.Render(s => s.Add(p => p.BlogPostId, blogPostId)); cut.Find("#edit-blogpost").Click(); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs index d9127733..20a8c959 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ConfirmDialogTests.cs @@ -8,8 +8,8 @@ public class ConfirmDialogTests public void ShouldInvokeEventOnOkClick() { var okWasClicked = false; - using var ctx = new TestContext(); - var cut = ctx.RenderComponent( + using var ctx = new BunitContext(); + var cut = ctx.Render( b => b .Add(p => p.OnYesPressed, _ => okWasClicked = true)); cut.Instance.Open(); diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs index cae50eb6..fa6a531c 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs @@ -9,7 +9,7 @@ namespace LinkDotNet.Blog.IntegrationTests.Web.Shared; -public class NavMenuTests : TestContext +public class NavMenuTests : BunitContext { public NavMenuTests() { @@ -20,9 +20,9 @@ public NavMenuTests() public void ShouldNavigateToSearchPage() { Services.AddScoped(_ => Options.Create(new ApplicationConfiguration())); - this.AddTestAuthorization(); + this.AddAuthorization(); var navigationManager = Services.GetRequiredService(); - var cut = RenderComponent(); + var cut = Render(); cut.FindComponent().Find("input").Change("Text"); cut.FindComponent().Find("button").Click(); @@ -38,9 +38,9 @@ public void ShouldDisplayAboutMePage() IsAboutMeEnabled = true }); Services.AddScoped(_ => config); - this.AddTestAuthorization(); + this.AddAuthorization(); - var cut = RenderComponent(); + var cut = Render(); cut .FindAll(".nav-link").ToList() @@ -53,8 +53,8 @@ public void ShouldPassCorrectUriToComponent() { var config = Options.Create(new ProfileInformation()); Services.AddScoped(_ => config); - this.AddTestAuthorization(); - var cut = RenderComponent(); + this.AddAuthorization(); + var cut = Render(); Services.GetRequiredService().NavigateTo("test"); @@ -73,9 +73,9 @@ public void ShouldShowBrandImageIfAvailable() var profileInfoConfig = Options.Create(new ProfileInformation()); Services.AddScoped(_ => profileInfoConfig); - this.AddTestAuthorization(); + this.AddAuthorization(); - var cut = RenderComponent(); + var cut = Render(); var brandImage = cut.Find(".nav-brand img"); var image = brandImage as IHtmlImageElement; @@ -98,9 +98,9 @@ public void ShouldShowBlogNameWhenNotBrand(string brandUrl) var profileInfoConfig = Options.Create(new ProfileInformation()); Services.AddScoped(_ => profileInfoConfig); - this.AddTestAuthorization(); + this.AddAuthorization(); - var cut = RenderComponent(); + var cut = Render(); var brandImage = cut.Find(".nav-brand"); var image = brandImage as IHtmlAnchorElement; diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ProfileTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ProfileTests.cs index 3ac6b701..74c3c1b3 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ProfileTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/ProfileTests.cs @@ -12,7 +12,7 @@ namespace LinkDotNet.Blog.IntegrationTests.Web.Shared; -public class ProfileTests : TestContext +public class ProfileTests : BunitContext { [Fact] public void ShouldRenderAllItemsSortedByOrder() @@ -177,11 +177,11 @@ private static void SetupGetAll( return (repoMock, calcMock); } - private IRenderedComponent RenderProfileWithEmptyInformation() - => RenderComponent(p => p.Add(s => s.ProfileInformation, new())); + private RenderedComponent RenderProfileWithEmptyInformation() + => Render(p => p.Add(s => s.ProfileInformation, new())); - private IRenderedComponent RenderProfileInAdmin() - => RenderComponent(p => p + private RenderedComponent RenderProfileInAdmin() + => Render(p => p .Add(s => s.ProfileInformation, new()) .Add(s => s.ShowAdminActions, true)); } diff --git a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Skills/SkillTableTests.cs b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Skills/SkillTableTests.cs index 66daa331..085c411a 100644 --- a/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Skills/SkillTableTests.cs +++ b/tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/Skills/SkillTableTests.cs @@ -15,11 +15,11 @@ public class SkillTableTests : SqlDatabaseTestBase public async Task ShouldDeleteItem() { var skill = new SkillBuilder().WithSkillName("C#").Build(); - using var ctx = new TestContext(); + using var ctx = new BunitContext(); await Repository.StoreAsync(skill); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - var cut = ctx.RenderComponent(p => + var cut = ctx.Render(p => p.Add(s => s.ShowAdminActions, true)); cut.WaitForComponent().Find("button").Click(); @@ -32,10 +32,10 @@ public async Task ShouldDeleteItem() [Fact] public async Task ShouldAddSkill() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - var cut = ctx.RenderComponent(p => + var cut = ctx.Render(p => p.Add(s => s.ShowAdminActions, true)); cut.Find("button").Click(); var dialog = cut.FindComponent(); @@ -58,13 +58,13 @@ public async Task ShouldAddSkill() [Fact] public async Task ShouldNotAllowToEditSkillTagsWhenNotAdmin() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); var skill = new SkillBuilder().Build(); await Repository.StoreAsync(skill); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - var cut = ctx.RenderComponent(p => + var cut = ctx.Render(p => p.Add(s => s.ShowAdminActions, false)); cut.WaitForComponent().Instance.ShowAdminActions.Should().BeFalse(); @@ -73,13 +73,13 @@ public async Task ShouldNotAllowToEditSkillTagsWhenNotAdmin() [Fact] public async Task ShouldUpdateProficiencyWhenSkillTagDragged() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); var skill = new SkillBuilder().WithProficiencyLevel(ProficiencyLevel.Familiar).Build(); await DbContext.AddAsync(skill); await DbContext.SaveChangesAsync(); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - var cut = ctx.RenderComponent(p => + var cut = ctx.Render(p => p.Add(s => s.ShowAdminActions, true)); cut.WaitForElement(".skill-tag"); @@ -93,13 +93,13 @@ public async Task ShouldUpdateProficiencyWhenSkillTagDragged() [Fact] public async Task ShouldStayOnSameProficiencyWhenDroppedOnSameProficiencyLevel() { - using var ctx = new TestContext(); + using var ctx = new BunitContext(); var skill = new SkillBuilder().WithProficiencyLevel(ProficiencyLevel.Familiar).Build(); await DbContext.AddAsync(skill); await DbContext.SaveChangesAsync(); ctx.Services.AddScoped(_ => Repository); ctx.Services.AddScoped(_ => Substitute.For()); - var cut = ctx.RenderComponent(p => + var cut = ctx.Render(p => p.Add(s => s.ShowAdminActions, true)); cut.WaitForElement(".skill-tag"); diff --git a/tests/LinkDotNet.Blog.TestUtilities/BunitExtensions.cs b/tests/LinkDotNet.Blog.TestUtilities/BunitExtensions.cs index 561627c2..22ad1afb 100644 --- a/tests/LinkDotNet.Blog.TestUtilities/BunitExtensions.cs +++ b/tests/LinkDotNet.Blog.TestUtilities/BunitExtensions.cs @@ -6,14 +6,14 @@ namespace LinkDotNet.Blog.TestUtilities; public static class BunitExtensions { - public static IRenderedComponent WaitForComponent(this IRenderedFragment component) + public static RenderedComponent WaitForComponent(this RenderedFragment component) where TComponent : IComponent { component.WaitForState(component.HasComponent); return component.FindComponent(); } - public static IReadOnlyList> WaitForComponents(this IRenderedFragment component) + public static IReadOnlyList> WaitForComponents(this RenderedFragment component) where TComponent : IComponent { component.WaitForState(component.HasComponent); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/AboutMePageTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/AboutMePageTests.cs index 7cd9e0b5..d9966085 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/AboutMePageTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/AboutMePageTests.cs @@ -13,12 +13,12 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.AboutMe; -public class AboutMePageTests : TestContext +public class AboutMePageTests : BunitContext { [Fact] public void ShouldPassIsAuthenticated() { - this.AddTestAuthorization().SetAuthorized("test"); + AddAuthorization().SetAuthorized("test"); var config = new ProfileInformation { ProfilePictureUrl = string.Empty }; var applicationConfiguration = new ApplicationConfiguration @@ -28,7 +28,7 @@ public void ShouldPassIsAuthenticated() SetupMocks(config, applicationConfiguration); - var cut = RenderComponent(); + var cut = Render(); cut.FindComponent().Instance.ShowAdminActions.Should().BeTrue(); cut.FindComponent().Instance.ShowAdminActions.Should().BeTrue(); @@ -38,7 +38,7 @@ public void ShouldPassIsAuthenticated() [Fact] public void ShouldNotShowWhenEnabledFalse() { - this.AddTestAuthorization().SetNotAuthorized(); + this.AddAuthorization().SetNotAuthorized(); var config = new ProfileInformation(); var applicationConfiguration = new ApplicationConfiguration @@ -48,7 +48,7 @@ public void ShouldNotShowWhenEnabledFalse() SetupMocks(config, applicationConfiguration); - var cut = RenderComponent(); + var cut = Render(); cut.FindComponents().Any().Should().BeFalse(); cut.FindComponents().Any().Should().BeFalse(); @@ -57,7 +57,7 @@ public void ShouldNotShowWhenEnabledFalse() [Fact] public void ShouldSetOgData() { - this.AddTestAuthorization().SetNotAuthorized(); + this.AddAuthorization().SetNotAuthorized(); var profileInformation = new ProfileInformation { Name = "My Name", @@ -69,7 +69,7 @@ public void ShouldSetOgData() }; SetupMocks(profileInformation, applicationConfiguration); - var cut = RenderComponent(); + var cut = Render(); var ogData = cut.FindComponent().Instance; ogData.AbsolutePreviewImageUrl.Should().Be("http://localhost/someurl"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddProfileShortItemTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddProfileShortItemTests.cs index a8a4cbfc..cd0799ab 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddProfileShortItemTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddProfileShortItemTests.cs @@ -2,13 +2,13 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.AboutMe.Components; -public class AddProfileShortItemTests : TestContext +public class AddProfileShortItemTests : BunitContext { [Fact] public void ShouldAddShortItem() { string addedItem = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.ValueAdded, c => addedItem = c)); cut.Find("input").Change("Key"); @@ -24,7 +24,7 @@ public void ShouldAddShortItem() public void ShouldNotAddItemWhenKeyOrValueIsEmpty(string content) { var wasInvoked = false; - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.ValueAdded, _ => wasInvoked = true)); cut.Find("input").Change(content); @@ -36,7 +36,7 @@ public void ShouldNotAddItemWhenKeyOrValueIsEmpty(string content) [Fact] public void ShouldEmptyModelAfterTextEntered() { - var cut = RenderComponent(); + var cut = Render(); cut.Find("input").Change("Key"); cut.Find("button").Click(); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddSkillDialogTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddSkillDialogTests.cs index 13969806..12c291f2 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddSkillDialogTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/AddSkillDialogTests.cs @@ -5,7 +5,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.AboutMe.Components; -public class AddSkillDialogTests : TestContext +public class AddSkillDialogTests : BunitContext { [Fact] public void ShouldCreateSkill() @@ -13,7 +13,7 @@ public void ShouldCreateSkill() Skill addedSkill = null; var toastServiceMock = Substitute.For(); Services.AddScoped(_ => toastServiceMock); - var cut = RenderComponent(p => + var cut = Render(p => p.Add(s => s.SkillAdded, t => addedSkill = t)); cut.Find("#title").Change("C#"); cut.Find("#image").Change("Url"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/SkillTagTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/SkillTagTests.cs index 3a2b2a39..d1dc1001 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/SkillTagTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/AboutMe/Components/SkillTagTests.cs @@ -4,14 +4,14 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.AboutMe.Components; -public class SkillTagTests : TestContext +public class SkillTagTests : BunitContext { [Fact] public void ShouldRenderImageAndText() { var skill = new SkillBuilder().WithSkillName("C#").WithIconUrl("test").Build(); - var cut = RenderComponent(p => p.Add( + var cut = Render(p => p.Add( s => s.Skill, skill)); cut.Find("span").TextContent.Should().Contain("C#"); @@ -24,7 +24,7 @@ public void ShouldNotRenderImageWhenNotAvailable() { var skill = new SkillBuilder().WithIconUrl(null).Build(); - var cut = RenderComponent(p => p.Add( + var cut = Render(p => p.Add( s => s.Skill, skill)); cut.FindAll("img").Should().HaveCount(0); @@ -35,7 +35,7 @@ public void ShouldInvokeDeleteEvent() { var skill = new SkillBuilder().Build(); var wasInvoked = false; - var cut = RenderComponent(p => p + var cut = Render(p => p .Add( s => s.Skill, skill) .Add(s => s.ShowAdminActions, true) diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPostTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPostTests.cs index 4ecb2dfe..d3bf3cfb 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPostTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPostTests.cs @@ -9,7 +9,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.BlogPostEditor.Components; -public class CreateNewBlogPostTests : TestContext +public class CreateNewBlogPostTests : BunitContext { public CreateNewBlogPostTests() { @@ -21,7 +21,7 @@ public CreateNewBlogPostTests() public void ShouldCreateNewBlogPostWhenValidDataGiven() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPost = bp)); cut.Find("#title").Input("My Title"); cut.Find("#short").Input("My short Description"); @@ -56,7 +56,7 @@ public void ShouldFillGivenBlogPost() .WithTags("tag1", "tag2") .Build(); BlogPost blogPostFromComponent = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPostFromComponent = bp) .Add(c => c.BlogPost, blogPost)); @@ -76,7 +76,7 @@ public void ShouldFillGivenBlogPost() public void ShouldNotDeleteModelWhenSet() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.ClearAfterCreated, true) .Add(c => c.OnBlogPostCreated, post => blogPost = post)); cut.Find("#title").Input("My Title"); @@ -96,7 +96,7 @@ public void ShouldNotDeleteModelWhenSet() public void ShouldNotDeleteModelWhenNotSet() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.ClearAfterCreated, false) .Add(c => c.OnBlogPostCreated, post => blogPost = post)); cut.Find("#title").Input("My Title"); @@ -118,7 +118,7 @@ public void ShouldNotUpdateUpdatedDateWhenCheckboxSet() var someWhen = new DateTime(1991, 5, 17); var originalBlogPost = new BlogPostBuilder().WithUpdatedDate(someWhen).Build(); BlogPost blogPostFromComponent = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPostFromComponent = bp) .Add(c => c.BlogPost, originalBlogPost)); @@ -137,7 +137,7 @@ public void ShouldNotUpdateUpdatedDateWhenCheckboxSet() [Fact] public void ShouldNotSetOptionToNotUpdateUpdatedDateOnInitialCreate() { - var cut = RenderComponent(); + var cut = Render(); var found = cut.FindAll("#updatedate"); @@ -148,7 +148,7 @@ public void ShouldNotSetOptionToNotUpdateUpdatedDateOnInitialCreate() public void ShouldAcceptInputWithoutLosingFocusOrEnter() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPost = bp)); cut.Find("#title").Input("My Title"); cut.Find("#short").Input("My short Description"); @@ -173,7 +173,7 @@ public void ShouldAcceptInputWithoutLosingFocusOrEnter() [Fact] public void ShouldStopExternalNavigationWhenDirty() { - var cut = RenderComponent(); + var cut = Render(); cut.Find("#title").Input("Hey"); @@ -185,9 +185,9 @@ public void ShouldStopInternalNavigationWhenDirty() { JSInterop.Setup("confirm", "You have unsaved changes. Are you sure you want to continue?") .SetResult(false); - var cut = RenderComponent(); + var cut = Render(); cut.Find("#tags").Change("Hey"); - var fakeNavigationManager = Services.GetRequiredService(); + var fakeNavigationManager = Services.GetRequiredService(); fakeNavigationManager.NavigateTo("/internal"); @@ -199,9 +199,9 @@ public void ShouldStopInternalNavigationWhenDirty() public void ShouldNotBlogNavigationOnInitialLoad() { var blogPost = new BlogPostBuilder().Build(); - RenderComponent( + Render( p => p.Add(s => s.BlogPost, blogPost)); - var fakeNavigationManager = Services.GetRequiredService(); + var fakeNavigationManager = Services.GetRequiredService(); fakeNavigationManager.NavigateTo("/internal"); @@ -213,7 +213,7 @@ public void ShouldNotBlogNavigationOnInitialLoad() public void GivenBlogPostWithSchedule_ShouldSetSchedule() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPost = bp)); cut.Find("#title").Input("My Title"); cut.Find("#short").Input("My short Description"); @@ -231,7 +231,7 @@ public void GivenBlogPostWithSchedule_ShouldSetSchedule() public void GivenBlogPost_WhenEnteringScheduledDate_ThenIsPublishedSetToFalse() { BlogPost blogPost = null; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.OnBlogPostCreated, bp => blogPost = bp)); cut.Find("#title").Input("My Title"); cut.Find("#short").Input("My short Description"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/UploadFileTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/UploadFileTests.cs index eb11564e..ee4b1f6e 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/UploadFileTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/UploadFileTests.cs @@ -6,7 +6,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.BlogPostEditor.Components; -public class UploadFileTests : TestContext +public class UploadFileTests : BunitContext { public UploadFileTests() { @@ -27,7 +27,7 @@ public async Task ShouldCallProcessorWhenFilesUploaded() file, }); Services.AddScoped(_ => fileProcessor); - var cut = RenderComponent( + var cut = Render( s => s.Add(p => p.OnFileUploaded, f => invokedContent = f)); var inputComponent = cut.FindComponent().Instance; @@ -40,7 +40,7 @@ public async Task ShouldCallProcessorWhenFilesUploaded() public void ShouldIndicateDragAndDropBehavior() { Services.AddScoped(_ => Substitute.For()); - var cut = RenderComponent(); + var cut = Render(); cut.Find("input").DragEnter(); @@ -51,7 +51,7 @@ public void ShouldIndicateDragAndDropBehavior() public void ShouldRemoveDragAndDropBehaviorWhenOutside() { Services.AddScoped(_ => Substitute.For()); - var cut = RenderComponent(); + var cut = Render(); cut.Find("input").DragEnter(); cut.Find("input").DragLeave(); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Dashboard/Components/DateRangeSelectorTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Dashboard/Components/DateRangeSelectorTests.cs index 9753f089..2b4947eb 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Dashboard/Components/DateRangeSelectorTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Dashboard/Components/DateRangeSelectorTests.cs @@ -3,13 +3,13 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.Dashboard.Components; -public class DateRangeSelectorTests : TestContext +public class DateRangeSelectorTests : BunitContext { [Fact] public void ShouldSetBeginDateWhenSet() { Filter filter = null; - var cut = RenderComponent(p => p.Add(s => s.FilterChanged, f => + var cut = Render(p => p.Add(s => s.FilterChanged, f => { filter = f; })); @@ -25,7 +25,7 @@ public void ShouldSetBeginDateWhenSet() public void ShouldSetEndDateWhenSet() { Filter filter = null; - var cut = RenderComponent(p => p.Add(s => s.FilterChanged, f => + var cut = Render(p => p.Add(s => s.FilterChanged, f => { filter = f; })); @@ -41,7 +41,7 @@ public void ShouldSetEndDateWhenSet() public void ShouldReset() { Filter filter = null; - var cut = RenderComponent(p => p.Add(s => s.FilterChanged, f => + var cut = Render(p => p.Add(s => s.FilterChanged, f => { filter = f; })); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings/SettingsPageTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings/SettingsPageTests.cs index f2aac34f..2d93aa10 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings/SettingsPageTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Settings/SettingsPageTests.cs @@ -7,7 +7,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.Settings; -public class SettingsPageTests : TestContext +public class SettingsPageTests : BunitContext { [Fact] public void GivenSettingsPage_WhenClicking_InvalidateCacheButton_TokenIsCancelled() @@ -16,7 +16,7 @@ public void GivenSettingsPage_WhenClicking_InvalidateCacheButton_TokenIsCancelle Services.AddScoped(_ => cacheInvalidator); Services.AddScoped(_ => Options.Create(new())); Services.AddScoped(_ => Substitute.For()); - var cut = RenderComponent(); + var cut = Render(); var invalidateCacheButton = cut.Find("#invalidate-cache"); invalidateCacheButton.Click(); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/Services/SitemapServiceTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/Services/SitemapServiceTests.cs index fce443e3..ca55f7dc 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/Services/SitemapServiceTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/Services/SitemapServiceTests.cs @@ -9,17 +9,17 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.Sitemap.Services; -public class SitemapServiceTests : TestContext +public class SitemapServiceTests : BunitContext { private readonly IRepository repositoryMock; private readonly IXmlFileWriter xmlFileWriterMock; private readonly SitemapService sut; - private readonly FakeNavigationManager fakeNavigationManager; + private readonly BunitNavigationManager fakeNavigationManager; public SitemapServiceTests() { repositoryMock = Substitute.For>(); - fakeNavigationManager = new FakeNavigationManager(Renderer); + fakeNavigationManager = new BunitNavigationManager(this); xmlFileWriterMock = Substitute.For(); sut = new SitemapService( diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/SitemapPageTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/SitemapPageTests.cs index 79b33827..db74b33c 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/SitemapPageTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/Sitemap/SitemapPageTests.cs @@ -8,17 +8,17 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Admin.Sitemap; -public class SitemapPageTests : TestContext +public class SitemapPageTests : BunitContext { [Fact] public async Task ShouldSaveSitemap() { - this.AddTestAuthorization().SetAuthorized("steven"); + this.AddAuthorization().SetAuthorized("steven"); var sitemapMock = Substitute.For(); Services.AddScoped(_ => sitemapMock); var sitemap = new SitemapUrlSet(); sitemapMock.CreateSitemapAsync().Returns(sitemap); - var cut = RenderComponent(); + var cut = Render(); cut.Find("button").Click(); @@ -28,7 +28,7 @@ public async Task ShouldSaveSitemap() [Fact] public void ShouldDisplaySitemap() { - this.AddTestAuthorization().SetAuthorized("steven"); + this.AddAuthorization().SetAuthorized("steven"); var sitemapMock = Substitute.For(); Services.AddScoped(_ => sitemapMock); var sitemap = new SitemapUrlSet @@ -39,7 +39,7 @@ public void ShouldDisplaySitemap() }, }; sitemapMock.CreateSitemapAsync().Returns(sitemap); - var cut = RenderComponent(); + var cut = Render(); cut.Find("button").Click(); @@ -51,7 +51,7 @@ public void ShouldDisplaySitemap() [Fact] public void ShouldShowLoadingWhenGenerating() { - this.AddTestAuthorization().SetAuthorized("steven"); + this.AddAuthorization().SetAuthorized("steven"); var sitemapMock = Substitute.For(); Services.AddScoped(_ => sitemapMock); var sitemap = new SitemapUrlSet @@ -67,7 +67,7 @@ public void ShouldShowLoadingWhenGenerating() return sitemap; })); - var cut = RenderComponent(); + var cut = Render(); cut.Find("button").Click(); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/OgDataTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/OgDataTests.cs index cbc818f9..484aa363 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/OgDataTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/OgDataTests.cs @@ -7,14 +7,14 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Components; -public class OgDataTests : TestContext +public class OgDataTests : BunitContext { [Fact] public void ShouldRenderMetaTagsWhenSet() { ComponentFactories.AddStub(ps => ps.Get(p => p.ChildContent)); - var cut = RenderComponent(p => p + var cut = Render(p => p .Add(s => s.Title, "Title") .Add(s => s.Description, "Description") .Add(s => s.AbsolutePreviewImageUrl, "http://localhost/image.png") @@ -31,7 +31,7 @@ public void ShouldNotSetMetaInformationWhenNotProvided() { ComponentFactories.AddStub(ps => ps.Get(p => p.ChildContent)); - var cut = RenderComponent(p => p + var cut = Render(p => p .Add(s => s.Title, "Title")); GetMetaTagExists(cut, "image").Should().BeFalse(); @@ -46,7 +46,7 @@ public void ShouldSetCanoncialLink() Services.GetRequiredService().NavigateTo(expectedUri); ComponentFactories.AddStub(ps => ps.Get(p => p.ChildContent)); - var cut = RenderComponent(p => p + var cut = Render(p => p .Add(s => s.Title, "Title")); var link = cut.FindAll("link").FirstOrDefault(l => l.Attributes.Any(a => a.Name == "rel" && a.Value == "canonical")) as IHtmlLinkElement; @@ -60,7 +60,7 @@ public void ShouldSetCanoncialLinkWithoutQueryParameter() ComponentFactories.AddStub(ps => ps.Get(p => p.ChildContent)); Services.GetRequiredService().NavigateTo("https://localhost.com/site?query=2"); - var cut = RenderComponent(p => p + var cut = Render(p => p .Add(s => s.Title, "Title")); var link = cut.FindAll("link").FirstOrDefault(l => l.Attributes.Any(a => a.Name == "rel" && a.Value == "canonical")) as IHtmlLinkElement; @@ -68,7 +68,7 @@ public void ShouldSetCanoncialLinkWithoutQueryParameter() } private static void AssertMetaTagExistsWithValue( - IRenderedFragment cut, + RenderedFragment cut, string metaTag, string metaTagValue, string ogPropertyName = null) @@ -85,7 +85,7 @@ private static void AssertMetaTagExistsWithValue( } private static bool GetMetaTagExists( - IRenderedFragment cut, + RenderedFragment cut, string metaTag) { var metaTags = cut.FindAll("meta"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/PreviewImageTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/PreviewImageTests.cs index 1a69ae27..e8e9325a 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/PreviewImageTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/PreviewImageTests.cs @@ -4,12 +4,12 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Components; -public class PreviewImageTests : TestContext +public class PreviewImageTests : BunitContext { [Fact] public void ShouldOfferImageWhenProvided() { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/") .Add(p => p.PreviewImageUrlFallback, "http://fallback.png/")); @@ -26,7 +26,7 @@ public void ShouldOfferImageWhenProvided() [Fact] public void ShouldOfferOnlyImageWhenNoFallbackProvided() { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/")); var image = cut.Find("img") as IHtmlImageElement; @@ -40,7 +40,7 @@ public void ShouldOfferOnlyImageWhenNoFallbackProvided() [InlineData(false, "eager")] public void ShouldSetLazyLoadBehavior(bool lazyLoad, string expectedLazy) { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/") .Add(p => p.PreviewImageUrlFallback, "http://fallback.png/") .Add(p => p.LazyLoadImage, lazyLoad)); @@ -57,7 +57,7 @@ public void ShouldSetLazyLoadBehavior(bool lazyLoad, string expectedLazy) [InlineData(false, "eager")] public void ShouldSetLazyLoadBehaviorNoFallback(bool lazyLoad, string expectedLazy) { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/") .Add(p => p.LazyLoadImage, lazyLoad)); @@ -72,7 +72,7 @@ public void ShouldSetLazyLoadBehaviorNoFallback(bool lazyLoad, string expectedLa [InlineData("http://localhost/image.avif", "image/avif")] public void ShouldDetectFileTypes(string fileName, string mimeType) { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, fileName) .Add(p => p.PreviewImageUrlFallback, "not empty")); @@ -87,7 +87,7 @@ public void ShouldDetectFileTypes(string fileName, string mimeType) [InlineData(false, "auto")] public void ShouldSetDecodingBehavior(bool lazyLoad, string expectedBehaviour) { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/") .Add(p => p.PreviewImageUrlFallback, "http://fallback.png/") .Add(p => p.LazyLoadImage, lazyLoad)); @@ -104,7 +104,7 @@ public void ShouldSetDecodingBehavior(bool lazyLoad, string expectedBehaviour) [InlineData(false, "auto")] public void ShouldSetDecodingBehaviorNoFallback(bool lazyLoad, string expectedBehaviour) { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.PreviewImageUrl, "http://image.png/") .Add(p => p.LazyLoadImage, lazyLoad)); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/ShortBlogPostTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/ShortBlogPostTests.cs index c913b7b1..90e25394 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/ShortBlogPostTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/ShortBlogPostTests.cs @@ -5,14 +5,14 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Components; -public class ShortBlogPostTests : TestContext +public class ShortBlogPostTests : BunitContext { [Fact] public void ShouldOpenBlogPost() { var blogPost = new BlogPostBuilder().Build(); blogPost.Id = "SomeId"; - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); var readMore = cut.Find(".read-more a"); @@ -24,7 +24,7 @@ public void ShouldOpenBlogPost() public void ShouldNavigateToEscapedTagSiteWhenClickingOnTag() { var blogPost = new BlogPostBuilder().WithTags("Tag 1").Build(); - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); var searchByTagLink = cut.Find(".goto-tag"); @@ -37,7 +37,7 @@ public void WhenNoTagsAreGivenThenTagsAreNotShown() { var blogPost = new BlogPostBuilder().Build(); - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); cut.FindAll(".goto-tag").Should().BeEmpty(); @@ -49,7 +49,7 @@ public void GivenBlogPostThatIsScheduled_ThenIndicating() var blogPost = new BlogPostBuilder().IsPublished(false).WithScheduledPublishDate(new DateTime(2099, 1, 1)) .Build(); - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); cut.Find(".schedule").Should().NotBeNull(); @@ -60,7 +60,7 @@ public void GivenBlogPostThatIsNotPublishedAndNotScheduled_ThenIndicating() { var blogPost = new BlogPostBuilder().IsPublished(false).Build(); - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); cut.Find(".draft").Should().NotBeNull(); @@ -71,7 +71,7 @@ public void GivenBlogPostThatIsPublished_ThenNoDraft() { var blogPost = new BlogPostBuilder().IsPublished(true).Build(); - var cut = RenderComponent( + var cut = Render( p => p.Add(c => c.BlogPost, blogPost)); cut.FindAll(".draft").Should().BeEmpty(); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/TextAreaWithShortcutsTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/TextAreaWithShortcutsTests.cs index a73d559c..5da769d3 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/TextAreaWithShortcutsTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Components/TextAreaWithShortcutsTests.cs @@ -3,7 +3,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Components; -public class TextAreaWithShortcutsTests : TestContext +public class TextAreaWithShortcutsTests : BunitContext { [Theory] [InlineData("b", 0, 4, true, "**Test**")] @@ -23,7 +23,7 @@ public void ShouldSetMarkerOnKeyUp(string key, int start, int end, bool ctrlPres }; JSInterop.Mode = JSRuntimeMode.Loose; JSInterop.Setup("getSelectionFromElement", id).SetResult(range); - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.Id, id)); cut.Find("textarea").Input("Test"); cut.Find("textarea").KeyUp(key, ctrlKey: ctrlPressed); @@ -40,7 +40,7 @@ public void ShouldSetCursorPosition() JSInterop.Mode = JSRuntimeMode.Loose; JSInterop.Setup("getSelectionFromElement", element) .SetResult(new SelectionRange { Start = 2, End = 5 }); - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.Id, element)); cut.Find($"#{element}").Input("Hello World"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AccessControlTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AccessControlTests.cs index 6b80293f..024b0cfb 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AccessControlTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AccessControlTests.cs @@ -3,14 +3,14 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Home.Components; -public class AccessControlTests : TestContext +public class AccessControlTests : BunitContext { [Fact] public void ShouldShowLoginAndHideAdminWhenNotLoggedIn() { - this.AddTestAuthorization(); + this.AddAuthorization(); - var cut = RenderComponent(); + var cut = Render(); cut.FindAll("a:contains('Admin')").Should().HaveCount(0); cut.FindAll("a:contains('Log in')").Should().HaveCount(1); @@ -19,9 +19,9 @@ public void ShouldShowLoginAndHideAdminWhenNotLoggedIn() [Fact] public void ShouldShowLogoutAndAdminWhenLoggedIn() { - this.AddTestAuthorization().SetAuthorized("steven"); + this.AddAuthorization().SetAuthorized("steven"); - var cut = RenderComponent(); + var cut = Render(); cut.FindAll("a:contains('Admin')").Should().HaveCount(1); cut.FindAll("a:contains('Log out')").Should().HaveCount(1); @@ -31,9 +31,9 @@ public void ShouldShowLogoutAndAdminWhenLoggedIn() public void LoginShouldHaveCurrentUriAsRedirectUri() { const string currentUri = "http://localhost/test"; - this.AddTestAuthorization(); + this.AddAuthorization(); - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.CurrentUri, currentUri)); ((IHtmlAnchorElement)cut.Find("a:contains('Log in')")).Href.Should().Contain(currentUri); @@ -43,9 +43,9 @@ public void LoginShouldHaveCurrentUriAsRedirectUri() public void LogoutShouldHaveCurrentUriAsRedirectUri() { const string currentUri = "http://localhost/test"; - this.AddTestAuthorization().SetAuthorized("steven"); + this.AddAuthorization().SetAuthorized("steven"); - var cut = RenderComponent( + var cut = Render( p => p.Add(s => s.CurrentUri, currentUri)); ((IHtmlAnchorElement)cut.Find("a:contains('Log out')")).Href.Should().Contain(currentUri); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AnchorTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AnchorTests.cs index ca1c52a1..94af5443 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AnchorTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/AnchorTests.cs @@ -4,12 +4,12 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Home.Components; -public class AnchorTests : TestContext +public class AnchorTests : BunitContext { [Fact] public void ShouldShowHrefWhenNotEmpty() { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.Href, "http://url/") .Add(p => p.CssClass, "page")); @@ -22,7 +22,7 @@ public void ShouldShowHrefWhenNotEmpty() [Fact] public void ShouldNotShowHrefWhenEmpty() { - var cut = RenderComponent(ps => ps + var cut = Render(ps => ps .Add(p => p.Href, string.Empty) .Add(p => p.CssClass, "page")); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/BlogPostNavigationTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/BlogPostNavigationTests.cs index 6efa4792..a0d645db 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/BlogPostNavigationTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/BlogPostNavigationTests.cs @@ -6,14 +6,14 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Home.Components; -public class BlogPostNavigationTests : TestContext +public class BlogPostNavigationTests : BunitContext { [Fact] public void ShouldFireEventWhenGoingToNextPage() { var page = CreatePagedList(2, 3); - var cut = RenderComponent>(p => + var cut = Render>(p => p.Add(param => param.PageList, page)); cut.FindAll("a").Cast().Last().Href.Should().EndWith("/3"); @@ -24,7 +24,7 @@ public void ShouldFireEventWhenGoingToPreviousPage() { var page = CreatePagedList(2, 3); - var cut = RenderComponent>(p => + var cut = Render>(p => p.Add(param => param.PageList, page)); cut.FindAll("a").Cast().First().Href.Should().EndWith("/1"); @@ -34,7 +34,7 @@ public void ShouldFireEventWhenGoingToPreviousPage() public void ShouldNotFireNextWhenOnLastPage() { var page = CreatePagedList(2, 2); - var cut = RenderComponent>(p => + var cut = Render>(p => p.Add(param => param.PageList, page)); cut.Find("li:last-child").ClassList.Should().Contain("disabled"); @@ -44,7 +44,7 @@ public void ShouldNotFireNextWhenOnLastPage() public void ShouldNotFireNextWhenOnFirstPage() { var page = CreatePagedList(1, 2); - var cut = RenderComponent>(p => + var cut = Render>(p => p.Add(param => param.PageList, page)); cut.Find("li:first-child").ClassList.Should().Contain("disabled"); @@ -54,7 +54,7 @@ public void ShouldNotFireNextWhenOnFirstPage() public void ShouldNotFireNextWhenNoPage() { var page = CreatePagedList(0, 0); - var cut = RenderComponent>(p => + var cut = Render>(p => p.Add(param => param.PageList, page)); cut.Find("li:first-child").ClassList.Should().Contain("disabled"); diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/FooterTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/FooterTests.cs index db1df6bb..62de52f6 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/FooterTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components/FooterTests.cs @@ -6,7 +6,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Home.Components; -public class FooterTests : TestContext +public class FooterTests : BunitContext { [Fact] public void ShouldSetCopyrightInformation() @@ -23,7 +23,7 @@ public void ShouldSetCopyrightInformation() }); Services.AddScoped(_ => appConfig); - var cut = RenderComponent