Exemplo n.º 1
0
        public void Setup()
        {
            _storage = new Moq.Mock <IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.SetupGet(x => x.BookType).Returns(Bloom.Book.Book.BookType.Publication);
            _storage.Setup(x => x.GetRelocatableCopyOfDom(It.IsAny <IProgress>())).Returns(() =>
            {
                return
                (_bookDom.Clone());
            });                                                                  // review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny <HtmlDom>(), It.IsAny <IProgress>())).Returns(
                (HtmlDom x, IProgress y) => { return(x.Clone()); });             // review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(() => _fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path, "original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);            // review: the real thing does more than just clone


            _templateFinder = new Moq.Mock <ITemplateFinder>();
            _fileLocator    = new Moq.Mock <IFileLocator>();
            string root               = FileLocator.GetDirectoryDistributedWithApplication("BloomBrowserUI");
            string xMatter            = FileLocator.GetDirectoryDistributedWithApplication("xMatter");
            string factoryCollections = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections");
            string templates          = FileLocator.GetDirectoryDistributedWithApplication("factoryCollections", "templates");

            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplayTemplate.css")).Returns(root.CombineForPath("bookLayout", "languageDisplayTemplate.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny <IEnumerable <string> >())).Returns(_fileLocator.Object);

            _thumbnailer          = new Moq.Mock <HtmlThumbNailer>(new object[] { 60 });
            _pageSelection        = new Mock <PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }
Exemplo n.º 2
0
        public virtual void Setup()
        {
            _storage = new Moq.Mock <IBookStorage>();
            _storage.Setup(x => x.GetLooksOk()).Returns(true);
            _bookDom = new HtmlDom(GetThreePageDom());
            _storage.SetupGet(x => x.Dom).Returns(() => _bookDom);
            _storage.SetupGet(x => x.Key).Returns("testkey");
            _storage.SetupGet(x => x.FileName).Returns("testTitle");
            _storage.Setup(x => x.GetRelocatableCopyOfDom()).Returns(() =>
            {
                return
                (_bookDom.Clone());
            });                                         // review: the real thing does more than just clone
            _storage.Setup(x => x.MakeDomRelocatable(It.IsAny <HtmlDom>())).Returns(
                (HtmlDom x) => { return(x.Clone()); }); // review: the real thing does more than just clone

            _storage.Setup(x => x.GetFileLocator()).Returns(() => _fileLocator.Object);

            _testFolder = new TemporaryFolder("BookTests");
            _tempFolder = new TemporaryFolder(_testFolder, "book");
            MakeSamplePngImageWithMetadata(Path.Combine(_tempFolder.Path, "original.png"));
            _storage.SetupGet(x => x.FolderPath).Returns(_tempFolder.Path);            // review: the real thing does more than just clone
            _metadata = new BookInfo(_tempFolder.Path, true);
            _storage.SetupGet(x => x.MetaData).Returns(_metadata);
            _storage.Setup(x => x.HandleRetiredXMatterPacks(It.IsAny <HtmlDom>(), It.IsAny <string>()))
            .Returns((HtmlDom dom, string y) => { return(y == "BigBook" ? "Factory" : y); });

            _templateFinder = new Moq.Mock <ITemplateFinder>();
            _fileLocator    = new Moq.Mock <IFileLocator>();
            string root    = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
            string xMatter = BloomFileLocator.GetInstalledXMatterDirectory();

            _fileLocator.Setup(x => x.LocateFileWithThrow("languageDisplay.css")).Returns("../notareallocation/languageDisplay.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("previewMode.css")).Returns("../notareallocation/previewMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("origami.css")).Returns("../notareallocation/origami.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editMode.css")).Returns("../notareallocation/editMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editTranslationMode.css")).Returns("../notareallocation/editTranslationMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editOriginalMode.css")).Returns("../notareallocation/editOriginalMode.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("editPaneGlobal.css")).Returns("../notareallocation/editPaneGlobal.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("basePage.css")).Returns("../notareallocation/basePage.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomBootstrap.js")).Returns("../notareallocation/bloomBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("bloomPreviewBootstrap.js")).Returns("../notareallocation/bloomPreviewBootstrap.js");
            _fileLocator.Setup(x => x.LocateFileWithThrow("baseEPUB.css")).Returns("../notareallocation/baseEPUB.css");
            _fileLocator.Setup(x => x.LocateFileWithThrow("customBookStyles.css")).Returns(Path.Combine(_tempFolder.Path, "customBookStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("settingsCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "settingsCollectionStyles.css"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("customCollectionStyles.css")).Returns(Path.Combine(_testFolder.Path, "customCollectionStyles.css"));
            var basicBookPath = BloomFileLocator.GetCodeBaseFolder() + "/../browser/templates/template books/Basic Book/Basic Book.css";

            _fileLocator.Setup(x => x.LocateFile("Basic Book.css")).Returns(basicBookPath);

            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Factory-XMatter")).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Factory-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Factory-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Factory-XMatter".CombineForPath("Factory-XMatter.htm"))).Returns(xMatter.CombineForPath("Factory-XMatter", "Factory-XMatter.htm"));

            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("Traditional-XMatter")).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("Traditional-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("Traditional-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("Traditional-XMatter".CombineForPath("Traditional-XMatter.htm"))).Returns(xMatter.CombineForPath("Traditional-XMatter", "Factory-XMatter.htm"));


            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectoryWithThrow("BigBook-XMatter")).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateDirectory("BigBook-XMatter", It.IsAny <string>())).Returns(xMatter.CombineForPath("BigBook-XMatter"));
            _fileLocator.Setup(x => x.LocateFileWithThrow("BigBook-XMatter".CombineForPath("BigBook-XMatter.htm"))).Returns(xMatter.CombineForPath("BigBook-XMatter", "BigBook-XMatter.htm"));

            //warning: we're neutering part of what the code under test is trying to do here:
            _fileLocator.Setup(x => x.CloneAndCustomize(It.IsAny <IEnumerable <string> >())).Returns(_fileLocator.Object);

            _thumbnailer          = new Moq.Mock <HtmlThumbNailer>(new object[] { new NavigationIsolator() });
            _pageSelection        = new Mock <PageSelection>();
            _pageListChangedEvent = new PageListChangedEvent();
        }