forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using KoeBook.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace KoeBook.Test; | ||
|
||
public class DiTestBase | ||
{ | ||
protected IHost Host { get; } = Microsoft.Extensions.Hosting.Host | ||
.CreateDefaultBuilder() | ||
.ConfigureCore() | ||
.Build(); | ||
|
||
protected T GetService<T>() where T: notnull | ||
{ | ||
return Host.Services.GetRequiredService<T>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using KoeBook.Core; | ||
using KoeBook.Epub.Contracts.Services; | ||
using KoeBook.Epub.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace KoeBook.Test.Epub; | ||
|
||
public class ScrapingNaroServiceTest : DiTestBase | ||
{ | ||
private readonly ScrapingNaroService _scrapingNaroService; | ||
|
||
public ScrapingNaroServiceTest() | ||
{ | ||
_scrapingNaroService = Host.Services | ||
.GetServices<IScrapingService>() | ||
.OfType<ScrapingNaroService>() | ||
.Single(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://ncode.syosetu.com/n0000a", "n0000a")] | ||
[InlineData("https://ncode.syosetu.com/n0000a/", "n0000a")] | ||
[InlineData("https://ncode.syosetu.com/n0000a/123", "n0000a")] | ||
[InlineData("https://ncode.syosetu.com/n0000a/123/", "n0000a")] | ||
[InlineData("https://ncode.syosetu.com/novelview/infotop/ncode/n0000a", "n0000a")] | ||
[InlineData("https://ncode.syosetu.com/novelview/infotop/ncode/n0000a/", "n0000a")] | ||
public void GetNcode_Success(string url, string? expected) | ||
{ | ||
var result = ScrapingNaroService.GetNcode(url); | ||
|
||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://ncode.syosetu.com/n0000あ")] | ||
[InlineData("https://ncode.syosetu.com/n0000あ/")] | ||
[InlineData("https://ncode.syosetu.com/n0000aあ/123")] | ||
[InlineData("https://ncode.syosetu.com/n0000aあ/123/")] | ||
public void GetNcode_Error(string url) | ||
{ | ||
var exception = Record.Exception(() => ScrapingNaroService.GetNcode(url)); | ||
|
||
var ebookException = Assert.IsType<EbookException>(exception); | ||
Assert.Equal(ExceptionType.InvalidUrl, ebookException.ExceptionType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using KoeBook.Core.Contracts.Services; | ||
using KoeBook.Core.Services; | ||
using KoeBook.Epub.Contracts.Services; | ||
using KoeBook.Epub.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace KoeBook.Core; | ||
|
||
internal static class Startup | ||
{ | ||
/// <summary> | ||
/// System, Core, Epub のDIを登録します | ||
/// </summary> | ||
public static IHostBuilder ConfigureCore(this IHostBuilder builder) | ||
{ | ||
builder.ConfigureServices((context, services) => | ||
{ | ||
// System | ||
services.AddSingleton(TimeProvider.System); | ||
// Core Services | ||
services.AddHttpClient() | ||
.ConfigureHttpClientDefaults(builder => | ||
{ | ||
builder.SetHandlerLifetime(TimeSpan.FromMinutes(5)); | ||
}); | ||
services.AddSingleton<IFileService, FileService>(); | ||
services.AddSingleton<ISecretSettingsService, SecretSettingsService>(); | ||
services.AddSingleton<IStyleBertVitsClientService, StyleBertVitsClientService>(); | ||
services.AddSingleton<ISoundGenerationSelectorService, SoundGenerationSelectorService>(); | ||
services.AddSingleton<ISoundGenerationService, SoundGenerationService>(); | ||
services.AddSingleton<IEpubGenerateService, EpubGenerateService>(); | ||
services.AddSingleton<IEpubDocumentStoreService, EpubDocumentStoreService>(); | ||
services.AddSingleton<IAnalyzerService, AnalyzerService>(); | ||
services.AddSingleton<ILlmAnalyzerService, ChatGptAnalyzerService>(); | ||
services.AddSingleton<OpenAI.Interfaces.IOpenAIService, MyOpenAiService>(); | ||
// Epub Services | ||
services | ||
.AddKeyedSingleton<IScrapingClientService, ScrapingClientService>(nameof(ScrapingAozoraService)) | ||
.AddKeyedSingleton<IScrapingClientService, ScrapingClientService>(nameof(ScrapingNaroService)) | ||
.AddSingleton<IScraperSelectorService, ScraperSelectorService>() | ||
.AddSingleton<IScrapingService, ScrapingAozoraService>() | ||
.AddSingleton<IScrapingService, ScrapingNaroService>(); | ||
services.AddSingleton<IEpubCreateService, EpubCreateService>(); | ||
services.AddSingleton<IFileExtensionService, FileExtensionService>(); | ||
}); | ||
|
||
return builder; | ||
} | ||
} |