From 8e6aac89392567239a83ed420023886554b649e3 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Tue, 9 Apr 2024 03:18:36 +0900 Subject: [PATCH] =?UTF-8?q?#23=20=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ScrapingAozoraService.cs | 2 +- .../Epub/ScrapingAozoraServiceTest.cs | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs index 1615bb6..7ca480c 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs @@ -19,7 +19,7 @@ public partial class ScrapingAozoraService(ISplitBraceService splitBraceService, private readonly ISplitBraceService _splitBraceService = splitBraceService; private readonly IScrapingClientService _scrapingClientService = scrapingClientService; - private EpubDocument _document; + private EpubDocument? _document; public bool IsMatchSite(Uri uri) diff --git a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs index 6b5a537..0f96c53 100644 --- a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs +++ b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs @@ -3,9 +3,6 @@ using AngleSharp.Dom; using KoeBook.Epub.Models; using KoeBook.Epub.Services; -using System.Runtime.CompilerServices; -using System.Linq; -using System.Net.Http; namespace KoeBook.Test.Epub; @@ -18,9 +15,9 @@ public static object[][] ProcessChildrenTestCases() (string, EpubDocument, EpubDocument)[] cases = [ // レイアウト // 1.1 改丁 - (ToMainText(@"[#改丁]"), EmptySingleParagraph , new EpubDocument("", "", "", Guid.NewGuid()) { Chapters = [new Chapter() { Sections = [new Section("") { Elements = [new Paragraph() { Text = "[#改丁]", ScriptLine = new Core.Models.ScriptLine("", "", "") }] }] }] }), + (@"[#改丁]", EmptySingleParagraph , new EpubDocument("", "", "", Guid.NewGuid()) { Chapters = [new Chapter() { Sections = [new Section("") { Elements = [new Paragraph() { Text = "[#改丁]", ScriptLine = new Core.Models.ScriptLine("", "", "") }] }] }] }), ]; - return cases.Select(c => new object[] { c.Item1, c.Item2, c.Item3 }).ToArray(); + return cases.Select(c => new object[] { ToMainText(c.Item1), c.Item2, c.Item3 }).ToArray(); } /// @@ -44,7 +41,7 @@ public async void ProcessChildrenTest(string html, EpubDocument initial, EpubDoc var scraper = new ScrapingAozoraService(new SplitBraceService(), new ScrapingClientService(new httpClientFactory(), TimeProvider.System)); scraper._document() = initial; - scraper.ProcessChildren(mainText); + scraper.ProcessChildren(mainText!); Assert.True(HaveSmaeText(scraper._document(), expexted)); } @@ -62,16 +59,34 @@ private static bool HaveSmaeText(EpubDocument document, EpubDocument comparison) same = (document.Title == comparison.Title); same = (document.Author == comparison.Author); same = (document.CssClasses == comparison.CssClasses); + same = (document.Chapters.Count == comparison.Chapters.Count); foreach ((Chapter selfChapter, Chapter comparisonChapter) in document.Chapters.Zip(comparison.Chapters)) { same = (selfChapter.Title == comparisonChapter.Title); + same = (selfChapter.Sections.Count == comparisonChapter.Sections.Count); foreach ((Section selfSection, Section comparisonSection) in selfChapter.Sections.Zip(comparisonChapter.Sections)) { same = (selfSection.Title == comparisonSection.Title); - - same = selfSection.Elements.Equals(comparisonSection.Elements); + same = (selfSection.Elements.Count == comparisonSection.Elements.Count); + + foreach ((KoeBook.Epub.Models.Element selfElement, KoeBook.Epub.Models.Element comparisonElement) in selfSection.Elements.Zip(comparisonSection.Elements)) + { + switch (selfElement, comparisonElement) + { + case (Paragraph selfParagraph, Paragraph comparisonParagraph): + same = (selfParagraph.Text == comparisonParagraph.Text); + same = (selfParagraph.ScriptLine?.Text == comparisonParagraph.ScriptLine?.Text); + break; + case (Picture selfPicture, Picture comparisonPicture): + same = (selfPicture.PictureFilePath == comparisonPicture.PictureFilePath); + break; + default: + same = false; + break; + } + } } }