Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Utils\TestCaseUtils.fs" />
<Compile Include="TestInpLine.fs" />
<Compile Include="TestBook.fs" />
<Compile Include="TestBookImporter.fs" />
Expand All @@ -30,7 +29,7 @@

<ItemGroup>
<ProjectReference Include="..\HomeLibProt.CollectionImporter\HomeLibProt.CollectionImporter.fsproj" />
<ProjectReference Include="..\HomeLibProt.Domain.Tests\HomeLibProt.Domain.Tests.csproj" />
<ProjectReference Include="..\HomeLibProt.Common.Tests\HomeLibProt.Common.Tests.fsproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System
open System.IO

open HomeLibProt.CollectionImporter.CollectionValidator
open HomeLibProt.CollectionImporter.Tests.Utils
open HomeLibProt.Common.Tests.Utils
open HomeLibProt.Domain.DataAccess
open HomeLibProt.Domain.Tests.Utils

Expand Down
2 changes: 1 addition & 1 deletion HomeLibProt.CollectionImporter.Tests/TestInpxImporter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System
open System.IO

open HomeLibProt.CollectionImporter.InpxImporter
open HomeLibProt.CollectionImporter.Tests.Utils
open HomeLibProt.Common.Tests.Utils
open HomeLibProt.Domain.DataAccess
open HomeLibProt.Domain.Tests.Entities
open HomeLibProt.Domain.Tests.Utils
Expand Down
36 changes: 36 additions & 0 deletions HomeLibProt.Common.Tests/HomeLibProt.Common.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Include="Utils\TestCaseUtils.fs" />
<Compile Include="TestFb2Reader.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HomeLibProt.Common\HomeLibProt.Common.fsproj" />
<ProjectReference Include="..\HomeLibProt.Domain.Tests\HomeLibProt.Domain.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="TestCases\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions HomeLibProt.Common.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Program =

[<EntryPoint>]
let main _ = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<genre>genre1</genre>
<genre>genre2</genre>
<author>
<first-name>Aa</first-name>
<middle-name>Bb</middle-name>
<last-name>Cc</last-name>
</author>
<author>
<first-name>Dd</first-name>
<middle-name>Ee</middle-name>
<last-name>Ff</last-name>
</author>
<book-title>Title 1</book-title>
<lang>en</lang>
<sequence name="Series 1" number="1"/>
<sequence name="Series 2" number="1"/>
<keywords>Keyword1, Keyword2</keywords>
<keywords>Keyword3</keywords>
</title-info>
</description>
<body>
<section>
<p>Body</p>
</section>
</body>
</FictionBook>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<genre>genre1</genre>
<genre>genre2</genre>
<author>
<first-name>Aa</first-name>
<middle-name>Bb</middle-name>
<last-name>Cc</last-name>
</author>
<author>
<first-name>Dd</first-name>
<middle-name>Ee</middle-name>
<last-name>Ff</last-name>
</author>
<book-title>Title 1</book-title>
<coverpage>
<image l:href="#coverpage" />
</coverpage>
<lang>en</lang>
<sequence name="Series 1" number="1"/>
<sequence name="Series 2" number="1"/>
<keywords>Keyword1, Keyword2</keywords>
<keywords>Keyword3</keywords>
</title-info>
</description>
<body>
<section>
<p>Body</p>
</section>
</body>
<binary content-type="image/jpeg" id="coverpage">Base64</binary>
</FictionBook>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<genre>genre1</genre>
<genre>genre2</genre>
<author>
<first-name>Aa</first-name>
<middle-name>Bb</middle-name>
<last-name>Cc</last-name>
</author>
<author>
<first-name>Dd</first-name>
<middle-name>Ee</middle-name>
<last-name>Ff</last-name>
</author>
<book-title>Title 1</book-title>
<annotation>
<p>Annotation</p>
</annotation>
<coverpage>
<image l:href="#coverpage" />
</coverpage>
<lang>en</lang>
<sequence name="Series 1" number="1"/>
<sequence name="Series 2" number="1"/>
<keywords>Keyword1, Keyword2</keywords>
<keywords>Keyword3</keywords>
</title-info>
</description>
<body>
<section>
<p>Body</p>
</section>
</body>
<binary content-type="image/jpeg" id="coverpage">Base64</binary>
</FictionBook>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<annotation>
<p>Annotation</p>
</annotation>
<coverpage>
<image l:href="#coverpage" />
</coverpage>
</title-info>
</description>
<body>
<section>
<p>Body</p>
</section>
</body>
<binary content-type="image/jpeg" id="coverpage">Base64</binary>
</FictionBook>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
<description>
<title-info>
<genre>genre1</genre>
<genre>genre2</genre>
<author>
<first-name>Aa</first-name>
<middle-name>Bb</middle-name>
<last-name>Cc</last-name>
</author>
<author>
<first-name>Dd</first-name>
<middle-name>Ee</middle-name>
<last-name>Ff</last-name>
</author>
<book-title>Title 1</book-title>
<annotation>
<p>Annotation</p>
</annotation>
<coverpage>
<image l:href="#coverpage" />
</coverpage>
<lang>en</lang>
<sequence name="Series 1" number="1"/>
<sequence name="Series 2" number="1"/>
<keywords>Keyword1, Keyword2</keywords>
<keywords>Keyword3</keywords>
</title-info>
</description>
<body>
<section>
<p>Body</p>
</section>
</body>
<binary content-type="image/jpeg" id="coverpage">Base64</binary>
</FictionBook>
71 changes: 71 additions & 0 deletions HomeLibProt.Common.Tests/TestFb2Reader.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module HomeLibProt.Common.Tests.TestFb2Reader

