示例#1
0
        public void UpdateFullArchive()
        {
            string TestName         = $"UpdateFullArchive_DefaultUpdateDir_Logging";
            string AppDir           = Path.Combine(Helper.BaseDirectory, TestName, "app");
            string UpdateDir        = Path.Combine(Helper.BaseDirectory, TestName, "update");
            string DefaultUpdateDir = Path.Combine(AppDir, "update");
            string UpdateFiles      = Path.Combine(Helper.BaseDirectory, TestName, "updateFiles");

            // Cleanup prior test
            if (Directory.Exists(AppDir))
            {
                Directory.Delete(AppDir, true);
            }
            if (Directory.Exists(UpdateDir))
            {
                Directory.Delete(UpdateDir, true);
            }
            if (Directory.Exists(UpdateFiles))
            {
                Directory.Delete(UpdateFiles, true);
            }

            // Prepare
            Helper.CopyDirectory(Path.Combine(Helper.TestFilesDirectory, "app_v1"), AppDir);
            Helper.CopyDirectory(Path.Combine(Helper.TestFilesDirectory, "updatedir_v3"), UpdateFiles);
            // force full archive update by making sure its smaller than the patches
            string     updateInfoFile = Path.Combine(UpdateFiles, "update.json");
            UpdateInfo updateInfo     = UpdateInfo.Deserialize(File.ReadAllText(updateInfoFile));

            updateInfo.PatchTrail[updateInfo.PatchTrail.Count - 1].SizeInBytes = updateInfo.FullAppArchiveSize * 2;
            File.WriteAllText(updateInfoFile, updateInfo.Serialize());

            // Start app
            string  arguments = $"{new Uri(UpdateFiles).ToString()} true";
            Process app       = Process.Start(Path.Combine(AppDir, Helper.AppName), arguments);

            app.WaitForExit();
            Assert.Equal(0, app.ExitCode);

            Thread.Sleep(Helper.UPDATER_TIMEOUT); // wait for the updater to patch the files

            Assert.True(Directory.Exists(DefaultUpdateDir));
            Directory.Move(DefaultUpdateDir, UpdateDir);

            Assert.True(Helper.DirectoriesEqual(Path.Combine(Helper.TestFilesDirectory, "app_v3"), AppDir));
        }