/// <summary> /// Check if migration is required and if so the migration settings are initialized. /// </summary> /// <param name="filePath">The project file to open.</param> /// <param name="migrationConstructionProperties">Output: Will be null if this method /// returns <see cref="MigrationRequired.No"/> or <see cref="MigrationRequired.Aborted"/>. /// Will be a concrete instance if this method returns <see cref="MigrationRequired.Yes"/>.</param> /// <returns>Indicates if migration is required or not, or that the operation has /// been cancelled.</returns> /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is /// not a valid file path.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="filePath"/> /// is <c>null</c>.</exception> /// <exception cref="CriticalFileReadException">Thrown when the file at <paramref name="filePath"/> /// couldn't be read.</exception> /// <exception cref="StorageValidationException">Thrown when the file at <paramref name="filePath"/> /// is not a valid project file.</exception> private MigrationRequired PrepareProjectMigration(string filePath, out OpenProjectActivity.ProjectMigrationConstructionProperties migrationConstructionProperties) { migrationConstructionProperties = null; MigrationRequired migrationNeeded = projectMigrator.ShouldMigrate(filePath); if (migrationNeeded == MigrationRequired.Yes) { string projectFilePathTakingIntoAccountMigration = projectMigrator.DetermineMigrationLocation(filePath); if (string.IsNullOrWhiteSpace(projectFilePathTakingIntoAccountMigration)) { migrationNeeded = MigrationRequired.Aborted; } else { migrationConstructionProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties { Migrator = projectMigrator, MigrationFilePath = projectFilePathTakingIntoAccountMigration }; } } return(migrationNeeded); }
/// <summary> /// Opens the given project file and determines if migration to the current version is /// required and performs migration if needed. /// </summary> /// <param name="filePath">The project file to open.</param> /// <returns>Returns <c>true</c> if the project was successfully opened; Returns /// <c>false</c> if an error occurred or when opening the project has been cancelled.</returns> /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is /// not a valid file path.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="filePath"/> /// is <c>null</c>.</exception> /// <exception cref="CriticalFileReadException">Thrown when the file at <paramref name="filePath"/> /// couldn't be read.</exception> /// <exception cref="StorageValidationException">Thrown when the file at <paramref name="filePath"/> /// is not a valid project file.</exception> private bool OpenExistingProjectCore(string filePath) { MigrationRequired migrationRequired = PrepareProjectMigration( filePath, out OpenProjectActivity.ProjectMigrationConstructionProperties migrationProperties); if (migrationRequired == MigrationRequired.NotSupported) { projectOwner.SetProject(null, null); return(false); } if (migrationRequired == MigrationRequired.Aborted) { return(false); } return(MigrateAndOpenProject(filePath, migrationProperties)); }
public void ShouldMigrate_LatestProjectVersion_ReturnsFalse() { // Setup var mocks = new MockRepository(); var inquiryHelper = mocks.Stub <IInquiryHelper>(); mocks.ReplayAll(); string sourceFilePath = ProjectMigrationTestHelper.GetLatestProjectFilePath(); var migrator = new ProjectMigrator(inquiryHelper); // Call MigrationRequired shouldMigrate = migrator.ShouldMigrate(sourceFilePath); // Assert Assert.AreEqual(MigrationRequired.No, shouldMigrate); mocks.VerifyAll(); }
public void ShouldMigrate_OutdatedProjectSupported_AskMigrationConfirmationAndReturnBasedOnConfirmation(bool confirmContinuation) { // Setup string question = "Het project dat u wilt openen is opgeslagen in het formaat van een eerdere versie van Riskeer of Ringtoets." + $"{Environment.NewLine}{Environment.NewLine}" + $"Weet u zeker dat u het bestand wilt migreren naar het formaat van uw huidige Riskeerversie ({currentDatabaseVersion})?"; var mocks = new MockRepository(); var inquiryHelper = mocks.StrictMock <IInquiryHelper>(); inquiryHelper.Expect(h => h.InquireContinuation(question)).Return(confirmContinuation); mocks.ReplayAll(); string sourceFilePath = ProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); var migrator = new ProjectMigrator(inquiryHelper); // Call var shouldMigrate = MigrationRequired.No; void Call() => shouldMigrate = migrator.ShouldMigrate(sourceFilePath); // Assert var expectedLogMessages = new List <Tuple <string, LogLevelConstant> >(); if (!confirmContinuation) { expectedLogMessages.Add(Tuple.Create($"Het migreren van het projectbestand '{sourceFilePath}' is geannuleerd.", LogLevelConstant.Warn)); } TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedLogMessages, expectedLogMessages.Count); MigrationRequired expectedResult = confirmContinuation ? MigrationRequired.Yes : MigrationRequired.Aborted; Assert.AreEqual(expectedResult, shouldMigrate); mocks.VerifyAll(); }