public async Task ExtractNavigationPoints_TocNcxExample1Full_ReturnsNavigationPoints()
        {
            var docString = TestResources.TocNcxExample1;
            var doc       = await XmlStructureFile.LoadFromTextAsync(string.Empty, docString);

            var preface1File = TestItemFactory.CreateFileFromString("preface01.html");
            var ch1File      = TestItemFactory.CreateFileFromString("ch01.html");
            var indexFile    = TestItemFactory.CreateFileFromString("ix01.html");
            var testee       = new NcxNavigationExtractor();

            var result = testee.ExtractNavigationPoints(doc, new[] { preface1File, ch1File, indexFile });

            var expected = new[]
            {
                new NavigationPoint("Preface", preface1File, null, 1, new []
                {
                    new NavigationPoint("This book is written for", preface1File, "this_book_is_written_for", 2, new NavigationPoint[0]),
                    new NavigationPoint("About This Book", preface1File, "about_this_book", 3, new NavigationPoint[0]),
                    new NavigationPoint("Conventions", preface1File, "conventions", 4, new[]
                    {
                        new NavigationPoint("text", preface1File, "conventions_text", 5, new NavigationPoint[0]),
                    }),
                }),
                new NavigationPoint("1. Beginning", ch1File, "beginning", 6, new NavigationPoint[0]),
                new NavigationPoint("Index", indexFile, null, 7, new NavigationPoint[0]),
            };

            CustomAsserts.AssertNavigationPointsAreEqual(result, expected);
        }
Example #2
0
        public async Task ExtractNavigationPoints_TocXHtmlExample1_ExtractsNavigation()
        {
            var doc = await XmlStructureFile.LoadFromTextAsync(string.Empty, TestResources.TocXHtmlExample1);

            var preface1File = TestItemFactory.CreateFileFromString("preface01.html");
            var ch1File      = TestItemFactory.CreateFileFromString("ch01.html");
            var indexFile    = TestItemFactory.CreateFileFromString("index.html");
            var testee       = new XHtmlNavigationExtractor();

            var result = testee.ExtractNavigationPoints(doc, new[] { preface1File, ch1File, indexFile });

            var expected = new[]
            {
                new NavigationPoint("Preface", preface1File, null, 1, new []
                {
                    new NavigationPoint("This book is written for", preface1File, "this_book_is_written_for", 2, new NavigationPoint[0]),
                    new NavigationPoint("About", preface1File, "about", 3, new NavigationPoint[0]),
                }),
                new NavigationPoint("1. Beginning", ch1File, "beginning", 4, new []
                {
                    new NavigationPoint("1.1. Why", ch1File, "why", 5, new NavigationPoint[0]),
                }),
                new NavigationPoint("Index", indexFile, null, 6, new NavigationPoint[0]),
            };

            CustomAsserts.AssertNavigationPointsAreEqual(result, expected);
        }
Example #3
0
        public async Task ExtractManifestItems_WithExampleOpf_ReturnsManifestItems()
        {
            var opf = TestResources.OpfManifestExample;
            var doc = await XmlStructureFile.LoadFromTextAsync("/test.opf", opf);

            var testee = new ManifestExtractor();

            var result = testee.ExtractManifestItems(doc).ToArray();

            var expected = new[]
            {
                new ManifestItem("ncxtoc", "toc.ncx", null, ContentType.Ncx),
                new ManifestItem("css", "style.css", null, ContentType.Css),
                new ManifestItem("cover", "cover.html", null, ContentType.XHtml),
                new ManifestItem("epub.embedded.font.1", "CustomFont.otf", null, ContentType.FontOpenType),
                new ManifestItem("id2558953", "index.html", null, ContentType.XHtml),
                new ManifestItem("cover-image", "cover.jpg", null, ContentType.ImageJpeg),
                new ManifestItem("id01", "ch1.html", null, ContentType.XHtml),
            };

            for (int index = 0; index <= 6; index++)
            {
                Assert.IsTrue(AreManifestItemsEqual(expected[index], result[index]));
            }
        }
