public void Deploy_WithSourceAndDestinationDirectories_CopiesOneToTheOther()
        {
            // arrange
            var webroot = new SubtextDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
            webroot.Create();

            var destination = new SubtextDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
            destination.Create();

            var dir = webroot.Combine(Guid.NewGuid().ToString());
            dir.Create();

            var file = webroot.CombineFile(Guid.NewGuid().ToString());
            using (var sw = new StreamWriter(file.OpenWrite()))
                sw.WriteLine(@"Lorem ipsum dolor sit amet, consectetur adipiscing elit.");

            var fileDeployer = new FileDeployer(webroot, destination);

            // act
            fileDeployer.Deploy();

            // assert
            Assert.IsTrue(destination.CombineFile(file.Name).Exists);
            Assert.IsTrue(destination.Combine(dir.Name).Exists);
        }
        public void RemoveOldFiles_WithDestination_RemovesUnusedFiles()
        {
            // arrange
            var webroot = new Mock<IDirectory>();
            var destination = new Mock<IDirectory>();
            destination.Setup(d => d.CombineFile(It.IsAny<string>())).Returns(new Mock<IFile>().Object);
            var fileDeployer = new FileDeployer(webroot.Object, destination.Object);

            // act
            fileDeployer.RemoveOldFiles();

            // assert
            destination.Verify(d => d.CombineFile("AggDefault.aspx"));
        }
        public void RemoveOldDirectories_WithDestination_RemovesUnusedDirectories()
        {
            // arrange
            var webroot = new Mock<IDirectory>();
            var destination = new Mock<IDirectory>();
            destination.Setup(d => d.Combine(It.IsAny<string>())).Returns(new Mock<IDirectory>().Object);
            destination.Setup(d => d.CombineFile(It.IsAny<string>())).Returns(new Mock<IFile>().Object);
            var fileDeployer = new FileDeployer(webroot.Object, destination.Object);

            // act
            fileDeployer.RemoveOldDirectories();

            // assert
            destination.Verify(d => d.Combine("Admin"));
            destination.Verify(d => d.Combine("HostAdmin"));
            destination.Verify(d => d.Combine("Install"));
            destination.Verify(d => d.Combine("SystemMessages"));
        }
示例#4
0
        public void Run()
        {
            //assuming sourceDirectory is set, either explicitly or by unzipped resources.
            var sourceDirectory = new SubtextDirectory(Settings.SourceDirectory);

            if (!VerifyDirectory(sourceDirectory, "source"))
            {
                return;
            }

            var targetDirectory = new SubtextDirectory(Settings.UpgradeTargetDirectory);

            if (!VerifyDirectory(targetDirectory, "target"))
            {
                return;
            }

            IDirectory backup = null;

            if (!String.IsNullOrEmpty(Settings.BackupDirectory))
            {
                backup = new SubtextDirectory(Settings.BackupDirectory);
                if (!VerifyDirectory(backup, "backup"))
                {
                    return;
                }
            }

            string message = "Upgrading using the following settings:";

            Progress.ReportProgress(10, message);

            if (UserCancelled())
            {
                return;
            }

            message = string.Format("Source Directory: '{0}'", Settings.SourceDirectory);

            Progress.ReportProgress(10, message);

            if (UserCancelled())
            {
                return;
            }

            message = string.Format("Target Directory: '{0}", Settings.UpgradeTargetDirectory);

            Progress.ReportProgress(10, message);

            if (UserCancelled())
            {
                return;
            }

            if (backup != null)
            {
                message = string.Format("Backup Directory: '{0}", Settings.BackupDirectory);

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                {
                    return;
                }

                message = string.Format("Clearing backup directory '{0}'", backup.Path);

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                {
                    return;
                }

                backup.Delete(true);
                backup.Create();
                message = "Backing up source and target directories";

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                {
                    return;
                }

                sourceDirectory.CopyTo(backup.Combine("source").Create());
                targetDirectory.CopyTo(backup.Combine("target").Create());
            }

            var configUpgrader = new WebConfigUpgrader(sourceDirectory);

            message = "Upgrading Web.config";

            Progress.ReportProgress(30, message);

            if (UserCancelled())
            {
                return;
            }

            configUpgrader.UpgradeConfig(targetDirectory);

            var customSkinConfig = targetDirectory.CombineFile(@"Admin\Skins.User.config");

            if (customSkinConfig.Exists)
            {
                message = "Updating skin.config for custom skins";

                Progress.ReportProgress(60, message);

                if (UserCancelled())
                {
                    return;
                }

                var skinConfig     = new LegacySkinsConfig(customSkinConfig);
                var skinsDirectory = sourceDirectory.Combine(@"Skins").Ensure();
                skinConfig.UpgradeSkins(skinsDirectory);
            }
            else
            {
                message = string.Format("Did not find custom skins file at '{0}'", customSkinConfig.Path);

                Progress.ReportProgress(60, message);

                if (UserCancelled())
                {
                    return;
                }
            }

            message = string.Format("Deploying '{0}' to '{1}'", sourceDirectory.Path, targetDirectory.Path);

            Progress.ReportProgress(80, message);

            if (UserCancelled())
            {
                return;
            }

            var deployer = new FileDeployer(sourceDirectory, targetDirectory);

            deployer.Deploy();

            message = "Cleaning up old directories";

            Progress.ReportProgress(90, message);

            if (UserCancelled())
            {
                return;
            }

            deployer.RemoveOldDirectories();


            message = "Checking skins for references to legacy Subtext.Web.Controls assembly.";
            Progress.ReportProgress(95, message);

            var skinUpgrader = new SkinUpgrader(targetDirectory.Combine("Skins"));

            skinUpgrader.Run();


            message = "Done!";

            Progress.ReportProgress(100, message);
        }
