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 SchemaReaderTests { private const string EPUB_CONTAINER_FILE_PATH = "META-INF/container.xml"; private const string CONTENT_DIRECTORY_PATH = "Content"; private const string OPF_PACKAGE_FILE_PATH = $"{CONTENT_DIRECTORY_PATH}/content.opf"; private const string NCX_FILE_NAME = "toc.ncx"; private const string NCX_FILE_PATH = $"{CONTENT_DIRECTORY_PATH}/{NCX_FILE_NAME}"; private const string NAV_FILE_NAME = "toc.html"; private const string NAV_FILE_PATH = $"{CONTENT_DIRECTORY_PATH}/{NAV_FILE_NAME}"; private const string SMIL_FILE_NAME = "chapter1.smil"; private const string SMIL_FILE_PATH = $"{CONTENT_DIRECTORY_PATH}/{SMIL_FILE_NAME}"; private const string META_INF_CONTAINER_FILE = $""" """; private const string OPF_PACKAGE_FILE = $""" Test title John Doe 9781234567890 """; private const string NCX_FILE = """ Test title John Doe Chapter 1 Chapter 2 """; private const string NAV_FILE = """ """; private const string SMIL_FILE = """ """; [Fact(DisplayName = "Constructing a SchemaReader instance with a non-null epubReaderOptions parameter should succeed")] public void ConstructorWithNonNullEpubReaderOptionsTest() { _ = new SchemaReader(new EpubReaderOptions()); } [Fact(DisplayName = "Constructing a SchemaReader instance with a null epubReaderOptions parameter should succeed")] public void ConstructorWithNullEpubReaderOptionsTest() { _ = new SchemaReader(null); } [Fact(DisplayName = "Reading a typical schema from a EPUB file should succeed")] public async Task ReadSchemaAsyncTest() { TestZipFile testZipFile = new(); testZipFile.AddEntry(EPUB_CONTAINER_FILE_PATH, META_INF_CONTAINER_FILE); testZipFile.AddEntry(OPF_PACKAGE_FILE_PATH, OPF_PACKAGE_FILE); testZipFile.AddEntry(NCX_FILE_PATH, NCX_FILE); testZipFile.AddEntry(NAV_FILE_PATH, NAV_FILE); testZipFile.AddEntry(SMIL_FILE_PATH, SMIL_FILE); EpubSchema expectedEpubSchema = new ( package: new EpubPackage ( 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" ) } ), manifest: new EpubManifest ( items: new List() { new ( id: "item-1", href: "chapter1.html", mediaType: "application/xhtml+xml" ), new ( id: "item-2", href: "chapter2.html", mediaType: "application/xhtml+xml" ), new ( id: "item-toc", href: NAV_FILE_NAME, mediaType: "application/xhtml+xml", properties: new List() { EpubManifestProperty.NAV } ), new ( id: "ncx", href: NCX_FILE_NAME, mediaType: "application/x-dtbncx+xml" ) } ), spine: new EpubSpine ( toc: "ncx", items: new List() { new ( id: "itemref-1", idRef: "item-1", isLinear: true ), new ( id: "itemref-2", idRef: "item-2", isLinear: true ) } ), guide: null ), epub2Ncx: new Epub2Ncx ( filePath: NCX_FILE_PATH, head: new Epub2NcxHead ( items: new List() { new ( name: "dtb:uid", content: "9781234567890" ) } ), docTitle: "Test title", docAuthors: new List() { "John Doe" }, navMap: new Epub2NcxNavigationMap ( items: new List() { new ( id: "navpoint-1", navigationLabels: new List() { new ( text: "Chapter 1" ) }, content: new Epub2NcxContent ( source: "chapter1.html" ) ), new ( id: "navpoint-2", navigationLabels: new List() { new ( text: "Chapter 2" ) }, content: new Epub2NcxContent ( source: "chapter2.html" ) ) } ) ), epub3NavDocument: new Epub3NavDocument ( filePath: NAV_FILE_PATH, navs: new List() { new ( type: Epub3StructuralSemanticsProperty.TOC, ol: new Epub3NavOl ( lis: new List() { new ( anchor: new Epub3NavAnchor ( href: "chapter1.html", text: "Chapter 1" ) ), new ( anchor: new Epub3NavAnchor ( href: "chapter2.html", text: "Chapter 2" ) ) } ) ) } ), mediaOverlays: new List() { new ( id: null, version: SmilVersion.SMIL_3, epubPrefix: null, head: null, body: new SmilBody ( id: null, epubTypes: null, epubTextRef: null, seqs: new List(), pars: new List() { new ( id: "sentence1", epubTypes: null, text: new SmilText ( id: null, src: "chapter1.html#sentence1" ), audio: new SmilAudio ( id: null, src: "chapter1_audio.mp3", clipBegin: "0s", clipEnd: "10s" ) ), new ( id: "sentence2", epubTypes: null, text: new SmilText ( id: null, src: "chapter1.html#sentence2" ), audio: new SmilAudio ( id: null, src: "chapter1_audio.mp3", clipBegin: "10s", clipEnd: "20s" ) ), new ( id: "sentence3", epubTypes: null, text: new SmilText ( id: null, src: "chapter1.html#sentence3" ), audio: new SmilAudio ( id: null, src: "chapter1_audio.mp3", clipBegin: "20s", clipEnd: "30s" ) ) } ) ) }, contentDirectoryPath: CONTENT_DIRECTORY_PATH ); SchemaReader schemaReader = new(); EpubSchema actualEpubSchema = await schemaReader.ReadSchemaAsync(testZipFile); EpubSchemaComparer.CompareEpubSchemas(expectedEpubSchema, actualEpubSchema); } } }