-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
Check failure on line 17 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
var chapter = Assert.Single(document.Chapters); | ||
Assert.Null(chapter.Title); | ||
Assert.Empty(chapter.Sections); | ||
|
||
// 空でないときは無視 | ||
document.AsPrivateProxy().EnsureChapter(); | ||
Check failure on line 24 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
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); | ||
Check failure on line 38 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
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); | ||
Check failure on line 62 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
Assert.Equal(3, document.Chapters[0].Sections.Count); | ||
|
||
document.AsPrivateProxy().EnsureSection(1); | ||
Check failure on line 66 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
Assert.Equal("chapter2", document.Chapters[1].Sections[0].Title); | ||
|
||
// インデックスは正しく指定する必要がある | ||
var exception = Record.Exception(() => document.AsPrivateProxy().EnsureSection(5)); | ||
Check failure on line 71 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
Assert.IsType<IndexOutOfRangeException>(exception); | ||
} | ||
|
||
[Fact] | ||
public void EnsureParagraph() | ||
{ | ||
var document = new EpubDocument("title", "author", "cover", default); | ||
|
||
Assert.Empty(document.Chapters); | ||
|
||
// 空のときは追加される | ||
document.AsPrivateProxy().EnsureParagraph(0, 0); | ||
Check failure on line 84 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
var chapter = Assert.Single(document.Chapters); | ||
var section = Assert.Single(chapter.Sections); | ||
var element = Assert.Single(section.Elements); | ||
var paragraph = Assert.IsType<Paragraph>(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); | ||
Check failure on line 110 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
chapter = Assert.Single(document.Chapters); | ||
section = Assert.Single(chapter.Sections); | ||
element = Assert.Single(section.Elements); | ||
paragraph = Assert.IsType<Paragraph>(element); | ||
Assert.Equal("paragraph1", paragraph.Text); | ||
|
||
document.AsPrivateProxy().EnsureParagraph(0, 1); | ||
Check failure on line 118 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
element = Assert.Single(document.Chapters[0].Sections[1].Elements); | ||
paragraph = Assert.IsType<Paragraph>(element); | ||
Assert.Null(paragraph.Audio); | ||
Assert.Null(paragraph.Text); | ||
Assert.Null(paragraph.ClassName); | ||
|
||
// インデックスは正しく指定する必要がある | ||
var exception = Record.Exception(() => document.AsPrivateProxy().EnsureParagraph(0, 5)); | ||
Check failure on line 127 in KoeBook.Test/Epub/EpubDocumentTest.cs GitHub Actions / test
|
||
|
||
Assert.IsType<IndexOutOfRangeException>(exception); | ||
} | ||
#endregion | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using KoeBook.Epub.Models; | ||
using PrivateProxy; | ||
|
||
namespace KoeBook.Test.Proxies; | ||
|
||
[GeneratePrivateProxy(typeof(EpubDocument))] | ||
partial struct EpubDocumentProxy; |
This file was deleted.