// No wip files left behind public void Migrate_Succeeds_CleansUpWipFilesAndBackupFiles() { using (var e = new EnvironmentForTest()) { e.WriteTestFile(EnvironmentForTest.XmlVersion1); var migrator = new FileMigrator(3, e.TestFilePath); migrator.AddVersionStrategy(new XPathVersion(3, "/configuration/@version")); migrator.AddMigrationStrategy(new XslStringMigrator(1, 2, EnvironmentForTest.Xsl1To2)); migrator.AddMigrationStrategy(new XslStringMigrator(2, 3, EnvironmentForTest.Xsl2To3)); migrator.Migrate(); var files = Directory.GetFiles(e.Path); Assert.That(files.Length, Is.EqualTo(1)); Assert.That(files, Has.Some.SamePath(e.TestFilePath)); } }
public void Migrate_UsingXslAndXml_ArrviesAtVersion3() { using (var e = new EnvironmentForTest()) { e.WriteTestFile(EnvironmentForTest.XmlVersion1); var migrator = new FileMigrator(3, e.TestFilePath); migrator.AddVersionStrategy(new XPathVersion(3, "/configuration/@version")); migrator.AddMigrationStrategy(new XslStringMigrator(1, 2, EnvironmentForTest.Xsl1To2)); migrator.AddMigrationStrategy(new XslStringMigrator(2, 3, EnvironmentForTest.Xsl2To3)); migrator.Migrate(); AssertThatXmlIn.File(e.TestFilePath).HasAtLeastOneMatchForXpath("configuration[@version='3']"); AssertThatXmlIn.File(e.TestFilePath).HasAtLeastOneMatchForXpath("/configuration/blah"); } }
public void Migrate_MissingMigrationStrategy_LeavesWipFiles() { using (var e = new EnvironmentForTest()) { e.WriteTestFile(EnvironmentForTest.XmlVersion1); var migrator = new FileMigrator(3, e.TestFilePath); migrator.AddVersionStrategy(new XPathVersion(3, "/configuration/@version")); migrator.AddMigrationStrategy(new XslStringMigrator(1, 2, EnvironmentForTest.Xsl1To2)); Assert.Throws<InvalidOperationException>(() => migrator.Migrate()); var files = Directory.GetFiles(e.Path); Assert.That(files, Has.Some.SamePath(e.TestFilePath)); Assert.That(files, Has.Some.SamePath(e.TestFilePath + ".bak")); Assert.That(files, Has.Some.SamePath(e.TestFilePath + ".Migrate_1_2")); } }
public void Migrate_WithBackupFileInTheWay_DoesntThrow() { using (var e = new EnvironmentForTest()) { e.WriteTestFile(EnvironmentForTest.XmlVersion1); var migrator = new FileMigrator(3, e.TestFilePath); File.Copy(migrator.SourceFilePath, migrator.BackupFilePath); // Place the backup file in the way. migrator.AddVersionStrategy(new XPathVersion(3, "/configuration/@version")); migrator.AddMigrationStrategy(new XslStringMigrator(1, 2, EnvironmentForTest.Xsl1To2)); migrator.AddMigrationStrategy(new XslStringMigrator(2, 3, EnvironmentForTest.Xsl2To3)); migrator.Migrate(); } }