50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using MangaReader.Core.HttpService;
|
||
using MangaReader.Core.Search;
|
||
using MangaReader.Core.Search.MangaDex;
|
||
using MangaReader.Tests.Utilities;
|
||
using NSubstitute;
|
||
using Shouldly;
|
||
|
||
namespace MangaReader.Tests.Search.MangaDex;
|
||
|
||
public class MangaDexSearchTests
|
||
{
|
||
class MangaDexSearchProviderTestWrapper(IHttpService httpService) : MangaDexSearchProvider(httpService)
|
||
{
|
||
internal string Test_GetSearchUrl(string keyword) => GetSearchUrl(keyword);
|
||
}
|
||
|
||
[Fact]
|
||
public void Get_Search_Url()
|
||
{
|
||
// Arrange
|
||
IHttpService httpService = Substitute.For<IHttpService>();
|
||
MangaDexSearchProviderTestWrapper searchProvider = new(httpService);
|
||
|
||
// Act
|
||
string url = searchProvider.Test_GetSearchUrl("Gal can't be");
|
||
|
||
// Assert
|
||
url.ShouldBe("https://api.mangadex.org/manga?title=gal can't be&limit=5");
|
||
}
|
||
|
||
[Fact]
|
||
public async Task Get_Search_Result()
|
||
{
|
||
string resourceName = "MangaReader.Tests.Search.MangaDex.SampleSearchResult.json";
|
||
string searchResultJson = await ResourceHelper.ReadJsonResourceAsync(resourceName);
|
||
|
||
IHttpService httpService = Substitute.For<IHttpService>();
|
||
|
||
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
|
||
.Returns(Task.FromResult(searchResultJson));
|
||
|
||
MangaDexSearchProvider searchProvider = new(httpService);
|
||
MangaSearchResult[] searchResult = await searchProvider.SearchAsync("Gal Can't Be Kind", CancellationToken.None);
|
||
|
||
searchResult.Length.ShouldBe(3);
|
||
searchResult[0].Title.ShouldBe("Gals Can’t 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");
|
||
}
|
||
} |