84 lines
3.1 KiB
C#
84 lines
3.1 KiB
C#
using JSMR.Application.Common;
|
|
using JSMR.Application.Integrations.DLSite.Models;
|
|
using JSMR.Infrastructure.Http;
|
|
using JSMR.Infrastructure.Integrations.DLSite;
|
|
using JSMR.Infrastructure.Integrations.DLSite.Mapping;
|
|
using JSMR.Infrastructure.Integrations.DLSite.Models;
|
|
using JSMR.Tests.Utilities;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
using Shouldly;
|
|
|
|
namespace JSMR.Tests.Integrations.DLSite;
|
|
|
|
public class DLSiteClientTests
|
|
{
|
|
private static async Task<string> ReadJsonResourceAsync(string resourceName)
|
|
{
|
|
return await ResourceHelper.ReadAsync($"JSMR.Tests.Integrations.DLSite.{resourceName}");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Deserialize_Product_Info_Collection()
|
|
{
|
|
string productInfoJson = await ReadJsonResourceAsync("Product-Info.json");
|
|
|
|
IHttpService httpService = Substitute.For<IHttpService>();
|
|
|
|
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
|
|
.Returns(Task.FromResult(productInfoJson));
|
|
|
|
var logger = Substitute.For<ILogger<DLSiteClient>>();
|
|
var client = new DLSiteClient(httpService, logger);
|
|
|
|
var result = await client.GetVoiceWorkDetailsAsync(["RJ01230163"], CancellationToken.None);
|
|
|
|
result.Count.ShouldBe(1);
|
|
|
|
result.ShouldContainKey("RJ01230163");
|
|
result["RJ01230163"].HasTrial.ShouldBeTrue();
|
|
result["RJ01230163"].HasDLPlay.ShouldBeTrue();
|
|
result["RJ01230163"].HasReviews.ShouldBeTrue();
|
|
result["RJ01230163"].SupportedLanguages.Length.ShouldBe(1);
|
|
result["RJ01230163"].SupportedLanguages.Select(x => x.Language).ShouldContain(Language.English);
|
|
result["RJ01230163"].DownloadCount.ShouldBe(659);
|
|
result["RJ01230163"].WishlistCount.ShouldBe(380);
|
|
}
|
|
|
|
[Fact]
|
|
public void Map_Basic_ProductInfoCollection()
|
|
{
|
|
ProductInfoCollection productInfoCollection = new()
|
|
{
|
|
{
|
|
"RG0001",
|
|
new ProductInfo()
|
|
{
|
|
WishlistCount = 250,
|
|
DownloadCount = 100,
|
|
Options = ["TRI", "DLP", "JPN"],
|
|
TitleId = "SE0001",
|
|
TitleName = "Series 1"
|
|
}
|
|
}
|
|
};
|
|
|
|
VoiceWorkDetailCollection mappedCollection = DLSiteToDomainMapper.Map(productInfoCollection);
|
|
mappedCollection.Count.ShouldBe(1);
|
|
mappedCollection.ShouldContainKey("RG0001");
|
|
|
|
VoiceWorkDetails voiceWorkDetails = mappedCollection["RG0001"];
|
|
voiceWorkDetails.WishlistCount.ShouldBe(250);
|
|
voiceWorkDetails.DownloadCount.ShouldBe(100);
|
|
voiceWorkDetails.HasTrial.ShouldBe(true);
|
|
voiceWorkDetails.HasDLPlay.ShouldBe(true);
|
|
voiceWorkDetails.AI.ShouldBe(AIGeneration.None);
|
|
|
|
voiceWorkDetails.Series.ShouldNotBeNull();
|
|
voiceWorkDetails.Series.Identifier.ShouldBe("SE0001");
|
|
voiceWorkDetails.Series.Name.ShouldBe("Series 1");
|
|
|
|
voiceWorkDetails.SupportedLanguages.Length.ShouldBe(1);
|
|
voiceWorkDetails.SupportedLanguages[0].Language.ShouldBe(Language.Japanese);
|
|
}
|
|
} |