public void Test_InitializeVersion()
        {
            string applicationName = "TestApplication";

            string fullApplicationPath = TestUtilities.GetTestApplicationPath(this, applicationName);

            VersionTestUtilities.CreateDummyVersion(fullApplicationPath, String.Empty);

            ApplicationInstaller installer = new ApplicationInstaller();

            installer.ApplicationPath = applicationName;
            installer.FileMapper      = new MockFileMapper(this, TestUtilities.GetTestingPath(this));
            installer.InitializeVersion();


            string versionFile = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar
                                 + applicationName + Path.DirectorySeparatorChar
                                 + installer.DataDirectory + Path.DirectorySeparatorChar
                                 + "Version.number";

            Assert.IsTrue(File.Exists(versionFile), "The version file wasn't found in the data directory.");
        }
        public void Test_Backup_PrepareForUpdate()
        {
            string applicationName = "TestApplication";


            string applicationPath = TestUtilities.GetTestApplicationPath(this, applicationName);

            string dataDirectoryPath = TestUtilities.GetTestDataPath(this, applicationName);

            string backupDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Backup";

            string exportDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Export";

            string legacyDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Legacy";


            VersionTestUtilities.CreateDummyVersion(dataDirectoryPath, "testing");

            CreateDummyFiles(dataDirectoryPath);


            TestUser user = new TestUser();

            user.ID        = Guid.NewGuid();
            user.FirstName = "Test";
            user.LastName  = "Test";

            DataAccess.Data.Saver.Save(user);

            TestRole role = new TestRole();

            role.ID   = Guid.NewGuid();
            role.Name = "Test Role";

            DataAccess.Data.Saver.Save(role);

            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test";

            DataAccess.Data.Saver.Save(article);

            TestCategory category = new TestCategory();

            category.Name = "Test";

            DataAccess.Data.Saver.Save(category);


            // Export data
            ApplicationBackup backup = new ApplicationBackup();

            backup.BackupDirectoryPath = backupDirectoryPath;
            backup.ExportDirectoryPath = exportDirectoryPath;
            backup.DataDirectoryPath   = dataDirectoryPath;
            backup.LegacyDirectoryPath = legacyDirectoryPath;
            backup.PrepareForUpdate    = true;

            string zipFilePath = backup.Backup();

            Assert.IsTrue(File.Exists(zipFilePath), "The zip file wasn't created.");


            long total = 0;

            using (ZipAnalyzer analyzer = new ZipAnalyzer(zipFilePath))
            {
                total = analyzer.CountFiles();
            }

            Assert.AreEqual(7, total, "The total number of files in the the zip.");

            Assert.IsFalse(Directory.Exists(backup.ExportDirectoryPath), "The export directory is still there. It should be removed after export.");

            Assert.IsTrue(Directory.Exists(backup.LegacyDirectoryPath), "The legacy directory wasn't found when it should have been.");
        }