Files
manga-reader/MangaReader.Tests/Sources/MangaDex/Search/MangaDexSearchTests.cs
2025-05-26 22:03:08 -04:00

108 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MangaReader.Core.Search;
using MangaReader.Core.Sources.MangaDex.Api;
using MangaReader.Core.Sources.MangaDex.Search;
using NSubstitute;
using Shouldly;
namespace MangaReader.Tests.Sources.MangaDex.Search;
public class MangaDexSearchTests
{
[Fact]
public async Task Get_Search_Result()
{
MangaDexCollectionResponse collectionResponse = new()
{
Result = "ok",
Response = "collection",
Data =
[
new MangaEntity()
{
Id = new Guid("ee96e2b7-9af2-4864-9656-649f4d3b6fec"),
Type = "manga",
Attributes = new()
{
Title = new()
{
{ "en", "Gals Cant Be Kind to Otaku!?" }
}
},
Relationships =
[
new CoverArtEntity()
{
Id = new Guid("a06943fd-6309-49a8-a66a-8df0f6dc41eb"),
Type = "cover_art",
Attributes = new()
{
FileName = "6b3073de-bb65-4723-8113-6068bf8c6eb4.jpg"
}
}
]
},
new MangaEntity()
{
Id = new Guid("16c34950-954c-4f0d-808e-d8278a546339"),
Type = "manga",
Attributes = new()
{
Title = new()
{
{ "en", "Suufungo no Mirai ga Wakaru You ni Natta Kedo, Onnagokoro wa Wakaranai." }
}
},
Relationships =
[
new CoverArtEntity()
{
Id = new Guid("ee8588b5-145f-4eee-981a-eb604856fbd2"),
Type = "cover_art",
Attributes = new()
{
FileName = "7d301e1e-642b-4b7d-b65b-9777b36e80bf.jpg"
}
}
]
},
new MangaEntity()
{
Id = new Guid("f395bfc6-e52f-4f64-9cfb-87037215d214"),
Type = "manga",
Attributes = new()
{
Title = new()
{
{ "en", "Ienai Himitsu No Aishikata" }
}
},
Relationships =
[
new CoverArtEntity()
{
Id = new Guid("40df2d2e-b786-4aa9-9218-e3ed168cd96e"),
Type = "cover_art",
Attributes = new()
{
FileName = "c00a33cd-b26b-4554-a9f0-d6885c81eb36.jpg"
}
}
]
}
]
};
IMangaDexClient mangaDexClient = Substitute.For<IMangaDexClient>();
mangaDexClient.SearchMangaByTitleAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(collectionResponse);
MangaDexSearchProvider searchProvider = new(mangaDexClient);
MangaSearchResult[] searchResult = await searchProvider.SearchAsync("Gal Can't Be Kind", CancellationToken.None);
searchResult.Length.ShouldBe(3);
searchResult[0].Title.ShouldBe("Gals Cant Be Kind to Otaku!?");
searchResult[0].Url.ShouldBe("https://mangadex.org/title/ee96e2b7-9af2-4864-9656-649f4d3b6fec/gals-can-t-be-kind-to-otaku");
searchResult[0].Thumbnail.ShouldBe("https://mangadex.org/covers/ee96e2b7-9af2-4864-9656-649f4d3b6fec/6b3073de-bb65-4723-8113-6068bf8c6eb4.jpg");
}
}