Updated scanner to infer when it has reached the end of results.
All checks were successful
ci / build-test (push) Successful in 2m18s
ci / publish-image (push) Has been skipped

This commit is contained in:
2026-03-07 01:26:04 -05:00
parent 1e01edf1b7
commit 62c2efab01
18 changed files with 193 additions and 79 deletions

View File

@@ -0,0 +1,20 @@
using JSMR.Infrastructure.Http;
using NSubstitute;
using System.Net;
namespace JSMR.Tests.Extensions;
internal static class HttpServiceTestExtensions
{
public static void ReturnsContent(this IHttpService httpService, string content, HttpStatusCode statusCode = HttpStatusCode.OK)
{
HttpStringResponse response = new()
{
StatusCode = statusCode,
Content = content
};
httpService.GetAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
.Returns(Task.FromResult(response));
}
}

View File

@@ -0,0 +1,17 @@
using JSMR.Application.Scanning.Contracts;
using JSMR.Application.Scanning.Ports;
using Shouldly;
namespace JSMR.Tests.Extensions;
internal static class ScannerTestExtensions
{
public static async Task<IReadOnlyList<DLSiteWork>> ScanWorksAsync(this IVoiceWorksScanner scanner, VoiceWorkScanOptions options)
{
VoiceWorkScanResult result = await scanner.ScanPageAsync(options, CancellationToken.None);
result.EndOfResults.ShouldBeFalse();
return result.Works;
}
}

View File

@@ -5,6 +5,7 @@ using JSMR.Infrastructure.Http;
using JSMR.Infrastructure.Integrations.DLSite;
using JSMR.Infrastructure.Integrations.DLSite.Mapping;
using JSMR.Infrastructure.Integrations.DLSite.Models;
using JSMR.Tests.Extensions;
using JSMR.Tests.Utilities;
using Microsoft.Extensions.Logging;
using NSubstitute;
@@ -25,9 +26,7 @@ public class DLSiteClientTests
string productInfoJson = await ReadJsonResourceAsync("Product-Info.json");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(productInfoJson));
httpService.ReturnsContent(productInfoJson);
var logger = Substitute.For<ILogger<DLSiteClient>>();
var client = new DLSiteClient(httpService, logger);

View File

@@ -4,6 +4,7 @@ using JSMR.Application.Scanning.Contracts;
using JSMR.Application.Scanning.Ports;
using JSMR.Infrastructure.Http;
using JSMR.Infrastructure.Scanning;
using JSMR.Tests.Extensions;
using JSMR.Tests.Utilities;
using NSubstitute;
using Shouldly;
@@ -23,9 +24,7 @@ public class VoiceWorkScannerTests
string html = await ReadResourceAsync("Japanese-Page.html");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(html));
httpService.ReturnsContent(html);
HtmlLoader loader = new(httpService);
JapaneseVoiceWorksScanner scanner = new(loader);
@@ -38,7 +37,7 @@ public class VoiceWorkScannerTests
ExcludedMakerIds: []
);
var result = await scanner.ScanPageAsync(options, CancellationToken.None);
var result = await scanner.ScanWorksAsync(options);
result.Count.ShouldBe(1);
@@ -61,9 +60,7 @@ public class VoiceWorkScannerTests
string html = await ReadResourceAsync("Japanese-Page-Updated.html");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(html));
httpService.ReturnsContent(html);
HtmlLoader loader = new(httpService);
JapaneseVoiceWorksScanner scanner = new(loader);
@@ -76,7 +73,7 @@ public class VoiceWorkScannerTests
ExcludedMakerIds: []
);
var result = await scanner.ScanPageAsync(options, CancellationToken.None);
var result = await scanner.ScanWorksAsync(options);
result.Count.ShouldBe(2);
@@ -110,7 +107,7 @@ public class VoiceWorkScannerTests
{
IVoiceWorksScanner scanner = Substitute.For<IVoiceWorksScanner>();
IReadOnlyList<DLSiteWork> scannedWorks =
DLSiteWork[] scannedWorks =
[
new()
{
@@ -123,8 +120,13 @@ public class VoiceWorkScannerTests
}
];
VoiceWorkScanResult scanResult = new(
Works: scannedWorks,
EndOfResults: false
);
scanner.ScanPageAsync(Arg.Any<VoiceWorkScanOptions>(), CancellationToken.None)
.Returns(Task.FromResult(scannedWorks));
.Returns(Task.FromResult(scanResult));
IDLSiteClient dlsiteClient = Substitute.For<IDLSiteClient>();
@@ -155,9 +157,7 @@ public class VoiceWorkScannerTests
string englishPageHtml = await ReadResourceAsync("English-Page.html");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(englishPageHtml));
httpService.ReturnsContent(englishPageHtml);
HtmlLoader loader = new(httpService);
EnglishVoiceWorksScanner scanner = new(loader);
@@ -170,7 +170,7 @@ public class VoiceWorkScannerTests
ExcludedMakerIds: []
);
var result = await scanner.ScanPageAsync(options, CancellationToken.None);
var result = await scanner.ScanWorksAsync(options);
result.Count.ShouldBe(2);
@@ -197,9 +197,7 @@ public class VoiceWorkScannerTests
string html = await ReadResourceAsync("English-Page-Updated.html");
IHttpService httpService = Substitute.For<IHttpService>();
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
.Returns(Task.FromResult(html));
httpService.ReturnsContent(html);
HtmlLoader loader = new(httpService);
EnglishVoiceWorksScanner scanner = new(loader);
@@ -212,7 +210,7 @@ public class VoiceWorkScannerTests
ExcludedMakerIds: []
);
var result = await scanner.ScanPageAsync(options, CancellationToken.None);
var result = await scanner.ScanWorksAsync(options);
result.Count.ShouldBe(1);