public void UpgradeSkins_WritesNewSkins_ToSkinTemplateDirectory() { // arrange var targetDirectory = new Mock<IDirectory>(); targetDirectory.Setup(d => d.Combine("Skins")).Returns(targetDirectory.Object); targetDirectory.Setup(d => d.Combine("Foo")).Returns(targetDirectory.Object); const string configXml = @"<?xml version=""1.0""?> <SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <Skins> <SkinTemplate Name=""Foo"" TemplateFolder=""Foo"" StyleMergeMode=""MergedAfter""> <Styles> <Style href=""csharp.css"" /> </Styles> </SkinTemplate> </Skins> </SkinTemplates>"; var file = new Mock<IFile>(); file.Setup(f => f.Contents).Returns(configXml); file.Setup(f => f.Directory.Parent).Returns(targetDirectory.Object); var memoryStream = new NonDisposableMemoryStream(); var skinFile = new Mock<IFile>(); skinFile.Setup(f => f.OpenWrite()).Returns(memoryStream); var skinDirectory = new Mock<IDirectory>(); skinDirectory.Setup(d => d.Exists).Returns(false); skinDirectory.Setup(d => d.CombineFile("skin.config")).Returns(skinFile.Object); skinDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object); var skinsDirectory = new Mock<IDirectory>(); skinsDirectory.Setup(d => d.Combine("Foo")).Returns(skinDirectory.Object); skinsDirectory.Setup(d => d.Ensure()).Returns(skinDirectory.Object); var oldConfig = new LegacySkinsConfig(file.Object); // act oldConfig.UpgradeSkins(skinsDirectory.Object); // assert targetDirectory.Verify(d => d.CopyTo(skinDirectory.Object)); const string expected = @"<SkinTemplates> <SkinTemplate Name=""Foo"" StyleMergeMode=""MergedAfter""> <Styles> <Style href=""csharp.css"" /> </Styles> </SkinTemplate> </SkinTemplates>"; Assert.AreEqual(expected, memoryStream.ToStringContents()); }
public void GetNewSkinConfigs_WithLegacySkinConfigXml_ExtractsSkinConfigs() { // arrange const string configXml = @"<?xml version=""1.0""?> <SkinTemplates xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <Skins> <SkinTemplate Name=""Foo"" TemplateFolder=""Foo"" StyleMergeMode=""MergedAfter""> <Styles> <Style href=""csharp.css"" /> </Styles> </SkinTemplate> <SkinTemplate Name=""Bar"" TemplateFolder=""Bar""> <Styles> <Style href=""bar.css"" /> </Styles> </SkinTemplate> </Skins> </SkinTemplates>"; var file = new Mock<IFile>(); file.Setup(f => f.Contents).Returns(configXml); var oldConfig = new LegacySkinsConfig(file.Object); // act var configs = oldConfig.GetNewSkinConfigs(); // assert Assert.AreEqual(2, configs.Count()); const string expectedFirstXml = @"<SkinTemplates><SkinTemplate Name=""Foo"" StyleMergeMode=""MergedAfter""><Styles><Style href=""csharp.css"" /></Styles></SkinTemplate></SkinTemplates>"; Assert.AreEqual(expectedFirstXml, configs.First().Xml.OuterXml); Assert.AreEqual("Foo", configs.First().TemplateFolder); const string expectedSecondXml = @"<SkinTemplates><SkinTemplate Name=""Bar""><Styles><Style href=""bar.css"" /></Styles></SkinTemplate></SkinTemplates>"; Assert.AreEqual(expectedSecondXml, configs.ElementAt(1).Xml.OuterXml); Assert.AreEqual("Bar", configs.ElementAt(1).TemplateFolder); }
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); }
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); }