Cleaned up test code files.
All checks were successful
ci / build-test (push) Successful in 1m27s
ci / publish-image (push) Has been skipped

This commit is contained in:
2025-11-04 09:53:50 -05:00
parent 06f8c2ec9e
commit fd384a1998
10 changed files with 115 additions and 332 deletions

View File

@@ -0,0 +1,24 @@
using JSMR.Infrastructure.Data;
using JSMR.Tests.Fixtures;
namespace JSMR.Tests.Search.Tag;
public sealed class TagSearchProviderFixture(MariaDbContainerFixture container) : SearchProviderFixture(container)
{
protected override async Task SeedAsync(AppDbContext context)
{
context.Tags.AddRange(
new() { TagId = 1, Name = "OL" },
new() { TagId = 2, Name = "ほのぼの", Favorite = true },
new() { TagId = 3, Name = "ツンデレ", Blacklisted = true }
);
context.EnglishTags.AddRange(
new() { EnglishTagId = 1, TagId = 1, Name = "Office Lady" },
new() { EnglishTagId = 2, TagId = 2, Name = "Heartwarming" },
new() { EnglishTagId = 3, TagId = 3, Name = "Tsundere" }
);
await context.SaveChangesAsync();
}
}

View File

@@ -0,0 +1,87 @@
using JSMR.Application.Common.Search;
using JSMR.Application.Tags.Queries.Search.Contracts;
using JSMR.Infrastructure.Data;
using JSMR.Infrastructure.Data.Repositories.Tags;
using Shouldly;
using SortDirection = JSMR.Application.Common.Search.SortDirection;
namespace JSMR.Tests.Search.Tag;
public class TagSearchProviderTests(TagSearchProviderFixture fixture) : IClassFixture<TagSearchProviderFixture>
{
private async Task<SearchResult<TagSearchItem>> SearchAsync(SearchOptions<TagSearchCriteria, TagSortField> options)
{
AppDbContext context = fixture.DbContext!;
TagSearchProvider provider = new(context);
return await provider.SearchAsync(options, TestContext.Current.CancellationToken);
}
[Fact]
public async Task Filter_None_Sort_Name()
{
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
{
SortOptions = [new(TagSortField.Name, SortDirection.Ascending)]
};
var result = await SearchAsync(options);
result.Items.Length.ShouldBe(3);
result.TotalItems.ShouldBe(3);
result.Items[0].Name.ShouldBe("OL");
result.Items[2].Name.ShouldBe("ツンデレ");
}
[Fact]
public async Task Filter_None_Sort_EnglishName()
{
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
{
SortOptions = [new(TagSortField.EnglishName, SortDirection.Ascending)]
};
var result = await SearchAsync(options);
result.Items.Length.ShouldBe(3);
result.TotalItems.ShouldBe(3);
result.Items[0].EnglishName.ShouldBe("Heartwarming");
result.Items[2].EnglishName.ShouldBe("Tsundere");
}
[Fact]
public async Task Filter_By_Name_Tag_Name()
{
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
{
Criteria = new()
{
Name = "ほの"
}
};
var result = await SearchAsync(options);
result.Items.Length.ShouldBe(1);
result.TotalItems.ShouldBe(1);
result.Items.ShouldContain(tagView => tagView.Name == "ほのぼの");
}
[Fact]
public async Task Filter_By_Name_English_Tag_Name()
{
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
{
Criteria = new()
{
Name = "Heart"
}
};
var result = await SearchAsync(options);
result.Items.Length.ShouldBe(1);
result.TotalItems.ShouldBe(1);
result.Items.ShouldContain(tagView => tagView.EnglishName == "Heartwarming");
}
}