Added tag and creator tests.
This commit is contained in:
@@ -42,8 +42,8 @@ public class CreatorSearchProvider(AppDbContext context) : SearchProvider<Creato
|
||||
Expression<Func<CreatorSearchItem, object>> selector = field switch
|
||||
{
|
||||
CreatorSortField.VoiceWorkCount => x => x.VoiceWorkCount,
|
||||
CreatorSortField.Favorite => x => x.Favorite,
|
||||
CreatorSortField.Blacklisted => x => x.Blacklisted,
|
||||
CreatorSortField.Favorite => x => !x.Favorite,
|
||||
CreatorSortField.Blacklisted => x => !x.Blacklisted,
|
||||
_ => x => x.Name
|
||||
};
|
||||
|
||||
|
||||
26
JSMR.Tests/Fixtures/CreatorSearchProviderFixture.cs
Normal file
26
JSMR.Tests/Fixtures/CreatorSearchProviderFixture.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using JSMR.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JSMR.Tests.Fixtures;
|
||||
|
||||
public class CreatorSearchProviderFixture : MariaDbFixture
|
||||
{
|
||||
protected override async Task OnInitializedAsync(AppDbContext context)
|
||||
{
|
||||
await SeedAsync(context);
|
||||
}
|
||||
|
||||
private static async Task SeedAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.Tags.AnyAsync())
|
||||
return;
|
||||
|
||||
context.Creators.AddRange(
|
||||
new() { CreatorId = 1, Name = "John Smith" },
|
||||
new() { CreatorId = 2, Name = "John Doe", Favorite = true },
|
||||
new() { CreatorId = 3, Name = "Jane Doe", Blacklisted = true }
|
||||
);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
32
JSMR.Tests/Fixtures/TagSearchProviderFixture.cs
Normal file
32
JSMR.Tests/Fixtures/TagSearchProviderFixture.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using JSMR.Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JSMR.Tests.Fixtures;
|
||||
|
||||
public class TagSearchProviderFixture : MariaDbFixture
|
||||
{
|
||||
protected override async Task OnInitializedAsync(AppDbContext context)
|
||||
{
|
||||
await SeedAsync(context);
|
||||
}
|
||||
|
||||
private static async Task SeedAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.Tags.AnyAsync())
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
103
JSMR.Tests/Integration/CreatorSearchProviderTests.cs
Normal file
103
JSMR.Tests/Integration/CreatorSearchProviderTests.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using JSMR.Application.Common.Search;
|
||||
using JSMR.Application.Creators.Queries.Search.Contracts;
|
||||
using JSMR.Infrastructure.Data;
|
||||
using JSMR.Infrastructure.Data.Repositories.Creators;
|
||||
using JSMR.Tests.Fixtures;
|
||||
using Shouldly;
|
||||
|
||||
namespace JSMR.Tests.Integration;
|
||||
|
||||
public class CreatorSearchProviderTests(CreatorSearchProviderFixture fixture) : IClassFixture<CreatorSearchProviderFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Filter_None_Sort_Name_Ascending()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
CreatorSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<CreatorSearchCriteria, CreatorSortField>()
|
||||
{
|
||||
SortOptions = [new(CreatorSortField.Name, Application.Common.Search.SortDirection.Ascending)]
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
result.Items.Length.ShouldBe(3);
|
||||
result.TotalItems.ShouldBe(3);
|
||||
result.Items[0].Name.ShouldBe("Jane Doe");
|
||||
result.Items[2].Name.ShouldBe("John Smith");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Filter_None_Sort_Name_Descending()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
CreatorSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<CreatorSearchCriteria, CreatorSortField>()
|
||||
{
|
||||
SortOptions = [new(CreatorSortField.Name, Application.Common.Search.SortDirection.Descending)]
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
result.Items.Length.ShouldBe(3);
|
||||
result.TotalItems.ShouldBe(3);
|
||||
result.Items[0].Name.ShouldBe("John Smith");
|
||||
result.Items[2].Name.ShouldBe("Jane Doe");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Filter_None_Sort_Favorite_Descending()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
CreatorSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<CreatorSearchCriteria, CreatorSortField>()
|
||||
{
|
||||
SortOptions = [new(CreatorSortField.Favorite, Application.Common.Search.SortDirection.Ascending)]
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
result.Items[0].Name.ShouldBe("John Doe");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Filter_None_Sort_Blacklisted_Descending()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
CreatorSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<CreatorSearchCriteria, CreatorSortField>()
|
||||
{
|
||||
SortOptions = [new(CreatorSortField.Blacklisted, Application.Common.Search.SortDirection.Ascending)]
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
result.Items[0].Name.ShouldBe("Jane Doe");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Filter_By_Name_Creator_Name()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
CreatorSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<CreatorSearchCriteria, CreatorSortField>()
|
||||
{
|
||||
Criteria = new()
|
||||
{
|
||||
Name = "Jane"
|
||||
}
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
// Assert
|
||||
result.Items.Length.ShouldBe(1);
|
||||
result.TotalItems.ShouldBe(1);
|
||||
result.Items.ShouldContain(creatorView => creatorView.Name == "Jane Doe");
|
||||
}
|
||||
}
|
||||
91
JSMR.Tests/Integration/TagSearchProviderTests.cs
Normal file
91
JSMR.Tests/Integration/TagSearchProviderTests.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using JSMR.Application.Common.Search;
|
||||
using JSMR.Application.Tags.Queries.Search.Contracts;
|
||||
using JSMR.Infrastructure.Data;
|
||||
using JSMR.Infrastructure.Data.Repositories.Tags;
|
||||
using JSMR.Tests.Fixtures;
|
||||
using Shouldly;
|
||||
|
||||
namespace JSMR.Tests.Integration;
|
||||
|
||||
public class TagSearchProviderTests(TagSearchProviderFixture fixture) : IClassFixture<TagSearchProviderFixture>
|
||||
{
|
||||
[Fact]
|
||||
public async Task Filter_None_Sort_Name()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
TagSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
|
||||
{
|
||||
SortOptions = [new(TagSortField.Name, Application.Common.Search.SortDirection.Ascending)]
|
||||
};
|
||||
|
||||
var result = await provider.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()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
TagSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
|
||||
{
|
||||
SortOptions = [new(TagSortField.EnglishName, Application.Common.Search.SortDirection.Ascending)]
|
||||
};
|
||||
|
||||
var result = await provider.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()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
TagSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
|
||||
{
|
||||
Criteria = new()
|
||||
{
|
||||
Name = "ほの"
|
||||
}
|
||||
};
|
||||
|
||||
var result = await provider.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()
|
||||
{
|
||||
await using AppDbContext context = fixture.CreateDbContext();
|
||||
TagSearchProvider provider = new(context);
|
||||
|
||||
var options = new SearchOptions<TagSearchCriteria, TagSortField>()
|
||||
{
|
||||
Criteria = new()
|
||||
{
|
||||
Name = "Heart"
|
||||
}
|
||||
};
|
||||
|
||||
var result = await provider.SearchAsync(options);
|
||||
|
||||
result.Items.Length.ShouldBe(1);
|
||||
result.TotalItems.ShouldBe(1);
|
||||
result.Items.ShouldContain(tagView => tagView.EnglishName == "Heartwarming");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user