Example #4
0
        public async Task ExtractOpfPath_WithContainerXml_ReturnsOpfPath()
        {
            var resource = TestResources.ContainerXmlSimple;
            var testee   = new OpfPathExtractor();

            var result = testee.ExtractOpfPath(await XmlStructureFile.LoadFromTextAsync("test.container", resource));

            Assert.AreEqual("OEBPS/content.opf", result);
        }
Example #5
0
        public async Task LoadFromTextAsync_WithPathAndContent_ReturnsXmlStructureFile()
        {
            var path      = "test";
            var docString = "<doc />";

            var result = await XmlStructureFile.LoadFromTextAsync(path, docString);

            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(docString, result.Doc.ToString());
        }
Example #6
0
        public async Task LoadFromBytesAsync_WithPathAndContent_ReturnsXmlStructureFile()
        {
            var path      = "test";
            var docString = "<doc />";
            var content   = Encoding.UTF8.GetBytes(docString);

            var result = await XmlStructureFile.LoadFromBytesAsync(path, content);

            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(docString, result.Doc.ToString());
        }
Example #7
0
        public async Task ExtractMeta_TitleSetTwice_ReturnsFirst()
        {
            var docString = $@"<package xmlns=""{XmlNamespaces.Opf}"" xmlns:dc=""{XmlNamespaces.OpfMetaElements}""><metadata><dc:title>test1</dc:title><dc:title>test2</dc:title></metadata></package>";
            var doc       = await XmlStructureFile.LoadFromTextAsync("/test.opf", docString);

            var testee = new MetaExtractor();

            var result = testee.ExtractMeta(doc).Title;

            Assert.AreEqual("test1", result);
        }
Example #8
0
        public async Task LoadFromStreamAsync_WithPathAndContent_ReturnsXmlStructureFile()
        {
            var path      = "test";
            var docString = "<doc />";

            using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(docString)))
            {
                var result = await XmlStructureFile.LoadFromStreamAsync(path, stream);

                Assert.AreEqual(path, result.Path);
                Assert.AreEqual(docString, result.Doc.ToString());
            }
        }
Example #9
0
        public async Task LoadFromZipAsync_WithPathAndContent_ReturnsXmlStructureFile()
        {
            var path      = "test";
            var docString = "<doc />";
            var zip       = new Mock <IZip>();

            zip
            .Setup(x => x.GetFileStream(path))
            .Returns(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(docString)));

            var result = await XmlStructureFile.LoadFromZipAsync(path, zip.Object);

            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(docString, result.Doc.ToString());
        }
Example #10
0
        public async Task Construct_ByDefault_SetsAlLValuesToProperties()
        {
            var opf = await XmlStructureFile.LoadFromTextAsync("test.opf", "<opf />");

            var container = await XmlStructureFile.LoadFromTextAsync("container.opf", "<container />");

            var zip = new Mock <IZip>().Object;

            var testee = new EpubStructure(opf, container, zip);

            var resultOpf       = testee.Opf;
            var resultContainer = testee.Container;
            var resultZip       = testee.Zip;

            Assert.AreEqual(opf, resultOpf);
            Assert.AreEqual(container, resultContainer);
            Assert.AreEqual(zip, resultZip);
        }
Example #11
0
        public async Task ExtractMeta_ExampleOpf2_ExtractsMetaData()
        {
            var docString = TestResources.OpfMetadataExample2;
            var doc       = await XmlStructureFile.LoadFromTextAsync("/test.opf", docString);

            var testee = new MetaExtractor();

            var result = testee.ExtractMeta(doc);

            Assert.AreEqual("1111111111111", result.Identifier);
            Assert.AreEqual("Some Book's Title", result.Title);
            Assert.AreEqual(null, result.Rights);
            Assert.AreEqual("Some Press", result.Publisher);
            Assert.AreEqual("2010-10-10", result.Date);
            Assert.AreEqual("Some text and some other text", result.Description);
            Assert.AreEqual("Anon ymous", result.Creator);
            Assert.AreEqual("en", result.Language);
        }
