Skip to content

Commit 8566b28

Browse files
committed
fix: Remove (temporarly) interceptors
1 parent a098f70 commit 8566b28

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/Dashboard/Components/VisitCountPerPageTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
88
using LinkDotNet.Blog.TestUtilities;
99
using LinkDotNet.Blog.Web.Features.Admin.Dashboard.Components;
10+
using Microsoft.AspNetCore.Components;
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.Logging;
1213
using TestContext = Xunit.TestContext;
@@ -54,7 +55,7 @@ public async Task ShouldFilterByDate()
5455
await DbContext.BlogPostRecords.AddRangeAsync(clicked1, clicked2, clicked3, clicked4);
5556
await DbContext.SaveChangesAsync(TestContext.Current.CancellationToken);
5657
await using var ctx = new BunitContext();
57-
ctx.ComponentFactories.AddStub<DateRangeSelector>();
58+
ctx.ComponentFactories.Add<DateRangeSelector, DateRangeSelectorStub>();
5859
RegisterRepositories(ctx);
5960
var cut = ctx.Render<VisitCountPerPage>();
6061
var filter = new Filter { StartDate = new DateOnly(2019, 1, 1), EndDate = new DateOnly(2020, 12, 31) };
@@ -136,4 +137,10 @@ private async Task SaveBlogPostArticleClicked(string blogPostId, int count)
136137

137138
await DbContext.SaveChangesAsync();
138139
}
140+
141+
private class DateRangeSelectorStub : ComponentBase
142+
{
143+
[Parameter]
144+
public EventCallback<Filter> FilterChanged { get; set; }
145+
}
139146
}

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/SearchByTag/SearchByTagPageTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using LinkDotNet.Blog.Domain;
44
using LinkDotNet.Blog.TestUtilities;
55
using LinkDotNet.Blog.Web.Features.SearchByTag;
6+
using Microsoft.AspNetCore.Components;
67
using Microsoft.AspNetCore.Components.Web;
78
using Microsoft.Extensions.DependencyInjection;
89

@@ -46,7 +47,7 @@ public void ShouldSetTitleToTag()
4647
{
4748
using var ctx = new BunitContext();
4849
ctx.Services.AddScoped(_ => Repository);
49-
ctx.ComponentFactories.AddStub<PageTitle>();
50+
ctx.ComponentFactories.Add<PageTitle, PageTitleStub>();
5051

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

@@ -66,4 +67,10 @@ private void RegisterServices(BunitContext ctx)
6667
{
6768
ctx.Services.AddScoped(_ => Repository);
6869
}
70+
71+
private class PageTitleStub : ComponentBase
72+
{
73+
[Parameter]
74+
public RenderFragment? ChildContent { get; set; } = default!;
75+
}
6976
}

tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class NavMenuTests : BunitContext
1212
{
1313
public NavMenuTests()
1414
{
15-
ComponentFactories.AddStub<ThemeToggler>();
15+
ComponentFactories.Add<ThemeToggler, ThemeTogglerStub>();
1616
}
1717

1818
[Fact]
@@ -101,6 +101,12 @@ public void ShouldShowBlogNameWhenNotBrand(string? brandUrl)
101101
var brandImage = cut.Find(".nav-brand");
102102
var image = brandImage as IHtmlAnchorElement;
103103
image.ShouldNotBeNull();
104-
image!.TextContent.ShouldBe("Steven");
104+
image.TextContent.ShouldBe("Steven");
105+
}
106+
107+
private class ThemeTogglerStub : ComponentBase
108+
{
109+
[Parameter]
110+
public string Class { get; set; } = default!;
105111
}
106112
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using LinkDotNet.Blog.Web.Features.Services;
1010
using LinkDotNet.Blog.Web.Features.ShowBlogPost;
1111
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
12+
using Microsoft.AspNetCore.Components;
1213
using Microsoft.AspNetCore.Components.Web;
1314
using Microsoft.Extensions.DependencyInjection;
1415
using Microsoft.Extensions.Options;
@@ -21,7 +22,7 @@ public class ShowBlogPostPageTests : BunitContext
2122
{
2223
public ShowBlogPostPageTests()
2324
{
24-
ComponentFactories.AddStub<SimilarBlogPostSection>();
25+
ComponentFactories.Add<SimilarBlogPostSection, SimilarBlogPostSectionStub>();
2526
JSInterop.Mode = JSRuntimeMode.Loose;
2627
var shortCodeRepository = Substitute.For<IRepository<ShortCode>>();
2728
shortCodeRepository.GetAllAsync().Returns(PagedList<ShortCode>.Empty);
@@ -31,8 +32,8 @@ public ShowBlogPostPageTests()
3132
Services.AddScoped(_ => Substitute.For<IInstantJobRegistry>());
3233
Services.AddScoped(_ => Options.Create(new ApplicationConfigurationBuilder().Build()));
3334
AddAuthorization();
34-
ComponentFactories.AddStub<PageTitle>();
35-
ComponentFactories.AddStub<Like>();
35+
ComponentFactories.Add<PageTitle, PageTitleStub>();
36+
ComponentFactories.Add<Like, LikeStub>();
3637
ComponentFactories.AddStub<CommentSection>();
3738
}
3839

@@ -161,4 +162,25 @@ public void ShouldSetCanoncialUrlOfOgDataWithoutSlug()
161162

162163
cut.FindComponent<OgData>().Instance.CanonicalRelativeUrl.ShouldBe("blogPost/1");
163164
}
165+
166+
private class PageTitleStub : ComponentBase
167+
{
168+
[Parameter]
169+
public RenderFragment? ChildContent { get; set; } = default!;
170+
}
171+
172+
private class LikeStub : ComponentBase
173+
{
174+
[Parameter]
175+
public BlogPost BlogPost { get; set; } = default!;
176+
177+
[Parameter]
178+
public EventCallback<bool> OnBlogPostLiked { get; set; } = default!;
179+
}
180+
181+
private class SimilarBlogPostSectionStub : ComponentBase
182+
{
183+
[Parameter]
184+
public BlogPost BlogPost { get; set; } = default!;
185+
}
164186
}

0 commit comments

Comments
 (0)