Skip to content

Commit

Permalink
#5-1 EpubDocumentのテストを作成中
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Mar 2, 2024
1 parent d2b3d40 commit 40917b3
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 10 deletions.
132 changes: 132 additions & 0 deletions KoeBook.Test/Epub/EpubDocumentTest.cs
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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

Assert.Equal(3, document.Chapters[0].Sections.Count);

document.AsPrivateProxy().EnsureSection(1);

Check failure on line 66 in KoeBook.Test/Epub/EpubDocumentTest.cs

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

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

View workflow job for this annotation

GitHub Actions / test

'EpubDocument' does not contain a definition for 'AsPrivateProxy' and no accessible extension method 'AsPrivateProxy' accepting a first argument of type 'EpubDocument' could be found (are you missing a using directive or an assembly reference?)

Assert.IsType<IndexOutOfRangeException>(exception);
}
#endregion
}
4 changes: 4 additions & 0 deletions KoeBook.Test/KoeBook.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="PrivateProxy" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions KoeBook.Test/Proxies/EpubModels.cs
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;
10 changes: 0 additions & 10 deletions KoeBook.Test/UnitTest1.cs

This file was deleted.

0 comments on commit 40917b3

Please sign in to comment.