Skip to content

Commit

Permalink
Use more interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jan 20, 2024
1 parent c22b0cd commit 7cd037d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
24 changes: 3 additions & 21 deletions src/LinkDotNet.Blog.Domain/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,17 @@ protected Enumeration(string key)
public string Key { get; }

public static bool operator ==(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
{
if (a is null || b is null)
{
return false;
}

return a.Key.Equals(b.Key, StringComparison.Ordinal);
}
=> a is not null && b is not null && a.Key.Equals(b.Key, StringComparison.Ordinal);

public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
{
return !(a == b);
}
public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b) => !(a == b);

public static TEnumeration Create(string key)
=> All.SingleOrDefault(p => p.Key == key)
?? throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");

public override int GetHashCode() => Key.GetHashCode(StringComparison.Ordinal);

public override bool Equals(object obj)
{
if (obj?.GetType() != typeof(TEnumeration))
{
return false;
}

return ((TEnumeration)obj).Key == Key;
}
public override bool Equals(object obj) => obj?.GetType() == typeof(TEnumeration) && ((TEnumeration)obj).Key == Key;

public override string ToString() => Key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;

Expand Down Expand Up @@ -55,12 +54,12 @@ public async Task ShouldFilterByDate()
await DbContext.BlogPostRecords.AddRangeAsync(clicked1, clicked2, clicked3, clicked4);
await DbContext.SaveChangesAsync();
using var ctx = new TestContext();
ctx.ComponentFactories.Add<DateRangeSelector, FilterStubComponent>();
ctx.ComponentFactories.AddStub<DateRangeSelector>();
RegisterRepositories(ctx);
var cut = ctx.RenderComponent<VisitCountPerPage>();
var filter = new Filter { StartDate = new DateOnly(2019, 1, 1), EndDate = new DateOnly(2020, 12, 31) };

await cut.InvokeAsync(() => cut.FindComponent<FilterStubComponent>().Instance.FireFilterChanged(filter));
await cut.InvokeAsync(() => cut.FindComponent<DateRangeSelectorStub>().Instance.FilterChanged.InvokeAsync(filter));

cut.WaitForState(() => cut.FindAll("td").Any());
var elements = cut.FindAll("td").ToList();
Expand Down Expand Up @@ -116,12 +115,4 @@ private async Task SaveBlogPostArticleClicked(string blogPostId, int count)

await DbContext.SaveChangesAsync();
}

private sealed class FilterStubComponent : ComponentBase
{
[Parameter]
public EventCallback<Filter> FilterChanged { get; set; }

public void FireFilterChanged(Filter filter) => FilterChanged.InvokeAsync(filter);
}
}
}

0 comments on commit 7cd037d

Please sign in to comment.