Index: Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs =================================================================== diff -u -r5ec759496df2662a183c1c5ed74e3724bd834ae2 -r4e4518eddf542f7f0d74b3f9125ee8326597ddda --- Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs (.../RingtoetsProjectMigrator.cs) (revision 5ec759496df2662a183c1c5ed74e3724bd834ae2) +++ Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs (.../RingtoetsProjectMigrator.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda) @@ -64,16 +64,16 @@ Resources.RingtoetsProject_FileExtension); } - public bool ShouldMigrate(string sourceFilePath) + public bool ShouldMigrate(string filePath) { - if (sourceFilePath == null) + if (filePath == null) { - throw new ArgumentNullException(nameof(sourceFilePath)); + throw new ArgumentNullException(nameof(filePath)); } - ValidateProjectPath(sourceFilePath); + ValidateProjectPath(filePath); - var versionedFile = new RingtoetsVersionedFile(sourceFilePath); + var versionedFile = new RingtoetsVersionedFile(filePath); string version = versionedFile.GetVersion(); if (version.Equals(currentProjectVersion)) @@ -91,29 +91,29 @@ return isVersionSupported; } - public string Migrate(string sourceFilePath) + public string Migrate(string filePath) { - if (sourceFilePath == null) + if (filePath == null) { - throw new ArgumentNullException(nameof(sourceFilePath)); + throw new ArgumentNullException(nameof(filePath)); } - ValidateProjectPath(sourceFilePath); + ValidateProjectPath(filePath); string query = Resources.RingtoetsProjectMigrator_Migrate_Outdated_project_file_update_to_current_version_inquire; if (inquiryHelper.InquireContinuation(query)) { - string suggestedFileName = GetSuggestedFileName(sourceFilePath); - string targetLocation = GetTargetFileLocation(suggestedFileName); + string suggestedFileName = GetSuggestedFileName(filePath); + string targetLocation = inquiryHelper.GetTargetFileLocation(fileFilter, suggestedFileName); if (!string.IsNullOrEmpty(targetLocation)) { - return MigrateToTargetLocation(sourceFilePath, targetLocation); + return MigrateToTargetLocation(filePath, targetLocation); } - GenerateMigrationCancelledLogMessage(sourceFilePath); + GenerateMigrationCancelledLogMessage(filePath); } - GenerateMigrationCancelledLogMessage(sourceFilePath); + GenerateMigrationCancelledLogMessage(filePath); return null; } Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs =================================================================== diff -u -r1324acb0da896511c15a2391338a50418cab8494 -r4e4518eddf542f7f0d74b3f9125ee8326597ddda --- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs (.../RingtoetsProjectMigratorTest.cs) (revision 1324acb0da896511c15a2391338a50418cab8494) +++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs (.../RingtoetsProjectMigratorTest.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda) @@ -82,7 +82,7 @@ // Assert string paramName = Assert.Throws(call).ParamName; - Assert.AreEqual("sourceFilePath", paramName); + Assert.AreEqual("filePath", paramName); mocks.VerifyAll(); } @@ -204,7 +204,7 @@ // Assert string paramName = Assert.Throws(call).ParamName; - Assert.AreEqual("sourceFilePath", paramName); + Assert.AreEqual("filePath", paramName); } [Test] @@ -231,6 +231,7 @@ } // TODO: Investigate cause of the SaveFileDialogs hanging on the buildserver + //Causes the hanging on the buildserver . . . // [Test] // [Apartment(ApartmentState.STA)] // public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGivenWithoutExtension_ThenFileSuccessFullyMigratesAndExtensionAdded() @@ -278,86 +279,79 @@ // // mocks.VerifyAll(); // } + + [Test] + public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates() + { + // Setup + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd"); + + string targetFile = $"{nameof(GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates)}.rtd"; + string targetFilePath = Path.Combine(TestHelper.GetScratchPadPath(), testDirectory, targetFile); + string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + + const string message = "Het project dat u wilt openen is opgeslagen met een oudere " + + "versie van Ringtoets. Wilt u het bestand converteren naar uw " + + "huidige Ringtoetsversie?"; + inquiryHelper.Expect(helper => helper.InquireContinuation(message)).Return(true); + inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null)).IgnoreArguments().Return(targetFilePath); + mocks.ReplayAll(); + + var migrator = new RingtoetsProjectMigrator(inquiryHelper); + + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), testDirectory)) + { + string actualTargetFilePath = null; + + // When + Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath); + + // Then + string expectedMessage = $"Het projectbestand '{sourceFilePath}' is succesvol gemigreerd naar '{targetFilePath}' (versie {expectedVersion})."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + + Assert.AreEqual(targetFilePath, actualTargetFilePath); + var toVersionedFile = new RingtoetsVersionedFile(targetFilePath); + Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion()); + } + + mocks.VerifyAll(); + } + + [Test] + public void GivenMigratorAndSupportedFile_WhenDiscontinuedAfterInquiry_ThenFileNotMigrated() + { + // Setup + string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd"); + + var mocks = new MockRepository(); + var inquiryHelper = mocks.StrictMock(); + + const string message = "Het project dat u wilt openen is opgeslagen met een oudere " + + "versie van Ringtoets. Wilt u het bestand converteren naar uw " + + "huidige Ringtoetsversie?"; + inquiryHelper.Expect(helper => helper.InquireContinuation(message)).Return(false); + mocks.ReplayAll(); + + var migrator = new RingtoetsProjectMigrator(inquiryHelper); + string actualTargetFilePath = string.Empty; + + // Call + Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath); + + // Then + string expectedMessage = $"Het migreren van het projectbestand '{sourceFilePath}' is geannuleerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + Assert.IsNull(actualTargetFilePath); + + mocks.VerifyAll(); + } // // [Test] // [Apartment(ApartmentState.STA)] -// public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates() -// { -// // Setup -// string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd"); -// -// string targetFile = $"{nameof(GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates)}.rtd"; -// string targetFilePath = Path.Combine(TestHelper.GetScratchPadPath(), testDirectory, targetFile); -// string expectedVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); -// -// var mocks = new MockRepository(); -// var inquiryHelper = mocks.StrictMock(); -// -// const string message = "Het project dat u wilt openen is opgeslagen met een oudere " + -// "versie van Ringtoets. Wilt u het bestand converteren naar uw " + -// "huidige Ringtoetsversie?"; -// inquiryHelper.Expect(helper => helper.InquireContinuation(message)).Return(true); -// mocks.ReplayAll(); -// -// var migrator = new RingtoetsProjectMigrator(inquiryHelper); -// -// using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), testDirectory)) -// { -// string actualTargetFilePath = null; -// -// DialogBoxHandler = (name, wnd) => -// { -// var helper = new SaveFileDialogTester(wnd); -// helper.SaveFile(targetFilePath); -// }; -// -// // When -// Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath); -// -// // Then -// string expectedMessage = $"Het projectbestand '{sourceFilePath}' is succesvol gemigreerd naar '{targetFilePath}' (versie {expectedVersion})."; -// TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); -// -// Assert.AreEqual(targetFilePath, actualTargetFilePath); -// var toVersionedFile = new RingtoetsVersionedFile(targetFilePath); -// Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion()); -// } -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [Apartment(ApartmentState.STA)] -// public void GivenMigratorAndSupportedFile_WhenDiscontinuedAfterInquiry_ThenFileNotMigrated() -// { -// // Setup -// string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd"); -// -// var mocks = new MockRepository(); -// var inquiryHelper = mocks.StrictMock(); -// -// const string message = "Het project dat u wilt openen is opgeslagen met een oudere " + -// "versie van Ringtoets. Wilt u het bestand converteren naar uw " + -// "huidige Ringtoetsversie?"; -// inquiryHelper.Expect(helper => helper.InquireContinuation(message)).Return(false); -// mocks.ReplayAll(); -// -// var migrator = new RingtoetsProjectMigrator(inquiryHelper); -// string actualTargetFilePath = string.Empty; -// -// // Call -// Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath); -// -// // Then -// string expectedMessage = $"Het migreren van het projectbestand '{sourceFilePath}' is geannuleerd."; -// TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); -// Assert.IsNull(actualTargetFilePath); -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [Apartment(ApartmentState.STA)] // public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryButCancelledSaveFileDialog_ThenFileNotMigrated() // { // // Setup Index: Core/Common/src/Core.Common.Base/Storage/IMigrateProject.cs =================================================================== diff -u -r5ec759496df2662a183c1c5ed74e3724bd834ae2 -r4e4518eddf542f7f0d74b3f9125ee8326597ddda --- Core/Common/src/Core.Common.Base/Storage/IMigrateProject.cs (.../IMigrateProject.cs) (revision 5ec759496df2662a183c1c5ed74e3724bd834ae2) +++ Core/Common/src/Core.Common.Base/Storage/IMigrateProject.cs (.../IMigrateProject.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda) @@ -29,31 +29,31 @@ public interface IMigrateProject { /// - /// Indicates if the project from needs to be + /// Indicates if the project from needs to be /// updated to the newest version. /// - /// The file path of the project which needs to be checked. + /// The filepath of the project which needs to be checked. /// true if the file needs to be migrated, false if: /// /// The file does not need to be migrated. /// The file is not supported for the migration. /// - /// Thrown when is null. - /// Thrown when is an invalid file path. - bool ShouldMigrate(string sourceFilePath); + /// Thrown when is null. + /// Thrown when is an invalid file path. + bool ShouldMigrate(string filePath); /// - /// Migrates an outdated project file from + /// Migrates an outdated project file from /// to the newest project version version at a user defined target filepath. /// - /// The project file which needs to be migrated. + /// The filepath of the project which needs to be migrated. /// A filepath to the updated project file. null if: /// /// The user cancelled. /// The migration failed. /// - /// Thrown when is null. - /// Thrown when is an invalid file path. - string Migrate(string sourceFilePath); + /// Thrown when is null. + /// Thrown when is an invalid file path. + string Migrate(string filePath); } } Index: Core/Common/src/Core.Common.Gui/DialogBasedInquiryHelper.cs =================================================================== diff -u -r8eb717ca45b6518cccfef85e481e0da52ce1df4e -r4e4518eddf542f7f0d74b3f9125ee8326597ddda --- Core/Common/src/Core.Common.Gui/DialogBasedInquiryHelper.cs (.../DialogBasedInquiryHelper.cs) (revision 8eb717ca45b6518cccfef85e481e0da52ce1df4e) +++ Core/Common/src/Core.Common.Gui/DialogBasedInquiryHelper.cs (.../DialogBasedInquiryHelper.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda) @@ -75,10 +75,17 @@ public string GetTargetFileLocation() { + return GetTargetFileLocation(new FileFilterGenerator(), null); + } + + public string GetTargetFileLocation(FileFilterGenerator filter, string suggestedFileName) + { string filePath = null; using (SaveFileDialog dialog = new SaveFileDialog { - Title = Resources.SaveFileDialog_Title + Title = Resources.SaveFileDialog_Title, + Filter = filter.Filter, + FileName = suggestedFileName }) { DialogResult result = dialog.ShowDialog(); Index: Core/Common/src/Core.Common.Gui/IInquiryHelper.cs =================================================================== diff -u -r199f41a71b3b4c214f819f4519fffd4dc9418ff9 -r4e4518eddf542f7f0d74b3f9125ee8326597ddda --- Core/Common/src/Core.Common.Gui/IInquiryHelper.cs (.../IInquiryHelper.cs) (revision 199f41a71b3b4c214f819f4519fffd4dc9418ff9) +++ Core/Common/src/Core.Common.Gui/IInquiryHelper.cs (.../IInquiryHelper.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda) @@ -48,6 +48,15 @@ string GetTargetFileLocation(); /// + /// Returns the path to a file, which may or may not exist yet, that the user has chosen. + /// + /// A filter to which the path returned complies. + /// The initial name the user can choose. + /// A path to a file, which may or may not exist yet, or null if no location + /// was chosen. + string GetTargetFileLocation(FileFilterGenerator filter, string suggestedName); + + /// /// Gets the confirmation of a user. /// /// The query to which the user needs to answer.