示例#5
0
        public void Run()
        {
            //assuming sourceDirectory is set, either explicitly or by unzipped resources.
            var sourceDirectory = new SubtextDirectory(Settings.SourceDirectory);
            if (!VerifyDirectory(sourceDirectory, "source"))
            {
                return;
            }

            var targetDirectory = new SubtextDirectory(Settings.UpgradeTargetDirectory);
            if (!VerifyDirectory(targetDirectory, "target"))
            {
                return;
            }

            IDirectory backup = null;
            if (!String.IsNullOrEmpty(Settings.BackupDirectory))
            {
                backup = new SubtextDirectory(Settings.BackupDirectory);
                if (!VerifyDirectory(backup, "backup"))
                {
                    return;
                }
            }

            string message = "Upgrading using the following settings:";

            Progress.ReportProgress(10, message);

            if (UserCancelled())
                return;

            message = string.Format("Source Directory: '{0}'", Settings.SourceDirectory);

            Progress.ReportProgress(10, message);

            if (UserCancelled())
                return;

            message = string.Format("Target Directory: '{0}", Settings.UpgradeTargetDirectory);

            Progress.ReportProgress(10, message);

            if (UserCancelled())
                return;

            if (backup != null)
            {
                message = string.Format("Backup Directory: '{0}", Settings.BackupDirectory);

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                    return;

                message = string.Format("Clearing backup directory '{0}'", backup.Path);

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                    return;

                backup.Delete(true);
                backup.Create();
                message = "Backing up source and target directories";

                Progress.ReportProgress(20, message);

                if (UserCancelled())
                    return;

                sourceDirectory.CopyTo(backup.Combine("source").Create());
                targetDirectory.CopyTo(backup.Combine("target").Create());
            }

            var configUpgrader = new WebConfigUpgrader(sourceDirectory);
            message = "Upgrading Web.config";

            Progress.ReportProgress(30, message);

            if (UserCancelled())
                return;

            configUpgrader.UpgradeConfig(targetDirectory);

            var customSkinConfig = targetDirectory.CombineFile(@"Admin\Skins.User.config");
            if (customSkinConfig.Exists)
            {
                message = "Updating skin.config for custom skins";

                Progress.ReportProgress(60, message);

                if (UserCancelled())
                    return;

                var skinConfig = new LegacySkinsConfig(customSkinConfig);
                var skinsDirectory = sourceDirectory.Combine(@"Skins").Ensure();
                skinConfig.UpgradeSkins(skinsDirectory);
            }
            else
            {
                message = string.Format("Did not find custom skins file at '{0}'", customSkinConfig.Path);

                Progress.ReportProgress(60, message);

                if (UserCancelled())
                    return;
            }

            message = string.Format("Deploying '{0}' to '{1}'", sourceDirectory.Path, targetDirectory.Path);

            Progress.ReportProgress(80, message);

            if (UserCancelled())
                return;

            var deployer = new FileDeployer(sourceDirectory, targetDirectory);
            deployer.Deploy();

            message = "Cleaning up old directories";

            Progress.ReportProgress(90, message);

            if (UserCancelled())
                return;

            deployer.RemoveOldDirectories();

            message = "Checking skins for references to legacy Subtext.Web.Controls assembly.";
            Progress.ReportProgress(95, message);

            var skinUpgrader = new SkinUpgrader(targetDirectory.Combine("Skins"));
            skinUpgrader.Run();

            message = "Done!";

            Progress.ReportProgress(100, message);
        }