Skip to content

Commit

Permalink
#5-1 IVTを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Mar 3, 2024
1 parent 40917b3 commit e3c60f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Epub/KoeBook.Epub/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;

// PrivateProxyが外部プロジェクトに対応していないため
[assembly: InternalsVisibleTo("KoeBook.Test")]
4 changes: 4 additions & 0 deletions KoeBook.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;

// PrivateProxyが外部プロジェクトに対応していないため
[assembly: InternalsVisibleTo("KoeBook.Test")]
30 changes: 17 additions & 13 deletions KoeBook.Test/Epub/EpubDocumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<IndexOutOfRangeException>(exception);
Assert.IsType<ArgumentOutOfRangeException>(exception);
}

[Fact]
Expand All @@ -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);
Expand All @@ -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<Paragraph>(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<Paragraph>(element);
Expand All @@ -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<IndexOutOfRangeException>(exception);
Assert.IsType<ArgumentOutOfRangeException>(exception);
}
#endregion
}

0 comments on commit e3c60f2

Please sign in to comment.