From 1d8341e97e2166af6d844c24e6717c2ff89eae20 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 21 Apr 2024 20:00:11 +0900 Subject: [PATCH] =?UTF-8?q?#23=20DiTestBase=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Epub/ScrapingAozoraServiceTest.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs index 01dd3a7..2d10082 100644 --- a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs +++ b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs @@ -4,13 +4,22 @@ using KoeBook.Epub.Models; using KoeBook.Epub.Services; using KoeBook.Core.Models; +using Microsoft.Extensions.DependencyInjection; +using KoeBook.Epub.Contracts.Services; namespace KoeBook.Test.Epub; -public class ScrapingAozoraServiceTest +public class ScrapingAozoraServiceTest : DiTestBase { - private static readonly EpubDocument EmptySingleParagraph = new EpubDocument("", "", "", Guid.NewGuid()) { Chapters = [new Chapter() { Sections = [new Section("") { Elements = [new Paragraph()] }] }] }; + private readonly ScrapingAozoraService _scrapingAozoraService; + public ScrapingAozoraServiceTest() + { + _scrapingAozoraService = Host.Services + .GetServices() + .OfType() + .Single(); + } /// /// (htmlの要素の)テキストを"
"で囲む ///
@@ -46,10 +55,9 @@ public async void ProcessChildrenlayout1Test(string html, Paragraph expected) var mainText = doc.QuerySelector(".main_text"); if (mainText == null) Assert.Fail(); - var scraper = new ScrapingAozoraService(new SplitBraceService(), new ScrapingClientService(new httpClientFactory(), TimeProvider.System)); var document = EmptySingleParagraph; - scraper.ProcessChildren(document, mainText, ""); + _scrapingAozoraService.ProcessChildren(document, mainText, ""); Assert.Single(document.Chapters); Assert.Single(document.Chapters[^1].Sections); @@ -98,10 +106,10 @@ public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection= exceptedValue.max); + Assert.True(_scrapingAozoraService._Classes().ContainsKey(key)); + Assert.True(_scrapingAozoraService._Classes()[key].min <= exceptedValue.min); + Assert.True(_scrapingAozoraService._Classes()[key].max >= exceptedValue.max); } } }