Example #12
0
        public async Task ExtractFiles_WithManifestItemsInContentDirectory_ReturnsFiles()
        {
            var zip           = new Mock <IZip>();
            var content       = Encoding.ASCII.GetBytes("test");
            var manifestItems = new[]
            {
                new ManifestItem(string.Empty, "chapter1.xml", string.Empty, ContentType.Unknown),
            };
            var opf = await XmlStructureFile.LoadFromTextAsync("content/opf.opf", "<Doc />");

            zip.Setup(x => x.GetFileContent("content/chapter1.xml")).Returns(content);
            var testee = new FileExtractor();

            var result = (await testee.ExtractFiles(opf, manifestItems, zip.Object)).Single();

            Assert.AreEqual(content, result.Content);
            Assert.AreEqual("chapter1.xml", result.Name);
            Assert.AreEqual("content/chapter1.xml", result.Path);
        }
Example #13
0
        public async Task ExtractNavigationPoints_TocXHtmlExample2_ExtractsNavigation()
        {
            var doc = await XmlStructureFile.LoadFromTextAsync(string.Empty, TestResources.TocXHtmlExample2);

            var coverFile = TestItemFactory.CreateFileFromString("cover.xhtml");
            var introFile = TestItemFactory.CreateFileFromString("intro.xhtml");
            var testee    = new XHtmlNavigationExtractor();

            var result = testee.ExtractNavigationPoints(doc, new[] { coverFile, introFile });

            var expected = new[]
            {
                new NavigationPoint("Cover", coverFile, null, 1, new NavigationPoint[0]),
                new NavigationPoint("INTRODUCTION", introFile, "intro", 2, new []
                {
                    new NavigationPoint("About", introFile, "lev1", 3, new NavigationPoint[0]),
                }),
            };

            CustomAsserts.AssertNavigationPointsAreEqual(result, expected);
        }
Example #14
0
        public async Task ExtractManifestItems_WithExtendedOpf_ReturnsManifestItems()
        {
            var opf = TestResources.OpfManifestExtended;
            var doc = await XmlStructureFile.LoadFromTextAsync("/test.opf", opf);

            var testee = new ManifestExtractor();

            var result = testee.ExtractManifestItems(doc).ToArray();

            var expected = new[]
            {
                new ManifestItem("identifier", "reference", "properties", ContentType.Ncx),
                new ManifestItem("identifier", "reference", null, ContentType.Unknown),
                new ManifestItem("identifier", null, "properties", ContentType.Unknown),
                new ManifestItem(null, "reference", "properties", ContentType.XHtml),
            };

            for (int index = 0; index <= 3; index++)
            {
                Assert.IsTrue(AreManifestItemsEqual(expected[index], result[index]));
            }
        }
        public async Task ExtractNavigationPoints_TocNcxExample2WithoutPlayOrderAndElementIds_ReturnsNavigationPoints()
        {
            var docString = TestResources.TocNcxExample2;
            var doc       = await XmlStructureFile.LoadFromTextAsync(string.Empty, docString);

            var preface1File = TestItemFactory.CreateFileFromString("preface01.html");
            var testee       = new NcxNavigationExtractor();

            var result = testee.ExtractNavigationPoints(doc, new[] { preface1File });

            var expected = new[]
            {
                new NavigationPoint("Preface", preface1File, null, 1, new []
                {
                    new NavigationPoint("Conventions", preface1File, "conventions", 2, new[]
                    {
                        new NavigationPoint("text", preface1File, "conventions_text", 3, new NavigationPoint[0]),
                    }),
                }),
            };

            CustomAsserts.AssertNavigationPointsAreEqual(result, expected);
        }