public void Upgrade_ValidParameters_ExpectedProperties() { // Setup string filePath = TestHelper.GetScratchPadPath(nameof(Upgrade_ValidParameters_ExpectedProperties)); var mockRepository = new MockRepository(); var versionedFile = mockRepository.Stub <IVersionedFile>(); versionedFile.Expect(vf => vf.Location).Return(filePath); mockRepository.ReplayAll(); var createScript = new TestCreateScript("2"); var upgradeScript = new TestUpgradeScript("1", "2"); var migrationScript = new FileMigrationScript(createScript, upgradeScript); using (new FileDisposeHelper(filePath)) { // Call IVersionedFile upgradedFile = migrationScript.Upgrade(versionedFile); // Assert Assert.IsNotNull(upgradedFile); } mockRepository.VerifyAll(); }
public void Upgrade_VersionedFileNull_ThrowsArgumentNullException() { // Setup var createScript = new TestCreateScript("2"); var upgradeScript = new TestUpgradeScript("1", "2"); var migrationScript = new FileMigrationScript(createScript, upgradeScript); // Call TestDelegate call = () => migrationScript.Upgrade(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("sourceVersionedFile", paramName); }
/// <summary> /// Migrates <paramref name="versionedFile"/> to version <paramref name="toVersion"/> at location <paramref name="newFileLocation"/>. /// </summary> /// <param name="versionedFile">The source versioned file to migrate from.</param> /// <param name="toVersion">The version to upgrade to.</param> /// <param name="newFileLocation">The location where the migrated file needs to be saved.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the path of the <paramref name="versionedFile"/> or /// the <paramref name="newFileLocation"/> is invalid.</exception> /// <exception cref="CriticalMigrationException">Thrown when migrating <paramref name="versionedFile"/> /// to a new version on location <paramref name="newFileLocation"/> failed.</exception> public void Migrate(IVersionedFile versionedFile, string toVersion, string newFileLocation) { ValidateMigrationArguments(versionedFile, toVersion, newFileLocation); FileMigrationScript migrationScript = TryGetMigrationScript(versionedFile, toVersion); IVersionedFile upgradedVersionFile = migrationScript.Upgrade(versionedFile); if (!upgradedVersionFile.GetVersion().Equals(toVersion)) { Migrate(upgradedVersionFile, toVersion, newFileLocation); } else { MoveMigratedFile(upgradedVersionFile.Location, newFileLocation); } }