Skip to content

Commit

Permalink
fix: Remove (temporarly) interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Feb 21, 2025
1 parent a098f70 commit 8566b28
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.Admin.Dashboard.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using TestContext = Xunit.TestContext;
Expand Down Expand Up @@ -54,7 +55,7 @@ public async Task ShouldFilterByDate()
await DbContext.BlogPostRecords.AddRangeAsync(clicked1, clicked2, clicked3, clicked4);
await DbContext.SaveChangesAsync(TestContext.Current.CancellationToken);
await using var ctx = new BunitContext();
ctx.ComponentFactories.AddStub<DateRangeSelector>();
ctx.ComponentFactories.Add<DateRangeSelector, DateRangeSelectorStub>();
RegisterRepositories(ctx);
var cut = ctx.Render<VisitCountPerPage>();
var filter = new Filter { StartDate = new DateOnly(2019, 1, 1), EndDate = new DateOnly(2020, 12, 31) };
Expand Down Expand Up @@ -136,4 +137,10 @@ private async Task SaveBlogPostArticleClicked(string blogPostId, int count)

await DbContext.SaveChangesAsync();
}

private class DateRangeSelectorStub : ComponentBase
{
[Parameter]
public EventCallback<Filter> FilterChanged { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.SearchByTag;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -46,7 +47,7 @@ public void ShouldSetTitleToTag()
{
using var ctx = new BunitContext();
ctx.Services.AddScoped(_ => Repository);
ctx.ComponentFactories.AddStub<PageTitle>();
ctx.ComponentFactories.Add<PageTitle, PageTitleStub>();

var cut = ctx.Render<SearchByTagPage>(p => p.Add(s => s.Tag, "Tag"));

Expand All @@ -66,4 +67,10 @@ private void RegisterServices(BunitContext ctx)
{
ctx.Services.AddScoped(_ => Repository);
}

private class PageTitleStub : ComponentBase
{
[Parameter]
public RenderFragment? ChildContent { get; set; } = default!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NavMenuTests : BunitContext
{
public NavMenuTests()
{
ComponentFactories.AddStub<ThemeToggler>();
ComponentFactories.Add<ThemeToggler, ThemeTogglerStub>();
}

[Fact]
Expand Down Expand Up @@ -101,6 +101,12 @@ public void ShouldShowBlogNameWhenNotBrand(string? brandUrl)
var brandImage = cut.Find(".nav-brand");
var image = brandImage as IHtmlAnchorElement;
image.ShouldNotBeNull();
image!.TextContent.ShouldBe("Steven");
image.TextContent.ShouldBe("Steven");
}

private class ThemeTogglerStub : ComponentBase
{
[Parameter]
public string Class { get; set; } = default!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.Blog.Web.Features.ShowBlogPost;
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand All @@ -21,7 +22,7 @@ public class ShowBlogPostPageTests : BunitContext
{
public ShowBlogPostPageTests()
{
ComponentFactories.AddStub<SimilarBlogPostSection>();
ComponentFactories.Add<SimilarBlogPostSection, SimilarBlogPostSectionStub>();
JSInterop.Mode = JSRuntimeMode.Loose;
var shortCodeRepository = Substitute.For<IRepository<ShortCode>>();
shortCodeRepository.GetAllAsync().Returns(PagedList<ShortCode>.Empty);
Expand All @@ -31,8 +32,8 @@ public ShowBlogPostPageTests()
Services.AddScoped(_ => Substitute.For<IInstantJobRegistry>());
Services.AddScoped(_ => Options.Create(new ApplicationConfigurationBuilder().Build()));
AddAuthorization();
ComponentFactories.AddStub<PageTitle>();
ComponentFactories.AddStub<Like>();
ComponentFactories.Add<PageTitle, PageTitleStub>();
ComponentFactories.Add<Like, LikeStub>();
ComponentFactories.AddStub<CommentSection>();
}

Expand Down Expand Up @@ -161,4 +162,25 @@ public void ShouldSetCanoncialUrlOfOgDataWithoutSlug()

cut.FindComponent<OgData>().Instance.CanonicalRelativeUrl.ShouldBe("blogPost/1");
}

private class PageTitleStub : ComponentBase
{
[Parameter]
public RenderFragment? ChildContent { get; set; } = default!;
}

private class LikeStub : ComponentBase
{
[Parameter]
public BlogPost BlogPost { get; set; } = default!;

[Parameter]
public EventCallback<bool> OnBlogPostLiked { get; set; } = default!;
}

private class SimilarBlogPostSectionStub : ComponentBase
{
[Parameter]
public BlogPost BlogPost { get; set; } = default!;
}
}

0 comments on commit 8566b28

Please sign in to comment.