private static void WarningUpgrade()
        {
            // WARNING: Target file not found in backup.
            var testXmlFile = Path.Combine(Directory.GetCurrentDirectory(), @"Web.config");
            var fileList    = new List <TargetFileInfo>
            {
                new TargetFileInfo(
                    testXmlFile,
                    testXmlFile + ".upgrade"
                    )
            };

            var parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion(String.Empty),
                                               fileList);

            parameters.DumpToLog();

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode      = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }

            // WARNING: Target file not found: NotExist.config
            testXmlFile = @"NotExist.config";
            var upgradeFile = Path.Combine(Directory.GetCurrentDirectory(), @"Config1.xml.upgrade");

            fileList = new List <TargetFileInfo>
            {
                new TargetFileInfo(
                    testXmlFile,
                    upgradeFile
                    )
            };

            parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.0.1"), fileList);

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode      = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }

            // WARNING: Upgrade file info not found.
            fileList = new List <TargetFileInfo>
            {
                new TargetFileInfo(
                    testXmlFile,
                    testXmlFile + ".upgrade"
                    )
            };

            parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.0.1"), fileList);

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode      = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }
        }
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private static void RunUpgrade(string testXmlFile, string testNewXmlFile, bool expectedSuccessResult = true)
        {
            var fileList = new List <TargetFileInfo>
            {
                new TargetFileInfo(
                    testXmlFile,
                    testXmlFile + ".upgrade"
                    )
            };

            var parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.2.0"),
                                               fileList);

            parameters.DumpToLog();

            {
                var stageBackup = new StageBackup(parameters);
                var retCode     = stageBackup.Run();
                Assert.AreEqual(0, retCode);
            }

            File.Copy(testNewXmlFile, testXmlFile, true);

            {
                var definedMsiProperties = new Dictionary <string, string>
                {
                    { "ComputerName", "msk-app-0839" }
                };
                var stageUpgrade = new StageUpgrade(parameters, definedMsiProperties);
                var retCode      = stageUpgrade.Run();

                if (expectedSuccessResult)
                {
                    Assert.AreEqual(0, retCode);
                }
                else
                {
                    Assert.AreNotEqual(0, retCode);
                }
            }
        }
Exemplo n.º 3
0
        private void GoButton_Click(object sender, EventArgs e)
        {
            LogEdit.Clear();

            LogWriteLine("Validating parameters");
            if (!CheckTextBox(InstalledVersionEdit, "Installed Version"))
                return;

            if (!CheckTextBox(InstalledFileEdit, "Installed File"))
                return;

            if (!CheckTextBox(NewVersionEdit, "New Version"))
                return;

            if (!CheckTextBox(NewFileEdit, "New File"))
                return;

            if (!CheckTextBox(UpgradeFileEdit, "Upgrade File"))
                return;

            if (!CheckTextBox(WorkFolderEdit, "Work Folder"))
                return;

            {
                RegistrySettings.SaveValue("InstalledFilePath", InstalledFileEdit.Text);
                RegistrySettings.SaveValue("NewFilePath", NewFileEdit.Text);
                RegistrySettings.SaveValue("UpgradeFilePath", UpgradeFileEdit.Text);
                RegistrySettings.SaveValue("WorkFolder", WorkFolderEdit.Text);

                RegistrySettings.SaveValue("NewVersion", NewVersionEdit.Text);
                RegistrySettings.SaveValue("InstalledVersion", InstalledVersionEdit.Text);
            }

            if(!Directory.Exists(WorkFolderEdit.Text))
            {
                LogWriteLine("Creating work folder");
                Directory.CreateDirectory(WorkFolderEdit.Text);
            }

            var targetFile = Path.Combine(WorkFolderEdit.Text, Path.GetFileName(InstalledFileEdit.Text) + ".UPGRADED");

            LogWriteLine("Copying installed file to target");
            File.Copy(InstalledFileEdit.Text, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);

            var fileList = new List<TargetFileInfo>
                               	{
                               		new TargetFileInfo(
                               			targetFile,
                               			UpgradeFileEdit.Text
                               			)
                               	};

            var parameters = new RunParameters(
                "TestProduct",
                new InstallerVersion(NewVersionEdit.Text),
                new InstallerVersion(InstalledVersionEdit.Text),
                fileList);

            {
                LogWriteLine("Processing Backup Stage...");
                var stageBackup = new StageBackup(parameters);
                var retCode = stageBackup.Run();
                if(retCode != 0)
                {
                    LogWriteLine("Backup Stage FAILED: " + retCode);
                    return;
                }
            }

            LogWriteLine("Copying new file to target");
            File.Copy(NewFileEdit.Text, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);

            {
                LogWriteLine("Processing Upgrade Stage...");
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode = stageUpgrade.Run();
                if (retCode != 0)
                {
                    LogWriteLine("Upgrade Stage FAILED: " + retCode);
                    return;
                }
            }

            LogWriteLine("Successfully completed.");
            LogWriteLine("");
            LogWriteLine("See target file: " + targetFile);
        }
        private static void RunUpgrade(string testXmlFile, string testNewXmlFile, bool expectedSuccessResult = true)
        {
            var fileList = new List<TargetFileInfo>
                               	{
                               		new TargetFileInfo(
                               			testXmlFile,
                               			testXmlFile + ".upgrade"
                               			)
                               	};

            var parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.2.0"),
                fileList);
            parameters.DumpToLog();

            {
                var stageBackup = new StageBackup(parameters);
                var retCode = stageBackup.Run();
                Assert.AreEqual(0, retCode);
            }

            File.Copy(testNewXmlFile, testXmlFile, true);

            {
                var definedMsiProperties = new Dictionary<string, string>
                                           	{
                                           		{"ComputerName", "msk-app-0839"}
                                           	};
                var stageUpgrade = new StageUpgrade(parameters, definedMsiProperties);
                var retCode = stageUpgrade.Run();

                if (expectedSuccessResult)
                {
                    Assert.AreEqual(0, retCode);
                }
                else
                {
                    Assert.AreNotEqual(0, retCode);
                }
            }
        }
        private static void WarningUpgrade()
        {
            // WARNING: Target file not found in backup.
            var testXmlFile = Path.Combine(Directory.GetCurrentDirectory(), @"Web.config");
            var fileList = new List<TargetFileInfo>
                               	{
                               		new TargetFileInfo(
                               			testXmlFile,
                               			testXmlFile + ".upgrade"
                               			)
                               	};

            var parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion(String.Empty),
                fileList);
            parameters.DumpToLog();

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }

            // WARNING: Target file not found: NotExist.config
            testXmlFile = @"NotExist.config";
            var upgradeFile = Path.Combine(Directory.GetCurrentDirectory(), @"Config1.xml.upgrade");
            fileList = new List<TargetFileInfo>
                               	{
                               		new TargetFileInfo(
                               			testXmlFile,
                               			upgradeFile
                               			)
                               	};

            parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.0.1"), fileList);

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }

            // WARNING: Upgrade file info not found.
            fileList = new List<TargetFileInfo>
                               	{
                               		new TargetFileInfo(
                               			testXmlFile,
                               			testXmlFile + ".upgrade"
                               			)
                               	};

            parameters = new RunParameters("TestProduct", new InstallerVersion("1.10.1"), new InstallerVersion("1.0.1"), fileList);

            {
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode = stageUpgrade.Run();
                Assert.AreEqual(0, retCode);
            }
        }
