BringBookUpToDate() private method

As the bloom format evolves, including structure and classes and other attributes, this makes changes to old books. It needs to be very fast, because currently we dont' have a real way to detect the need for migration. So we do it all the time. Yes, we have format version number, but, for example, one overhaul of the common xmatter html introduced a new class, "frontCover". Hardly enough to justify bumping the version number and making older Blooms unable to read new books. But because this is run, the xmatter will be migrated to the new template.
private BringBookUpToDate ( HtmlDom bookDOM, IProgress progress ) : void
bookDOM HtmlDom
progress IProgress
return void
        public void BringBookUpToDate_MigratesReaderToolsAvailableToToolboxIsOpen()
        {
            var oldMetaData =
                "{\"bookInstanceId\":\"3328aa4a - 2ef3 - 43a8 - a656 - 1d7c6f00444c\",\"folio\":false,\"title\":\"Landscape basic book\",\"baseUrl\":null,\"bookOrder\":null,\"isbn\":\"\",\"bookLineage\":\"056B6F11-4A6C-4942-B2BC-8861E62B03B3\",\"downloadSource\":null,\"license\":\"cc-by\",\"formatVersion\":\"2.0\",\"licenseNotes\":null,\"copyright\":null,\"authors\":null,\"credits\":\"\",\"tags\":[\"<p>\r\n</p>\"],\"pageCount\":0,\"languages\":[],\"langPointers\":null,\"summary\":null,\"allowUploadingToBloomLibrary\":true,\"bookletMakingIsAppropriate\":true,\"uploader\":null,\"tools\":null,\"readerToolsAvailable\":true}";
            var storage = GetInitialStorage();

            // This seems to be needed to let it locate some kind of collection settings.
            var    folder  = storage.FolderPath;
            var    locator = (FileLocator)storage.GetFileLocator();
            string root    = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);

            locator.AddPath(root.CombineForPath("bookLayout"));
            var collectionSettings =
                new CollectionSettings(new NewCollectionSettings()
            {
                PathToSettingsFile  = CollectionSettings.GetPathForNewSettings(folder, "test"),
                Language1Iso639Code = "xyz",
                Language2Iso639Code = "en",
                Language3Iso639Code = "fr"
            });
            var book = new Bloom.Book.Book(new BookInfo(folder, true), storage, new Mock <ITemplateFinder>().Object,
                                           collectionSettings,
                                           new Mock <PageSelection>().Object, new PageListChangedEvent(), new BookRefreshEvent());
            var jsonPath = book.BookInfo.MetaDataPath;

            File.WriteAllText(jsonPath, oldMetaData);

            book.BringBookUpToDate(new NullProgress());

            Assert.That(book.BookInfo.ToolboxIsOpen, Is.True);
        }
        public void BringBookUpToDate_ConvertsTagsToJsonWithExpectedDefaults()
        {
            var    storage = GetInitialStorage();
            var    locator = (FileLocator)storage.GetFileLocator();
            string root    = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);

            locator.AddPath(root.CombineForPath("bookLayout"));
            var folder   = storage.FolderPath;
            var tagsPath = Path.Combine(folder, "tags.txt");

            File.WriteAllText(tagsPath, "suitableForMakingShells\nexperimental\nfolio\n");
            var collectionSettings =
                new CollectionSettings(new NewCollectionSettings()
            {
                PathToSettingsFile  = CollectionSettings.GetPathForNewSettings(folder, "test"),
                Language1Iso639Code = "xyz",
                Language2Iso639Code = "en",
                Language3Iso639Code = "fr"
            });
            var book = new Bloom.Book.Book(new BookInfo(folder, true), storage, new Mock <ITemplateFinder>().Object,
                                           collectionSettings,
                                           new Mock <PageSelection>().Object, new PageListChangedEvent(), new BookRefreshEvent());

            book.BringBookUpToDate(new NullProgress());

            Assert.That(!File.Exists(tagsPath), "The tags.txt file should have been removed");
            // BL-2163, we are no longer migrating suitableForMakingShells
            Assert.That(storage.MetaData.IsSuitableForMakingShells, Is.False);
            Assert.That(storage.MetaData.IsFolio, Is.True);
            Assert.That(storage.MetaData.IsExperimental, Is.True);
            Assert.That(storage.MetaData.BookletMakingIsAppropriate, Is.True);
            Assert.That(storage.MetaData.AllowUploading, Is.True);
        }
        public void BringBookUpToDate_ConvertsTagsToJsonWithExpectedDefaults()
        {
            var storage = GetInitialStorage();
            var locator = (FileLocator) storage.GetFileLocator();
            string root = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
            locator.AddPath(root.CombineForPath("bookLayout"));
            var folder = storage.FolderPath;
            var tagsPath = Path.Combine(folder, "tags.txt");
            File.WriteAllText(tagsPath, "suitableForMakingShells\nexperimental\nfolio\n");
            var collectionSettings =
                new CollectionSettings(new NewCollectionSettings()
                {
                    PathToSettingsFile = CollectionSettings.GetPathForNewSettings(folder, "test"),
                    Language1Iso639Code = "xyz",
                    Language2Iso639Code = "en",
                    Language3Iso639Code = "fr"
                });
            var book = new Bloom.Book.Book(new BookInfo(folder, true), storage, new Mock<ITemplateFinder>().Object,
                collectionSettings,
                new Mock<PageSelection>().Object, new PageListChangedEvent(), new BookRefreshEvent());

            book.BringBookUpToDate(new NullProgress());

            Assert.That(!File.Exists(tagsPath), "The tags.txt file should have been removed");
            // BL-2163, we are no longer migrating suitableForMakingShells
            Assert.That(storage.MetaData.IsSuitableForMakingShells, Is.False);
            Assert.That(storage.MetaData.IsFolio, Is.True);
            Assert.That(storage.MetaData.IsExperimental, Is.True);
            Assert.That(storage.MetaData.BookletMakingIsAppropriate, Is.True);
            Assert.That(storage.MetaData.AllowUploading, Is.True);
        }
        /// <summary>
        /// Make an ePUB out of the specified book. Sets up several instance variables with commonly useful parts of the results.
        /// </summary>
        /// <returns></returns>
        protected virtual ZipFile MakeEpub(string mainFileName, string folderName, Bloom.Book.Book book,
                                           BookInfo.HowToPublishImageDescriptions howToPublishImageDescriptions = BookInfo.HowToPublishImageDescriptions.None,
                                           string branding = "Default", Action <EpubMaker> extraInit = null)
        {
            book.CollectionSettings.BrandingProjectKey = branding;

            // BringBookUpToDate is done on entering the Publish tab, outside the scope of these tests.
            // But note that it must be done AFTER setting the branding (which in Bloom will happen well before
            // entering the Publish tab).
            book.BringBookUpToDate(new NullProgress());
            var epubFolder = new TemporaryFolder(folderName);
            var epubName   = mainFileName + ".epub";
            var epubPath   = Path.Combine(epubFolder.FolderPath, epubName);

            using (var maker = CreateEpubMaker(book))
            {
                maker.Unpaginated = true;                 // Currently we always make unpaginated epubs.
                maker.PublishImageDescriptions = howToPublishImageDescriptions;
                extraInit?.Invoke(maker);
                maker.SaveEpub(epubPath, new NullWebSocketProgress());
            }
            Assert.That(File.Exists(epubPath));
            _epub               = new ZipFile(epubPath);
            _manifestFile       = ExportEpubTestsBaseClass.GetManifestFile(_epub);
            _manifestContent    = StripXmlHeader(GetZipContent(_epub, _manifestFile));
            _manifestDoc        = XDocument.Parse(_manifestContent);
            _defaultSourceValue = $"created from Bloom book on {DateTime.Now:yyyy-MM-dd} with page size A5 Portrait";
            return(_epub);
        }
        public void BringBookUpToDate_MigratesReaderToolsAvailableToToolboxIsOpen()
        {
            var oldMetaData =
                "{\"bookInstanceId\":\"3328aa4a - 2ef3 - 43a8 - a656 - 1d7c6f00444c\",\"folio\":false,\"title\":\"Landscape basic book\",\"baseUrl\":null,\"bookOrder\":null,\"isbn\":\"\",\"bookLineage\":\"056B6F11-4A6C-4942-B2BC-8861E62B03B3\",\"downloadSource\":null,\"license\":\"cc-by\",\"formatVersion\":\"2.0\",\"licenseNotes\":null,\"copyright\":null,\"authors\":null,\"credits\":\"\",\"tags\":[\"<p>\r\n</p>\"],\"pageCount\":0,\"languages\":[],\"langPointers\":null,\"summary\":null,\"allowUploadingToBloomLibrary\":true,\"bookletMakingIsAppropriate\":true,\"uploader\":null,\"tools\":null,\"readerToolsAvailable\":true}";
            var storage = GetInitialStorage();

            // This seems to be needed to let it locate some kind of collection settings.
            var folder = storage.FolderPath;
            var locator = (FileLocator)storage.GetFileLocator();
            string root = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);

            locator.AddPath(root.CombineForPath("bookLayout"));
            var collectionSettings =
                new CollectionSettings(new NewCollectionSettings()
                {
                    PathToSettingsFile = CollectionSettings.GetPathForNewSettings(folder, "test"),
                    Language1Iso639Code = "xyz",
                    Language2Iso639Code = "en",
                    Language3Iso639Code = "fr"
                });
            var book = new Bloom.Book.Book(new BookInfo(folder, true), storage, new Mock<ITemplateFinder>().Object,
                collectionSettings,
                new Mock<PageSelection>().Object, new PageListChangedEvent(), new BookRefreshEvent());
            var jsonPath = book.BookInfo.MetaDataPath;
            File.WriteAllText(jsonPath, oldMetaData);

            book.BringBookUpToDate(new NullProgress());

            Assert.That(book.BookInfo.ToolboxIsOpen, Is.True);
        }