Updated scanner logic, and added initial scanner tests.

This commit is contained in:
2025-09-14 21:12:00 -04:00
parent 39274165cb
commit 646cf41476
16 changed files with 412 additions and 192 deletions

View File

@@ -0,0 +1,53 @@
using JSMR.Application.Scanning.Contracts;
using JSMR.Infrastructure.Http;
using JSMR.Infrastructure.Scanning;
using JSMR.Tests.Utilities;
using NSubstitute;
using Shouldly;
namespace JSMR.Tests.Integrations.DLSite;
public class VoiceWorkScannerTests
{
private static async Task<string> ReadResourceAsync(string resourceName)
{
return await ResourceHelper.ReadAsync($"JSMR.Tests.Scanning.{resourceName}");
}
[Fact]
public async Task Scan_With_English_Locale()
{
string englishPageHtml = await ReadResourceAsync("English-Page.html");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(englishPageHtml));
HtmlLoader loader = new(httpService);
EnglishVoiceWorksScanner scanner = new(loader);
VoiceWorkScanOptions options = new(
PageNumber: 1,
PageSize: 100,
ExcludeAIGeneratedWorks: true,
ExcludePartiallyAIGeneratedWorks: true,
ExcludedMakerIds: []
);
var result = await scanner.ScanPageAsync(options, CancellationToken.None);
result.Count.ShouldBe(2);
result[0].ExpectedDate.ShouldBeNull();
result[0].SalesDate.ShouldBe(new DateOnly(2025, 9, 6));
result[0].ProductId.ShouldBe("RJ00000001");
result[0].ProductName.ShouldBe("Title of Product");
result[0].Description.ShouldBe("Description of the product.");
result[0].Downloads.ShouldBe(1000);
result[1].ExpectedDate.ShouldBe(new DateOnly(2025, 10, 11));
result[1].SalesDate.ShouldBeNull();
result[1].ProductId.ShouldBe("RJ00000002");
}
}