using VersOne.Epub.Internal;
using VersOne.Epub.Options;
using VersOne.Epub.Schema;
using VersOne.Epub.Test.Comparers;
using VersOne.Epub.Test.Unit.Mocks;
namespace VersOne.Epub.Test.Unit.Readers
{
public class PackageReaderTests
{
private const string CONTAINER_FILE_PATH = "META-INF/container.xml";
private const string OPF_FILE_PATH = "content.opf";
private const string CONTAINER_FILE = $"""
""";
private const string MINIMAL_EPUB2_OPF_FILE = $"""
""";
private const string MINIMAL_EPUB3_OPF_FILE = $"""
""";
private const string MINIMAL_EPUB3_1_OPF_FILE = $"""
""";
private const string FULL_OPF_FILE = $"""
Test title
John Doe
9781234567890
en
2021-12-31T00:00:00Z
Test title for collection 1
Test title for collection 2
""";
private const string OPF_FILE_WITH_NON_SUPPORTED_EPUB_VERSION = $"""
""";
private const string OPF_FILE_WITHOUT_PACKAGE = $"""
""";
private const string OPF_FILE_WITHOUT_METADATA = $"""
""";
private const string OPF_FILE_WITHOUT_MANIFEST = $"""
""";
private const string OPF_FILE_WITHOUT_SPINE = $"""
""";
private const string OPF_FILE_WITHOUT_VERSION_IN_PACKAGE = $"""
""";
private const string OPF_FILE_WITHOUT_ID_IN_MANIFEST_ITEM = $"""
""";
private const string OPF_FILE_WITH_ESCAPED_HREF_IN_MANIFEST_ITEM = $"""
""";
private const string OPF_FILE_WITHOUT_HREF_IN_MANIFEST_ITEM = $"""
""";
private const string OPF_FILE_WITHOUT_MEDIA_TYPE_IN_MANIFEST_ITEM = $"""
""";
private const string OPF_FILE_WITH_DUPLICATING_MANIFEST_ITEM_IDS = $"""
""";
private const string OPF_FILE_WITH_DUPLICATING_MANIFEST_ITEM_HREFS = $"""
""";
private const string EPUB2_OPF_FILE_WITHOUT_SPINE_TOC = $"""
""";
private const string EPUB2_OPF_FILE_WITH_EMPTY_SPINE_TOC = $"""
""";
private const string OPF_FILE_WITHOUT_IDREF_IN_SPINE_ITEMREF = $"""
""";
private const string OPF_FILE_WITHOUT_TYPE_IN_GUIDE_REFERENCE = $"""
""";
private const string OPF_FILE_WITHOUT_HREF_IN_GUIDE_REFERENCE = $"""
""";
private const string OPF_FILE_WITHOUT_ROLE_IN_COLLECTION = $"""
""";
private static EpubPackage MinimalEpub2Package =>
new
(
uniqueIdentifier: null,
epubVersion: EpubVersion.EPUB_2,
metadata: new EpubMetadata(),
manifest: new EpubManifest(),
spine: new EpubSpine
(
toc: "ncx"
),
guide: null
);
private static EpubPackage MinimalEpub3Package =>
new
(
uniqueIdentifier: null,
epubVersion: EpubVersion.EPUB_3,
metadata: new EpubMetadata(),
manifest: new EpubManifest(),
spine: new EpubSpine(),
guide: null
);
private static EpubPackage MinimalEpub31Package =>
new
(
uniqueIdentifier: null,
epubVersion: EpubVersion.EPUB_3_1,
metadata: new EpubMetadata(),
manifest: new EpubManifest(),
spine: new EpubSpine(),
guide: null
);
private static EpubPackage FullPackage =>
new
(
uniqueIdentifier: "book-uid",
epubVersion: EpubVersion.EPUB_3,
metadata: new EpubMetadata
(
titles: new List()
{
new
(
title: "Test title"
)
},
creators: new List()
{
new
(
creator: "John Doe"
)
},
identifiers: new List()
{
new
(
identifier: "9781234567890",
id: "book-uid"
)
},
languages: new List()
{
new
(
language: "en"
)
},
metaItems: new List()
{
new
(
name: null,
content: "2021-12-31T00:00:00Z",
property: "dcterms:modified"
)
}
),
manifest: new EpubManifest
(
id: "manifest-id",
items: new List()
{
new
(
id: "item-front",
href: "front.html",
mediaType: "application/xhtml+xml"
),
new
(
id: "cover",
href: "cover.html",
mediaType: "application/xhtml+xml"
),
new
(
id: "cover-image",
href: "cover.jpg",
mediaType: "image/jpeg",
properties: new List()
{
EpubManifestProperty.COVER_IMAGE
}
),
new
(
id: "item-css",
href: "styles.css",
mediaType: "text/css"
),
new
(
id: "item-font",
href: "font.ttf",
mediaType: "application/x-font-truetype"
),
new
(
id: "item-1",
href: "chapter1.html",
mediaType: "application/xhtml+xml",
mediaOverlay: "item-1-smil",
requiredNamespace: null,
requiredModules: null,
fallback: null,
fallbackStyle: null,
properties: null
),
new
(
id: "item-1-smil",
href: "chapter1.smil",
mediaType: "application/smil+xml"
),
new
(
id: "item-2",
href: "chapter2.html",
mediaType: "application/xhtml+xml"
),
new
(
id: "item-2-fall",
href: "chapter2.xml",
mediaType: "text/example+xml",
mediaOverlay: null,
requiredNamespace: "http://example.com/ns/example/",
requiredModules: "ruby, server-side-image-map",
fallback: "item-2",
fallbackStyle: "item-css",
properties: null
),
new
(
id: "item-3",
href: "chapter3.html",
mediaType: "application/xhtml+xml"
),
new
(
id: "item-3-fall",
href: "chapter3.xml",
mediaType: "application/z3998-auth+xml",
mediaOverlay: null,
requiredNamespace: null,
requiredModules: null,
fallback: "item-3",
fallbackStyle: null,
properties: null
),
new
(
id: "item-3-remote-audio",
href: "http://example.com/audio/123/chapter3.mp4",
mediaType: "audio/mp4"
),
new
(
id: "item-image",
href: "image.jpg",
mediaType: "image/jpeg"
),
new
(
id: "item-title-audio",
href: "title.mp3",
mediaType: "audio/mpeg"
),
new
(
id: "item-atom",
href: "book.atom",
mediaType: "application/atom+xml"
),
new
(
id: "item-toc",
href: "toc.html",
mediaType: "application/xhtml+xml",
properties: new List
{
EpubManifestProperty.NAV
}
),
new
(
id: "ncx",
href: "toc.ncx",
mediaType: "application/x-dtbncx+xml"
)
}
),
spine: new EpubSpine
(
id: "spine",
pageProgressionDirection: EpubPageProgressionDirection.LEFT_TO_RIGHT,
toc: "ncx",
items: new List()
{
new
(
id: "itemref-1",
idRef: "item-front",
isLinear: true
),
new
(
id: "itemref-2",
idRef: "item-toc",
isLinear: false
),
new
(
id: "itemref-3",
idRef: "item-1",
isLinear: true
),
new
(
id: "itemref-4",
idRef: "item-2",
isLinear: true,
properties: new List()
{
EpubSpineProperty.PAGE_SPREAD_LEFT
}
),
new
(
id: "itemref-5",
idRef: "item-3",
isLinear: true,
properties: new List()
{
EpubSpineProperty.PAGE_SPREAD_RIGHT
}
)
}
),
guide: new EpubGuide
(
items: new List()
{
new
(
type: "toc",
title: "Contents",
href: "toc.html"
)
}
),
collections: new List()
{
new
(
role: "http://example.org/roles/group",
metadata: new EpubMetadata
(
titles: new List()
{
new
(
title: "Test title for collection 1",
id: "collection-1-title",
textDirection: EpubTextDirection.LEFT_TO_RIGHT,
language: "en"
)
}
),
nestedCollections: new List()
{
new
(
role: "http://example.org/roles/unit",
metadata: new EpubMetadata
(
titles: new List()
{
new
(
title: "Test title for collection 2",
id: "collection-2-title",
textDirection: EpubTextDirection.AUTO,
language: "is"
)
}
),
nestedCollections: new List(),
links: new List(),
id: "collection-2",
textDirection: EpubTextDirection.RIGHT_TO_LEFT,
language: "is"
)
},
links: new List()
{
new
(
href: "https://example.com/onix/123",
id: "collection-1-link",
mediaType: "application/xml",
properties: new List()
{
EpubMetadataLinkProperty.ONIX
},
relationships: new List()
{
EpubMetadataLinkRelationship.RECORD,
EpubMetadataLinkRelationship.ONIX_RECORD
},
hrefLanguage: null
)
},
id: "collection-1",
textDirection: EpubTextDirection.LEFT_TO_RIGHT,
language: "en"
)
},
id: "package-id",
textDirection: EpubTextDirection.LEFT_TO_RIGHT,
prefix: "foaf: http://xmlns.com/foaf/spec/",
language: "en"
);
private static EpubPackage Epub2PackageWithoutSpineToc =>
new
(
uniqueIdentifier: null,
epubVersion: EpubVersion.EPUB_2,
metadata: new EpubMetadata(),
manifest: new EpubManifest(),
spine: new EpubSpine(),
guide: null
);
public static IEnumerable