From b2347b3cb9795e2372a1fc5983139d38ec7e35f1 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 23 Apr 2024 20:11:05 +0900 Subject: [PATCH] =?UTF-8?q?#23=20=E3=83=9F=E3=82=B9=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Epub/ScrapingAozoraServiceTest.cs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs index 5617d30..819b816 100644 --- a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs +++ b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs @@ -6,6 +6,7 @@ using KoeBook.Core.Models; using Microsoft.Extensions.DependencyInjection; using KoeBook.Epub.Contracts.Services; +using AngleSharp.Html.Dom; namespace KoeBook.Test.Epub; @@ -22,14 +23,18 @@ public ScrapingAozoraServiceTest() } private static EpubDocument EmptySingleParagraph - { - get { return new EpubDocument("", "", "", Guid.NewGuid()) { Chapters = [new Chapter() { Sections = [new Section("") { Elements = [new Paragraph()] }] }] }; } - } + => new("", "", "", Guid.NewGuid()) + { + Chapters = [ + new () { + Sections = [new Section("") { Elements = [new Paragraph()] }] }] + }; + /// /// (htmlの要素の)テキストを"
"で囲む ///
- /// divタグで囲むhtmlの要素 + /// divタグで囲む htmlの要素 /// divタグで囲まれた private static string ToMainText(string text) { @@ -45,22 +50,22 @@ private static string ToMainText(string text) [InlineData(@"
[#改見開き]
", "[#改見開き]", "")] // レイアウト1.4 改段 [InlineData(@"
[#改段]
", "[#改段]", "")] - public async void ProcessChildrenlayout1Test(string html, string expectedPragraphText, string expectedScriptText) + public async void ProcessChildrenLayout1Test(string html, string expectedParagraphText, string expectedScriptText) { var config = Configuration.Default.WithDefaultLoader(); using var context = BrowsingContext.New(config); var doc = await context.OpenAsync(request => request.Content(html)); - var mainText = doc.DocumentElement.LastElementChild?.LastElementChild; + var mainText = doc.DocumentElement.LastElementChild?.LastElementChild as IHtmlDivElement; if (mainText == null) Assert.Fail(); var document = EmptySingleParagraph; - _scrapingAozoraService.ProcessChildren(document, mainText, ""); + _scrapingAozoraService.ProcessMainText(document, mainText); var chapter = Assert.Single(document.Chapters); var section = Assert.Single(chapter.Sections); var paragraph = Assert.IsType(section.Elements[^1]); - Assert.Equal(expectedPragraphText, paragraph.Text); + Assert.Equal(expectedParagraphText, paragraph.Text); Assert.Equal(string.Empty, paragraph.ClassName); Assert.NotNull(paragraph.ScriptLine); Assert.Equal(expectedScriptText, paragraph.ScriptLine.Text); @@ -92,18 +97,18 @@ public static object[][] ProcessChildrenlayout2TestCases() [Theory] [MemberData(nameof(ProcessChildrenlayout2TestCases))] - public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection expectedParagraphs, IEnumerable<(string key, (int min, int max) value)> expectedDictionary) + public async void ProcessChildrenLayout2Test(string html, IReadOnlyCollection expectedParagraphs, IEnumerable<(string key, (int min, int max) value)> expectedDictionary) { var config = Configuration.Default.WithDefaultLoader(); using var context = BrowsingContext.New(config); var doc = await context.OpenAsync(request => request.Content(html)); - var mainText = doc.QuerySelector(".main_text"); + var mainText = doc.QuerySelector(".main_text") as IHtmlDivElement; if (mainText == null) Assert.Fail(); var document = EmptySingleParagraph; _scrapingAozoraService._Classes().Clear(); - _scrapingAozoraService.ProcessChildren(document, mainText, ""); + _scrapingAozoraService.ProcessMainText(document, mainText); var chapter = Assert.Single(document.Chapters); var section = Assert.Single(chapter.Sections);