Skip to content

Commit

Permalink
#23 テストの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
TakenPt committed Apr 8, 2024
1 parent b7fecc1 commit 8e6aac8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 23 additions & 8 deletions KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,9 +15,9 @@ public static object[][] ProcessChildrenTestCases()
(string, EpubDocument, EpubDocument)[] cases = [
// レイアウト
// 1.1 改丁
(ToMainText(@"<span class=""notes"">[#改丁]</span>"), EmptySingleParagraph , new EpubDocument("", "", "", Guid.NewGuid()) { Chapters = [new Chapter() { Sections = [new Section("") { Elements = [new Paragraph() { Text = "[#改丁]", ScriptLine = new Core.Models.ScriptLine("", "", "") }] }] }] }),
(@"<span class=""notes"">[#改丁]</span>", 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();
}

/// <summary>
Expand All @@ -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));
}
Expand All @@ -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;
}
}
}
}

Expand Down

0 comments on commit 8e6aac8

Please sign in to comment.