From 3ef936451f3b7be6348fdd80b66ccfcb71ed39d7 Mon Sep 17 00:00:00 2001 From: TakenPt Date: Sun, 21 Apr 2024 20:53:43 +0900 Subject: [PATCH] =?UTF-8?q?#23=20ProcessChildrenlayout2Test=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE=E5=A4=89=E6=9B=B4(Assert.S?= =?UTF-8?q?ingle,=20Assert.All=E3=81=AE=E4=BD=BF=E7=94=A8=E3=81=AB?= =?UTF-8?q?=E3=81=A4=E3=81=84=E3=81=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Epub/ScrapingAozoraServiceTest.cs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs index 4866d5f..704d50f 100644 --- a/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs +++ b/KoeBook.Test/Epub/ScrapingAozoraServiceTest.cs @@ -104,7 +104,7 @@ public static object[][] ProcessChildrenlayout2TestCases() [Theory] [MemberData(nameof(ProcessChildrenlayout2TestCases))] - public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection expectedParagraphs, IEnumerable<(string, (int min, int max))> 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); @@ -117,27 +117,24 @@ public async void ProcessChildrenlayout2Test(string html, IReadOnlyCollection(actualElement); - if (actualElement is Paragraph actualParagraph) + Assert.All(expectedParagraphs.Zip(document.Chapters[^1].Sections[^1].Elements), v => { - Assert.Equal(expectedParagraph.Text, actualParagraph.Text); - Assert.Equal(expectedParagraph.ClassName, actualParagraph.ClassName); + var actualParagraph = Assert.IsType(v.Second); + Assert.Equal(v.First.Text, actualParagraph.Text); + Assert.Equal(v.First.ClassName, actualParagraph.ClassName); Assert.NotNull(actualParagraph.ScriptLine); - Assert.Equal(expectedParagraph.ScriptLine?.Text, actualParagraph.ScriptLine.Text); - } + Assert.Equal(v.First.ScriptLine?.Text, actualParagraph.ScriptLine.Text); + }); // ScrapingAozoraService.Classes の確認 - foreach ((var key, var exceptedValue) in expectedDictionary) + Assert.All(expectedDictionary, expectedKeyValuePair => { - Assert.True(_scrapingAozoraService._Classes().ContainsKey(key)); - Assert.True(_scrapingAozoraService._Classes()[key].min <= exceptedValue.min); - Assert.True(_scrapingAozoraService._Classes()[key].max >= exceptedValue.max); - } - } + Assert.True(_scrapingAozoraService._Classes().TryGetValue(expectedKeyValuePair.key, out var actualValue)); + Assert.True(actualValue.min <= expectedKeyValuePair.value.min); + Assert.True(actualValue.max >= expectedKeyValuePair.value.max); + }); } internal class httpClientFactory : IHttpClientFactory