Added MangaDex cover art logic. Added "Search Manga" test for MangaDex client.
This commit is contained in:
@@ -22,6 +22,52 @@ public class MangaDexClientTests
|
||||
MangaDexResponse? mangaDexResponse = await mangaDexClient.SearchMangaByTitleAsync("Some random text", CancellationToken.None);
|
||||
|
||||
// Testing here
|
||||
mangaDexResponse.ShouldNotBeNull();
|
||||
mangaDexResponse.Response.ShouldBe("collection");
|
||||
mangaDexResponse.ShouldBeOfType<MangaDexCollectionResponse>();
|
||||
|
||||
MangaDexCollectionResponse mangaDexCollectionResponse = (mangaDexResponse as MangaDexCollectionResponse)!;
|
||||
mangaDexCollectionResponse.Data.Count.ShouldBe(3);
|
||||
|
||||
mangaDexCollectionResponse.Data[0].ShouldBeOfType<MangaEntity>();
|
||||
MangaEntity mangaEntity = (mangaDexCollectionResponse.Data[0] as MangaEntity)!;
|
||||
|
||||
mangaEntity.Attributes.ShouldNotBeNull();
|
||||
|
||||
mangaEntity.Attributes.Title.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Title["en"].ShouldBe("Gals Can’t Be Kind to Otaku!?");
|
||||
|
||||
mangaEntity.Attributes.Description.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Description["en"].ShouldBe("Takuya Seo is an otaku who likes \"anime for girls\" and can't say he likes it out loud. One day, he hooks up with two gals from his class, Amane and Ijichi, but it seems that Amane is also an otaku...");
|
||||
|
||||
mangaEntity.Attributes.Tags.Count.ShouldBe(5);
|
||||
|
||||
mangaEntity.Attributes.Tags[0].Attributes.ShouldNotBeNull();
|
||||
mangaEntity.Attributes.Tags[0].Attributes!.Name.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Tags[0].Attributes!.Name["en"].ShouldBe("Romance");
|
||||
|
||||
mangaEntity.Attributes.Tags[1].Attributes.ShouldNotBeNull();
|
||||
mangaEntity.Attributes.Tags[1].Attributes!.Name.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Tags[1].Attributes!.Name["en"].ShouldBe("Comedy");
|
||||
|
||||
mangaEntity.Attributes.Tags[2].Attributes.ShouldNotBeNull();
|
||||
mangaEntity.Attributes.Tags[2].Attributes!.Name.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Tags[2].Attributes!.Name["en"].ShouldBe("School Life");
|
||||
|
||||
mangaEntity.Attributes.Tags[3].Attributes.ShouldNotBeNull();
|
||||
mangaEntity.Attributes.Tags[3].Attributes!.Name.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Tags[3].Attributes!.Name["en"].ShouldBe("Slice of Life");
|
||||
|
||||
mangaEntity.Attributes.Tags[4].Attributes.ShouldNotBeNull();
|
||||
mangaEntity.Attributes.Tags[4].Attributes!.Name.ShouldContainKey("en");
|
||||
mangaEntity.Attributes.Tags[4].Attributes!.Name["en"].ShouldBe("Gyaru");
|
||||
|
||||
mangaEntity.Relationships.Count.ShouldBe(4);
|
||||
mangaEntity.Relationships[2].ShouldBeOfType<CoverArtEntity>();
|
||||
|
||||
CoverArtEntity coverArtEntity = (mangaEntity.Relationships[2] as CoverArtEntity)!;
|
||||
coverArtEntity.Attributes.ShouldNotBeNull();
|
||||
coverArtEntity.Attributes.FileName.ShouldBe("6b3073de-bb65-4723-8113-6068bf8c6eb4.jpg");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -154,6 +200,35 @@ public class MangaDexClientTests
|
||||
mangaDexChapterResponse.Chapter.DataSaver[12].ShouldBe("13-b886b4ed986a473478e3db7bb18fe2faea567a1ad5e520408967410dcf8838d1.jpg");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Cover_Art()
|
||||
{
|
||||
string searchResultJson = await ReadJsonResourceAsync("Manga-Cover-Art-Response.json");
|
||||
|
||||
IHttpService httpService = Substitute.For<IHttpService>();
|
||||
|
||||
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
|
||||
.Returns(Task.FromResult(searchResultJson));
|
||||
|
||||
MangaDexClient mangaDexClient = new(httpService);
|
||||
MangaDexResponse? mangaDexResponse = await mangaDexClient.GetCoverArtAsync(Guid.NewGuid(), CancellationToken.None);
|
||||
|
||||
mangaDexResponse.ShouldNotBeNull();
|
||||
mangaDexResponse.Response.ShouldBe("collection");
|
||||
mangaDexResponse.ShouldBeOfType<MangaDexCollectionResponse>();
|
||||
|
||||
MangaDexCollectionResponse mangaDexEntityResponse = (mangaDexResponse as MangaDexCollectionResponse)!;
|
||||
|
||||
List<CoverArtEntity> coverArtEntities = [.. mangaDexEntityResponse.Data.Where(entity => entity is CoverArtEntity).Cast<CoverArtEntity>()];
|
||||
coverArtEntities.Count.ShouldBe(9);
|
||||
|
||||
coverArtEntities[0].Attributes.ShouldNotBeNull();
|
||||
coverArtEntities[0].Attributes!.FileName.ShouldBe("2569ffd8-4ba1-4030-8d08-b7a21333a7a6.jpg");
|
||||
|
||||
coverArtEntities[8].Attributes.ShouldNotBeNull();
|
||||
coverArtEntities[8].Attributes!.FileName.ShouldBe("6b3073de-bb65-4723-8113-6068bf8c6eb4.jpg");
|
||||
}
|
||||
|
||||
private static async Task<string> ReadJsonResourceAsync(string resourceName)
|
||||
{
|
||||
return await ResourceHelper.ReadJsonResourceAsync($"MangaReader.Tests.Sources.MangaDex.Api.{resourceName}");
|
||||
|
||||
Reference in New Issue
Block a user