open NUnit.Framework
open System.IO

open HomeLibProt.Common.Fb2Reader
open HomeLibProt.Common.Tests.Utils

let getBookPath (testCaseName: string) =
Path.Combine(TestCaseUtils.getTestCasesBasePath "TestFb2Reader", testCaseName, "Book.fb2")

let getFb2AttributesTestCases =
[| TestCaseData(
"GetAttributes/Simple",
Some
{ Annotation = Some "<p>Annotation</p>"
Coverpage = Some "Base64" }
)
TestCaseData(
"GetAttributes/OnlyReference",
Some
{ Annotation = None
Coverpage = Some "Base64" }
)
TestCaseData("GetAttributes/NoAttributes", Some { Annotation = None; Coverpage = None }) |]

let getFb2InfoTestCases =
[| TestCaseData(
"GetFb2Info/Simple",
Some
{ Authors =
[| { First = "Aa"
Middle = "Bb"
Last = "Cc" }
{ First = "Dd"
Middle = "Ee"
Last = "Ff" } |]
Genres = [| "genre1"; "genre2" |]
Title = "Title 1"
Language = "en"
Keywords = [| "Keyword1"; "Keyword2"; "Keyword3" |]
Series = [| { Name = "Series 1"; Number = "1" }; { Name = "Series 2"; Number = "1" } |] }
)
TestCaseData(
"GetFb2Info/NoAttributes",
Some
{ Authors = [||]
Genres = [||]
Title = ""
Language = ""
Keywords = [||]
Series = [||] }
) |]

[<Test>]
[<TestCaseSource(nameof getFb2AttributesTestCases)>]
let TestGetFb2Attributes (testCaseName: string, expected: Fb2Attributes option) =
use fb2 = getBookPath testCaseName |> File.OpenRead

let actual = getFb2Attributes fb2

Assert.That(actual, Is.EqualTo expected)

[<Test>]
[<TestCaseSource(nameof getFb2InfoTestCases)>]
let TestGetFb2Info (testCaseName: string, expected: Fb2Info option) =
use fb2 = getBookPath testCaseName |> File.OpenRead

let actual = getFb2Info fb2

Assert.That(actual, Is.EqualTo expected)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module HomeLibProt.CollectionImporter.Tests.Utils.TestCaseUtils
module HomeLibProt.Common.Tests.Utils.TestCaseUtils

open System.IO
open System.Reflection
Expand Down
Loading
Loading