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);
|
||||
}
|
||||
}
|
||||
223
JSMR.Tests/Integrations/DLSite/Product-Info.json
Normal file
223
JSMR.Tests/Integrations/DLSite/Product-Info.json
Normal file
@@ -0,0 +1,223 @@
|
||||
{
|
||||
"RJ01230163": {
|
||||
"site_id": "home",
|
||||
"site_id_touch": "hometouch",
|
||||
"maker_id": "RG64308",
|
||||
"age_category": 1,
|
||||
"affiliate_deny": 0,
|
||||
"dl_count": 659,
|
||||
"wishlist_count": 380,
|
||||
"dl_format": 0,
|
||||
"rank": [
|
||||
{
|
||||
"term": "day",
|
||||
"category": "voice",
|
||||
"rank": 20,
|
||||
"rank_date": "2024-07-21"
|
||||
},
|
||||
{
|
||||
"term": "week",
|
||||
"category": "voice",
|
||||
"rank": 46,
|
||||
"rank_date": "2024-07-26"
|
||||
}
|
||||
],
|
||||
"rate_average": 5,
|
||||
"rate_average_2dp": 4.92,
|
||||
"rate_average_star": 50,
|
||||
"rate_count": 37,
|
||||
"rate_count_detail": [
|
||||
{
|
||||
"review_point": 1,
|
||||
"count": 0,
|
||||
"ratio": 0
|
||||
},
|
||||
{
|
||||
"review_point": 2,
|
||||
"count": 0,
|
||||
"ratio": 0
|
||||
},
|
||||
{
|
||||
"review_point": 3,
|
||||
"count": 0,
|
||||
"ratio": 0
|
||||
},
|
||||
{
|
||||
"review_point": 4,
|
||||
"count": 3,
|
||||
"ratio": 8
|
||||
},
|
||||
{
|
||||
"review_point": 5,
|
||||
"count": 34,
|
||||
"ratio": 91
|
||||
}
|
||||
],
|
||||
"review_count": 1,
|
||||
"price": 1650,
|
||||
"price_without_tax": 1500,
|
||||
"price_str": "1,650",
|
||||
"default_point_rate": 10,
|
||||
"default_point": 150,
|
||||
"product_point_rate": null,
|
||||
"dlsiteplay_work": true,
|
||||
"is_ana": false,
|
||||
"is_sale": true,
|
||||
"on_sale": 1,
|
||||
"is_discount": false,
|
||||
"is_pointup": false,
|
||||
"gift": [],
|
||||
"is_rental": false,
|
||||
"work_rentals": [],
|
||||
"upgrade_min_price": 110,
|
||||
"down_url": "https:\/\/www.dlsite.com\/maniax\/download\/split\/=\/product_id\/RJ01230163.html",
|
||||
"is_tartget": "blank",
|
||||
"title_id": "SRI0000032800",
|
||||
"title_name": "Commander Pampering Team!",
|
||||
"title_name_masked": "Commander Pampering Team!",
|
||||
"title_volumn": null,
|
||||
"title_work_count": 21,
|
||||
"is_title_completed": false,
|
||||
"bulkbuy_key": null,
|
||||
"bonuses": [],
|
||||
"is_limit_work": false,
|
||||
"is_sold_out": false,
|
||||
"limit_stock": 0,
|
||||
"is_reserve_work": false,
|
||||
"is_reservable": false,
|
||||
"is_timesale": false,
|
||||
"timesale_stock": 0,
|
||||
"is_free": false,
|
||||
"is_oly": true,
|
||||
"is_led": false,
|
||||
"is_noreduction": false,
|
||||
"is_wcc": false,
|
||||
"translation_info": {
|
||||
"is_translation_agree": false,
|
||||
"is_volunteer": false,
|
||||
"is_original": true,
|
||||
"is_parent": false,
|
||||
"is_child": false,
|
||||
"is_translation_bonus_child": false,
|
||||
"original_workno": null,
|
||||
"parent_workno": null,
|
||||
"child_worknos": [],
|
||||
"lang": null,
|
||||
"production_trade_price_rate": 0,
|
||||
"translation_bonus_langs": []
|
||||
},
|
||||
"work_name": "[Azur Lane ASMR] Commander Pampering Team! Golden Hind's Tentacular Treatment",
|
||||
"work_name_masked": "[Azur Lane ASMR] Commander Pampering Team! Golden Hind's Tentacular Treatment",
|
||||
"work_image": "\/\/img.dlsite.jp\/modpub\/images2\/work\/doujin\/RJ01231000\/RJ01230163_img_main.jpg",
|
||||
"sales_end_info": null,
|
||||
"voice_pack": null,
|
||||
"regist_date": "2024-07-20 00:00:00",
|
||||
"locale_price": {
|
||||
"en_US": 11.13,
|
||||
"ar_AE": 11.13,
|
||||
"es_ES": 9.55,
|
||||
"de_DE": 9.55,
|
||||
"fr_FR": 9.55,
|
||||
"it_IT": 9.55,
|
||||
"pt_BR": 9.55,
|
||||
"zh_TW": 342,
|
||||
"zh_CN": 79.45,
|
||||
"ko_KR": 15464,
|
||||
"id_ID": 182744,
|
||||
"vi_VN": 292657,
|
||||
"th_TH": 359.49,
|
||||
"sv_SE": 105.03
|
||||
},
|
||||
"locale_price_str": {
|
||||
"en_US": "$11.13<i> USD<\/i>",
|
||||
"ar_AE": "$11.13<i> USD<\/i>",
|
||||
"es_ES": "9,55<i> \u20ac<\/i>",
|
||||
"de_DE": "9,55<i> \u20ac<\/i>",
|
||||
"fr_FR": "9,55<i> \u20ac<\/i>",
|
||||
"it_IT": "9,55<i> \u20ac<\/i>",
|
||||
"pt_BR": "9,55<i> \u20ac<\/i>",
|
||||
"zh_TW": "<i>NT$<\/i>342",
|
||||
"zh_CN": "79.45<i> RMB<\/i>",
|
||||
"ko_KR": "15,464<i> \u20a9<\/i>",
|
||||
"id_ID": "<i>Rp <\/i>182.744",
|
||||
"vi_VN": "292.657<i>\u20ab<\/i>",
|
||||
"th_TH": "<i>\u0e3f<\/i>359.49",
|
||||
"sv_SE": "105,03<i> kr<\/i>"
|
||||
},
|
||||
"currency_price": {
|
||||
"JPY": 1650,
|
||||
"USD": 11.13364080175709,
|
||||
"EUR": 9.549655604692873,
|
||||
"GBP": 8.290615726443848,
|
||||
"TWD": 341.92639257294434,
|
||||
"CNY": 79.4453271703019,
|
||||
"KRW": 15463.917525773195,
|
||||
"IDR": 182744.4899767416,
|
||||
"VND": 292656.9705569351,
|
||||
"THB": 359.4927883567911,
|
||||
"SEK": 105.03265560747069,
|
||||
"HKD": 86.85627655038454,
|
||||
"SGD": 14.338300468210683,
|
||||
"CAD": 15.361798280037203,
|
||||
"MYR": 47.01310098414091,
|
||||
"BRL": 60.70282838390676,
|
||||
"AUD": 17.02427971820174,
|
||||
"PHP": 637.7058050552678,
|
||||
"MXN": 208.2912542920622,
|
||||
"NZD": 18.956888588642414,
|
||||
"INR": 979.5191451469278
|
||||
},
|
||||
"work_type": "SOU",
|
||||
"book_type": null,
|
||||
"discount_calc_type": null,
|
||||
"is_pack_work": false,
|
||||
"limited_free_terms": [],
|
||||
"official_price": 1650,
|
||||
"options": "SND#TRI#DLP#ENG#REV",
|
||||
"custom_genres": [ "dlsiteaward2024" ],
|
||||
"dl_count_total": 12524,
|
||||
"dl_count_items": [
|
||||
{
|
||||
"workno": "RJ01230156",
|
||||
"edition_id": 25712,
|
||||
"edition_type": "language",
|
||||
"display_order": 1,
|
||||
"label": "\u65e5\u672c\u8a9e",
|
||||
"lang": "JPN",
|
||||
"dl_count": "10529",
|
||||
"display_label": "Japanese"
|
||||
},
|
||||
{
|
||||
"workno": "RJ01230163",
|
||||
"edition_id": 25712,
|
||||
"edition_type": "language",
|
||||
"display_order": 2,
|
||||
"label": "\u82f1\u8a9e",
|
||||
"lang": "ENG",
|
||||
"dl_count": "659",
|
||||
"display_label": "English"
|
||||
},
|
||||
{
|
||||
"workno": "RJ01230165",
|
||||
"edition_id": 25712,
|
||||
"edition_type": "language",
|
||||
"display_order": 3,
|
||||
"label": "\u7c21\u4f53\u4e2d\u6587",
|
||||
"lang": "CHI_HANS",
|
||||
"dl_count": "811",
|
||||
"display_label": "Chinese Simplified"
|
||||
},
|
||||
{
|
||||
"workno": "RJ01230167",
|
||||
"edition_id": 25712,
|
||||
"edition_type": "language",
|
||||
"display_order": 4,
|
||||
"label": "\u7e41\u4f53\u4e2d\u6587",
|
||||
"lang": "CHI_HANT",
|
||||
"dl_count": "525",
|
||||
"display_label": "Chinese Traditional"
|
||||
}
|
||||
],
|
||||
"default_point_str": "150"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user