From f7e8ce1c29c802b119625b625d785cb56e014751 Mon Sep 17 00:00:00 2001 From: miyaji255 <84168445+miyaji255@users.noreply.github.com> Date: Sat, 2 Mar 2024 18:58:52 +0900 Subject: [PATCH 1/4] =?UTF-8?q?#5-1=20EpubDocument=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E4=BD=9C=E6=88=90=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/EpubDocumentTest.cs | 132 ++++++++++++++++++++++++++ KoeBook.Test/KoeBook.Test.csproj | 4 + KoeBook.Test/Proxies/EpubModels.cs | 7 ++ 3 files changed, 143 insertions(+) create mode 100644 KoeBook.Test/Epub/EpubDocumentTest.cs create mode 100644 KoeBook.Test/Proxies/EpubModels.cs diff --git a/KoeBook.Test/Epub/EpubDocumentTest.cs b/KoeBook.Test/Epub/EpubDocumentTest.cs new file mode 100644 index 0000000..008b136 --- /dev/null +++ b/KoeBook.Test/Epub/EpubDocumentTest.cs @@ -0,0 +1,132 @@ +using KoeBook.Epub.Models; +using KoeBook.Test.Proxies; + +namespace KoeBook.Test.Epub; + +public class EpubDocumentTest +{ + #region Ensure List + [Fact] + public void EnsureChapter() + { + var document = new EpubDocument("title", "author", "cover", default); + + Assert.Empty(document.Chapters); + + // 空のときは追加 + document.AsPrivateProxy().EnsureChapter(); + + var chapter = Assert.Single(document.Chapters); + Assert.Null(chapter.Title); + Assert.Empty(chapter.Sections); + + // 空でないときは無視 + document.AsPrivateProxy().EnsureChapter(); + + var chapter2 = Assert.Single(document.Chapters); + Assert.Same(chapter, chapter2); + } + + [Fact] + public void EnsureSection() + { + var document = new EpubDocument("title", "author", "cover", default); + + Assert.Empty(document.Chapters); + + // 空のときは追加される + document.AsPrivateProxy().EnsureSection(0); + + var chapter = Assert.Single(document.Chapters); + Assert.Null(chapter.Title); + var section = Assert.Single(chapter.Sections); + Assert.Equal("title", section.Title); + Assert.Empty(section.Elements); + + // 空でないときは無視 + document.Chapters = [ + new() { + Title = "chapter1", + Sections = [ + new("section1"), + new("section2"), + new("section3"), + ], + }, + new() { + Title = "chapter2", + Sections = [], + }, + ]; + + document.AsPrivateProxy().EnsureSection(0); + + Assert.Equal(3, document.Chapters[0].Sections.Count); + + document.AsPrivateProxy().EnsureSection(1); + + Assert.Equal("chapter2", document.Chapters[1].Sections[0].Title); + + // インデックスは正しく指定する必要がある + var exception = Record.Exception(() => document.AsPrivateProxy().EnsureSection(5)); + + Assert.IsType(exception); + } + + [Fact] + public void EnsureParagraph() + { + var document = new EpubDocument("title", "author", "cover", default); + + Assert.Empty(document.Chapters); + + // 空のときは追加される + document.AsPrivateProxy().EnsureParagraph(0, 0); + + var chapter = Assert.Single(document.Chapters); + var section = Assert.Single(chapter.Sections); + var element = Assert.Single(section.Elements); + var paragraph = Assert.IsType(element); + Assert.Null(paragraph.Audio); + Assert.Null(paragraph.Text); + Assert.Null(paragraph.ClassName); + + // 空でないときは無視 + document.Chapters = [ + new() { + Title = "chapter1", + Sections = [ + new("section1") { + Elements = [ + new Paragraph() { + Text = "paragraph1", + }, + ] + }, + ], + }, + ]; + + document.AsPrivateProxy().EnsureParagraph(0, 0); + + chapter = Assert.Single(document.Chapters); + section = Assert.Single(chapter.Sections); + element = Assert.Single(section.Elements); + paragraph = Assert.IsType(element); + Assert.Equal("paragraph1", paragraph.Text); + + document.AsPrivateProxy().EnsureParagraph(0, 1); + + element = Assert.Single(document.Chapters[0].Sections[1].Elements); + paragraph = Assert.IsType(element); + Assert.Null(paragraph.Audio); + Assert.Null(paragraph.Text); + Assert.Null(paragraph.ClassName); + + // インデックスは正しく指定する必要がある + var exception = Record.Exception(() => document.AsPrivateProxy().EnsureParagraph(0, 5)); + + Assert.IsType(exception); + } + #endregion +} diff --git a/KoeBook.Test/KoeBook.Test.csproj b/KoeBook.Test/KoeBook.Test.csproj index c085021..2658a8d 100644 --- a/KoeBook.Test/KoeBook.Test.csproj +++ b/KoeBook.Test/KoeBook.Test.csproj @@ -12,6 +12,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/KoeBook.Test/Proxies/EpubModels.cs b/KoeBook.Test/Proxies/EpubModels.cs new file mode 100644 index 0000000..7a9822f --- /dev/null +++ b/KoeBook.Test/Proxies/EpubModels.cs @@ -0,0 +1,7 @@ +using KoeBook.Epub.Models; +using PrivateProxy; + +namespace KoeBook.Test.Proxies; + +[GeneratePrivateProxy(typeof(EpubDocument))] +partial struct EpubDocumentProxy; From 2171f647c6998b4d6664397f754f2214edf304f4 Mon Sep 17 00:00:00 2001 From: miyaji255 <84168445+miyaji255@users.noreply.github.com> Date: Sun, 3 Mar 2024 20:50:45 +0900 Subject: [PATCH 2/4] =?UTF-8?q?#5-1=20IVT=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Properties/AssemblyInfo.cs | 4 +++ KoeBook.Core/Properties/AssemblyInfo.cs | 4 +++ KoeBook.Test/Epub/EpubDocumentTest.cs | 30 +++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 Epub/KoeBook.Epub/Properties/AssemblyInfo.cs create mode 100644 KoeBook.Core/Properties/AssemblyInfo.cs diff --git a/Epub/KoeBook.Epub/Properties/AssemblyInfo.cs b/Epub/KoeBook.Epub/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9a2272a --- /dev/null +++ b/Epub/KoeBook.Epub/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +// PrivateProxyが外部プロジェクトに対応していないため +[assembly: InternalsVisibleTo("KoeBook.Test")] diff --git a/KoeBook.Core/Properties/AssemblyInfo.cs b/KoeBook.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9a2272a --- /dev/null +++ b/KoeBook.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +// PrivateProxyが外部プロジェクトに対応していないため +[assembly: InternalsVisibleTo("KoeBook.Test")] diff --git a/KoeBook.Test/Epub/EpubDocumentTest.cs b/KoeBook.Test/Epub/EpubDocumentTest.cs index 008b136..69138f1 100644 --- a/KoeBook.Test/Epub/EpubDocumentTest.cs +++ b/KoeBook.Test/Epub/EpubDocumentTest.cs @@ -14,14 +14,14 @@ public void EnsureChapter() Assert.Empty(document.Chapters); // 空のときは追加 - document.AsPrivateProxy().EnsureChapter(); + document.EnsureChapter(); var chapter = Assert.Single(document.Chapters); Assert.Null(chapter.Title); Assert.Empty(chapter.Sections); // 空でないときは無視 - document.AsPrivateProxy().EnsureChapter(); + document.EnsureChapter(); var chapter2 = Assert.Single(document.Chapters); Assert.Same(chapter, chapter2); @@ -35,7 +35,7 @@ public void EnsureSection() Assert.Empty(document.Chapters); // 空のときは追加される - document.AsPrivateProxy().EnsureSection(0); + document.EnsureSection(0); var chapter = Assert.Single(document.Chapters); Assert.Null(chapter.Title); @@ -59,18 +59,18 @@ public void EnsureSection() }, ]; - document.AsPrivateProxy().EnsureSection(0); + document.EnsureSection(0); Assert.Equal(3, document.Chapters[0].Sections.Count); - document.AsPrivateProxy().EnsureSection(1); + document.EnsureSection(1); Assert.Equal("chapter2", document.Chapters[1].Sections[0].Title); // インデックスは正しく指定する必要がある - var exception = Record.Exception(() => document.AsPrivateProxy().EnsureSection(5)); + var exception = Record.Exception(() => document.EnsureSection(5)); - Assert.IsType(exception); + Assert.IsType(exception); } [Fact] @@ -81,7 +81,7 @@ public void EnsureParagraph() Assert.Empty(document.Chapters); // 空のときは追加される - document.AsPrivateProxy().EnsureParagraph(0, 0); + document.EnsureParagraph(0, 0); var chapter = Assert.Single(document.Chapters); var section = Assert.Single(chapter.Sections); @@ -103,19 +103,23 @@ public void EnsureParagraph() }, ] }, + new("section1") { + Elements = [] + }, ], }, ]; - document.AsPrivateProxy().EnsureParagraph(0, 0); + document.EnsureParagraph(0, 0); chapter = Assert.Single(document.Chapters); - section = Assert.Single(chapter.Sections); + Assert.Equal(2, chapter.Sections.Count); + section = chapter.Sections[0]; element = Assert.Single(section.Elements); paragraph = Assert.IsType(element); Assert.Equal("paragraph1", paragraph.Text); - document.AsPrivateProxy().EnsureParagraph(0, 1); + document.EnsureParagraph(0, 1); element = Assert.Single(document.Chapters[0].Sections[1].Elements); paragraph = Assert.IsType(element); @@ -124,9 +128,9 @@ public void EnsureParagraph() Assert.Null(paragraph.ClassName); // インデックスは正しく指定する必要がある - var exception = Record.Exception(() => document.AsPrivateProxy().EnsureParagraph(0, 5)); + var exception = Record.Exception(() => document.EnsureParagraph(0, 5)); - Assert.IsType(exception); + Assert.IsType(exception); } #endregion } From fb8d6bc10a0fcec5990fbe42235b26913b108539 Mon Sep 17 00:00:00 2001 From: miyaji255 <84168445+miyaji255@users.noreply.github.com> Date: Sun, 3 Mar 2024 20:51:45 +0900 Subject: [PATCH 3/4] fmt --- KoeBook.Test/Epub/EpubDocumentTest.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/KoeBook.Test/Epub/EpubDocumentTest.cs b/KoeBook.Test/Epub/EpubDocumentTest.cs index 69138f1..e9209a8 100644 --- a/KoeBook.Test/Epub/EpubDocumentTest.cs +++ b/KoeBook.Test/Epub/EpubDocumentTest.cs @@ -45,7 +45,8 @@ public void EnsureSection() // 空でないときは無視 document.Chapters = [ - new() { + new() + { Title = "chapter1", Sections = [ new("section1"), @@ -53,7 +54,8 @@ public void EnsureSection() new("section3"), ], }, - new() { + new() + { Title = "chapter2", Sections = [], }, @@ -93,17 +95,21 @@ public void EnsureParagraph() // 空でないときは無視 document.Chapters = [ - new() { + new() + { Title = "chapter1", Sections = [ - new("section1") { + new("section1") + { Elements = [ - new Paragraph() { + new Paragraph() + { Text = "paragraph1", }, ] }, - new("section1") { + new("section1") + { Elements = [] }, ], From 3864450a5edbe99cd79dbab17a2359ab2536b0ce Mon Sep 17 00:00:00 2001 From: miyaji255 <84168445+miyaji255@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:17:28 +0900 Subject: [PATCH 4/4] =?UTF-8?q?#5-1=20PrivateProxy=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KoeBook.Test/Epub/EpubDocumentTest.cs | 1 - KoeBook.Test/KoeBook.Test.csproj | 4 ---- KoeBook.Test/Proxies/EpubModels.cs | 7 ------- 3 files changed, 12 deletions(-) delete mode 100644 KoeBook.Test/Proxies/EpubModels.cs diff --git a/KoeBook.Test/Epub/EpubDocumentTest.cs b/KoeBook.Test/Epub/EpubDocumentTest.cs index e9209a8..6ce0f15 100644 --- a/KoeBook.Test/Epub/EpubDocumentTest.cs +++ b/KoeBook.Test/Epub/EpubDocumentTest.cs @@ -1,5 +1,4 @@ using KoeBook.Epub.Models; -using KoeBook.Test.Proxies; namespace KoeBook.Test.Epub; diff --git a/KoeBook.Test/KoeBook.Test.csproj b/KoeBook.Test/KoeBook.Test.csproj index 2658a8d..c085021 100644 --- a/KoeBook.Test/KoeBook.Test.csproj +++ b/KoeBook.Test/KoeBook.Test.csproj @@ -12,10 +12,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/KoeBook.Test/Proxies/EpubModels.cs b/KoeBook.Test/Proxies/EpubModels.cs deleted file mode 100644 index 7a9822f..0000000 --- a/KoeBook.Test/Proxies/EpubModels.cs +++ /dev/null @@ -1,7 +0,0 @@ -using KoeBook.Epub.Models; -using PrivateProxy; - -namespace KoeBook.Test.Proxies; - -[GeneratePrivateProxy(typeof(EpubDocument))] -partial struct EpubDocumentProxy;