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); }
private void BuildUpTestItems() { this.TestItems.Clear(); this._recheckItems.Clear(); if (Settings.Default.ItemTXChaSunChecked) { this.TestItems.Add(TXChaSun); } if (Settings.Default.ItemRXChaSunChecked) { this.TestItems.Add(RXChaSun); } if (Settings.Default.ItemRXGeLiDuChecked) { this.TestItems.Add(RXGeLiDu); } if (Settings.Default.ItemTXNaiGongLu) { this.TestItems.Add(TXPowerResist); } if (Settings.Default.ItemRXNaiGongLuChecked || Settings.Default.ItemTXNaiGongLu) { this._recheckItems.Add(TestItemFactory.CreateTestItem(TestItemType.TxChaSun, true)); this._recheckItems.Add(TestItemFactory.CreateTestItem(TestItemType.RxChaSun, true)); } }
private void InitTestItem() { TXChaSun = TestItemFactory.CreateTestItem(TestItemType.TxChaSun, true); RXChaSun = TestItemFactory.CreateTestItem(TestItemType.RxChaSun, true); RXGeLiDu = TestItemFactory.CreateTestItem(TestItemType.RxGeLi, true); TXPowerResist = TestItemFactory.CreateTestItem(TestItemType.TxPower, true); }
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); }
public async Task LoadNcx_PathSpecifiedInManifestItem_LoadsXHtmlToc() { var testee = new NcxLoader(); var manifestItem = new ManifestItem(null, "toc.ncx", string.Empty, ContentType.Ncx); var file = TestItemFactory.CreateFileFromString("content/toc.ncx", "<toc />"); var result = await testee.LoadNcx(new[] { manifestItem }, "content/book.opf", new[] { file }); Assert.AreEqual("content/toc.ncx", result.Path); Assert.AreEqual("<toc />", result.Doc.ToString()); }
public void ToString_WithoutIdInFile_ReturnsStringRepresentationWithoutId() { var name = "Chapter 1"; var file = TestItemFactory.CreateFileFromString("test.txt"); string elementId = null; var testee = new NavigationPoint(name, file, elementId, 0, new NavigationPoint[0]); var result = testee.ToString(); Assert.AreEqual("Chapter 1 - test.txt", result); }
public void Construct_ByDefault_SetsAllValues() { var title = "name"; var file = TestItemFactory.CreateFileFromString("test.xhtml"); string elementId = null; var order = 0; var children = new NavigationPoint[0]; var result = new NavigationPoint( title, file, elementId, order, children); Assert.AreEqual(title, result.Title); Assert.AreEqual(file, result.File); Assert.AreEqual(elementId, result.ElementId); Assert.AreEqual(children, result.Children); Assert.AreEqual(order, result.Order); }
public void WithChildren_OtherChildren_ReturnsNewNavigationWithCopiedValuesAndNewChildren() { var title = "name"; var file = TestItemFactory.CreateFileFromString("test.xhtml"); string elementId = null; var order = 0; var oldChildren = Array.Empty <NavigationPoint>(); var newChildren = Array.Empty <NavigationPoint>(); var navigationPoint = new NavigationPoint( title, file, elementId, order, oldChildren); var result = navigationPoint.WithChildren(newChildren); Assert.AreEqual(title, result.Title); Assert.AreEqual(file, result.File); Assert.AreEqual(elementId, result.ElementId); Assert.AreEqual(newChildren, result.Children); Assert.AreEqual(order, result.Order); }
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); }
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); }
public void ShortenFilePaths_FilePathsCanBeShortened_ShortensFilePaths() { var builder = new BookBuilder(); builder.Files = new[] { TestItemFactory.CreateFileFromString("/test/file1.html"), TestItemFactory.CreateFileFromString("/test/file2.html"), TestItemFactory.CreateFileFromString("/test/content/file3.html"), }; var testee = new FilePathShortener(); testee.ShortenFilePaths(builder); var expected = new[] { "file1.html", "file2.html", "content/file3.html", }; var result = builder.Files.Select(f => f.Path).ToArray(); CollectionAssert.AreEqual(expected, result); }