Implemented DLSiteClient.
This commit is contained in:
86
JSMR.Tests/Integrations/DLSite/DLSiteClientTests.cs
Normal file
86
JSMR.Tests/Integrations/DLSite/DLSiteClientTests.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using JSMR.Application.Integrations.DLSite.Models;
|
||||
using JSMR.Infrastructure.Integrations.DLSite;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Mapping;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Models;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Serialization;
|
||||
using JSMR.Tests.Utilities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Shouldly;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
|
||||
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");
|
||||
|
||||
HttpResponseMessage response = new()
|
||||
{
|
||||
Content = new StringContent(productInfoJson),
|
||||
StatusCode = HttpStatusCode.OK
|
||||
};
|
||||
|
||||
HttpClient httpClient = Substitute.For<HttpClient>();
|
||||
httpClient.BaseAddress = new Uri("https://fake.site.com/");
|
||||
|
||||
//{ BaseAddress = new Uri("https://www.dlsite.com/") };
|
||||
|
||||
httpClient.SendAsync(Arg.Any<HttpRequestMessage>(), Arg.Any<HttpCompletionOption>(), CancellationToken.None)
|
||||
.Returns(Task.FromResult(response));
|
||||
|
||||
var logger = Substitute.For<ILogger<DLSiteClient>>();
|
||||
var client = new DLSiteClient(httpClient, logger);
|
||||
|
||||
var result = await client.GetVoiceWorkDetailsAsync(["RJ01230163"], CancellationToken.None);
|
||||
|
||||
result.Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
[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(Application.Common.AIGeneration.None);
|
||||
|
||||
voiceWorkDetails.Series.ShouldNotBeNull();
|
||||
voiceWorkDetails.Series.Identifier.ShouldBe("SE0001");
|
||||
voiceWorkDetails.Series.Name.ShouldBe("Series 1");
|
||||
|
||||
voiceWorkDetails.SupportedLanguages.Length.ShouldBe(1);
|
||||
voiceWorkDetails.SupportedLanguages[0].ShouldBe(Application.Common.Language.Japanese);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user