Skip to content

Commit

Permalink
#23 ミスの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
TakenPt committed Apr 23, 2024
1 parent bc0feb1 commit b2347b3
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()] }] }]
};


/// <summary>
/// (htmlの要素の)テキストを"<div class = \"main_text\"></div>"で囲む
/// </summary>
/// <param name="text">divタグで囲むhtmlの要素</param>
/// <param name="text">divタグで囲む htmlの要素</param>
/// <returns>divタグで囲まれた<paramref name="text"/></returns>
private static string ToMainText(string text)
{
Expand All @@ -45,22 +50,22 @@ private static string ToMainText(string text)
[InlineData(@"<div><span class=""notes"">[#改見開き]</span><br></div>", "[#改見開き]", "")]
// レイアウト1.4 改段
[InlineData(@"<div><span class=""notes"">[#改段]</span><br /><div>", "[#改段]", "")]
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<Paragraph>(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);
Expand Down Expand Up @@ -92,18 +97,18 @@ public static object[][] ProcessChildrenlayout2TestCases()

[Theory]
[MemberData(nameof(ProcessChildrenlayout2TestCases))]
public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection<Paragraph> expectedParagraphs, IEnumerable<(string key, (int min, int max) value)> expectedDictionary)
public async void ProcessChildrenLayout2Test(string html, IReadOnlyCollection<Paragraph> 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);
Expand Down

0 comments on commit b2347b3

Please sign in to comment.