Exemplo n.º 6
0
        private void GoButton_Click(object sender, EventArgs e)
        {
            LogEdit.Clear();


            LogWriteLine("Validating parameters");
            if (!CheckTextBox(InstalledVersionEdit, "Installed Version"))
            {
                return;
            }

            if (!CheckTextBox(InstalledFileEdit, "Installed File"))
            {
                return;
            }


            if (!CheckTextBox(NewVersionEdit, "New Version"))
            {
                return;
            }

            if (!CheckTextBox(NewFileEdit, "New File"))
            {
                return;
            }


            if (!CheckTextBox(UpgradeFileEdit, "Upgrade File"))
            {
                return;
            }

            if (!CheckTextBox(WorkFolderEdit, "Work Folder"))
            {
                return;
            }

            {
                RegistrySettings.SaveValue("InstalledFilePath", InstalledFileEdit.Text);
                RegistrySettings.SaveValue("NewFilePath", NewFileEdit.Text);
                RegistrySettings.SaveValue("UpgradeFilePath", UpgradeFileEdit.Text);
                RegistrySettings.SaveValue("WorkFolder", WorkFolderEdit.Text);

                RegistrySettings.SaveValue("NewVersion", NewVersionEdit.Text);
                RegistrySettings.SaveValue("InstalledVersion", InstalledVersionEdit.Text);
            }

            if (!Directory.Exists(WorkFolderEdit.Text))
            {
                LogWriteLine("Creating work folder");
                Directory.CreateDirectory(WorkFolderEdit.Text);
            }

            var targetFile = Path.Combine(WorkFolderEdit.Text, Path.GetFileName(InstalledFileEdit.Text) + ".UPGRADED");

            LogWriteLine("Copying installed file to target");
            File.Copy(InstalledFileEdit.Text, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);

            var fileList = new List <TargetFileInfo>
            {
                new TargetFileInfo(
                    targetFile,
                    UpgradeFileEdit.Text
                    )
            };

            var parameters = new RunParameters(
                "TestProduct",
                new InstallerVersion(NewVersionEdit.Text),
                new InstallerVersion(InstalledVersionEdit.Text),
                fileList);

            {
                LogWriteLine("Processing Backup Stage...");
                var stageBackup = new StageBackup(parameters);
                var retCode     = stageBackup.Run();
                if (retCode != 0)
                {
                    LogWriteLine("Backup Stage FAILED: " + retCode);
                    return;
                }
            }

            LogWriteLine("Copying new file to target");
            File.Copy(NewFileEdit.Text, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);

            {
                LogWriteLine("Processing Upgrade Stage...");
                var stageUpgrade = new StageUpgrade(parameters, null);
                var retCode      = stageUpgrade.Run();
                if (retCode != 0)
                {
                    LogWriteLine("Upgrade Stage FAILED: " + retCode);
                    return;
                }
            }

            LogWriteLine("Successfully completed.");
            LogWriteLine("");
            LogWriteLine("See target file: " + targetFile);
        }