Skip to content

Commit

Permalink
#23 DiTestBaseを使うように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
TakenPt committed Apr 21, 2024
1 parent 990c31e commit 1d8341e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IScrapingService>()
.OfType<ScrapingAozoraService>()
.Single();
}
/// <summary>
/// (htmlの要素の)テキストを"<div class = \"main_text\"></div>"で囲む
/// </summary>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -98,10 +106,10 @@ public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection<Pa
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;
_scrapingAozoraService._Classes().Clear();

scraper.ProcessChildren(document, mainText, "");
_scrapingAozoraService.ProcessChildren(document, mainText, "");

Assert.Single(document.Chapters);
Assert.Single(document.Chapters[^1].Sections);
Expand All @@ -119,9 +127,9 @@ public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection<Pa
// ScrapingAozoraService.Classes の確認
foreach ((var key, var exceptedValue) in expectedDictionary)
{
Assert.True(scraper._Classes().ContainsKey(key));
Assert.True(scraper._Classes()[key].min <= exceptedValue.min);
Assert.True(scraper._Classes()[key].max >= exceptedValue.max);
Assert.True(_scrapingAozoraService._Classes().ContainsKey(key));
Assert.True(_scrapingAozoraService._Classes()[key].min <= exceptedValue.min);
Assert.True(_scrapingAozoraService._Classes()[key].max >= exceptedValue.max);
}
}
}
Expand Down

0 comments on commit 1d8341e

Please sign in to comment.