Index: Application/Ringtoets/src/Application.Ringtoets.Migration/Application.Ringtoets.Migration.csproj
===================================================================
diff -u -r5ec759496df2662a183c1c5ed74e3724bd834ae2 -red998a9f0da19ea9bdf8f790fb78b52652ec9116
--- Application/Ringtoets/src/Application.Ringtoets.Migration/Application.Ringtoets.Migration.csproj (.../Application.Ringtoets.Migration.csproj) (revision 5ec759496df2662a183c1c5ed74e3724bd834ae2)
+++ Application/Ringtoets/src/Application.Ringtoets.Migration/Application.Ringtoets.Migration.csproj (.../Application.Ringtoets.Migration.csproj) (revision ed998a9f0da19ea9bdf8f790fb78b52652ec9116)
@@ -40,7 +40,6 @@
-
Index: Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs
===================================================================
diff -u -r4e4518eddf542f7f0d74b3f9125ee8326597ddda -red998a9f0da19ea9bdf8f790fb78b52652ec9116
--- Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs (.../RingtoetsProjectMigrator.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda)
+++ Application/Ringtoets/src/Application.Ringtoets.Migration/RingtoetsProjectMigrator.cs (.../RingtoetsProjectMigrator.cs) (revision ed998a9f0da19ea9bdf8f790fb78b52652ec9116)
@@ -21,7 +21,6 @@
using System;
using System.IO;
-using System.Windows.Forms;
using Application.Ringtoets.Migration.Core;
using Application.Ringtoets.Migration.Properties;
using Core.Common.Base.Storage;
@@ -30,7 +29,6 @@
using log4net;
using Migration.Scripts.Data.Exceptions;
using Ringtoets.Common.Utils;
-using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources;
using MigrationCoreStorageResources = Migration.Core.Storage.Properties.Resources;
namespace Application.Ringtoets.Migration
@@ -61,7 +59,7 @@
this.inquiryHelper = inquiryHelper;
fileMigrator = new RingtoetsSqLiteDatabaseFileMigrator();
fileFilter = new FileFilterGenerator(Resources.RingtoetsProject_FileExtension,
- Resources.RingtoetsProject_FileExtension);
+ Resources.RingtoetsProject_TypeDescription);
}
public bool ShouldMigrate(string filePath)
@@ -155,25 +153,6 @@
log.Warn(warningMessage);
}
- private string GetTargetFileLocation(string suggestedFileName)
- {
- string filePath = null;
- using (var dialog = new SaveFileDialog
- {
- Title = CoreCommonGuiResources.SaveFileDialog_Title,
- Filter = fileFilter.Filter,
- FileName = suggestedFileName
- })
- {
- DialogResult result = dialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- filePath = dialog.FileName;
- }
- }
- return filePath;
- }
-
private static void ValidateProjectPath(string sourceFilePath)
{
if (!IOUtils.IsValidFilePath(sourceFilePath))
Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs
===================================================================
diff -u -r4e4518eddf542f7f0d74b3f9125ee8326597ddda -red998a9f0da19ea9bdf8f790fb78b52652ec9116
--- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs (.../RingtoetsProjectMigratorTest.cs) (revision 4e4518eddf542f7f0d74b3f9125ee8326597ddda)
+++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsProjectMigratorTest.cs (.../RingtoetsProjectMigratorTest.cs) (revision ed998a9f0da19ea9bdf8f790fb78b52652ec9116)
@@ -22,7 +22,6 @@
using System;
using System.IO;
using System.Linq;
-using System.Threading;
using Application.Ringtoets.Migration.Core;
using Core.Common.Base.Storage;
using Core.Common.Gui;
@@ -230,60 +229,41 @@
mocks.VerifyAll();
}
- // 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()
-// {
-// // Setup
-// string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
-//
-// string targetFile = $"{nameof(GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGivenWithoutExtension_ThenFileSuccessFullyMigratesAndExtensionAdded)}";
-// 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}.rtd' (versie {expectedVersion}).";
-// TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
-//
-// string expectedFilePathWithExtension = $"{targetFilePath}.rtd";
-// Assert.AreEqual(expectedFilePathWithExtension, actualTargetFilePath);
-// var toVersionedFile = new RingtoetsVersionedFile(expectedFilePathWithExtension);
-// Assert.AreEqual(expectedVersion, toVersionedFile.GetVersion());
-// }
-//
-// mocks.VerifyAll();
-// }
+ [Test]
+ public void Migrate_Always_ReturnsSuggestedFileNameAndFileFilter()
+ {
+ // Setup
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
+ 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);
+
+ string versionSuffix = expectedVersion.Replace(".", "-");
+ string expectedSuggestedFileName = $"FullTestProject164_{versionSuffix}";
+ inquiryHelper.Expect(helper => helper.GetTargetFileLocation(new FileFilterGenerator("rtd", "Ringtoets project"),
+ expectedSuggestedFileName))
+ .Return(null);
+ mocks.ReplayAll();
+
+ var migrator = new RingtoetsProjectMigrator(inquiryHelper);
+
+ // Call
+ migrator.Migrate(sourceFilePath);
+
+ // Assert
+ mocks.VerifyAll();
+ }
+
[Test]
public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates()
{
- // Setup
+ // Given
string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
string targetFile = $"{nameof(GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryAndValidTargetLocationGiven_ThenFileSuccessFullyMigrates)}.rtd";
@@ -322,9 +302,9 @@
}
[Test]
- public void GivenMigratorAndSupportedFile_WhenDiscontinuedAfterInquiry_ThenFileNotMigrated()
+ public void GivenMigratorAndSupportedFile_WhenDiscontinuedAfterInquiry_ThenFileMigrationCancelledAndLogsMessage()
{
- // Setup
+ // Given
string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "FullTestProject164.rtd");
var mocks = new MockRepository();
@@ -339,7 +319,7 @@
var migrator = new RingtoetsProjectMigrator(inquiryHelper);
string actualTargetFilePath = string.Empty;
- // Call
+ // When
Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath);
// Then
@@ -349,87 +329,110 @@
mocks.VerifyAll();
}
-//
-// [Test]
-// [Apartment(ApartmentState.STA)]
-// public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryButCancelledSaveFileDialog_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(true);
-// mocks.ReplayAll();
-//
-// DialogBoxHandler = (name, wnd) =>
-// {
-// var helper = new SaveFileDialogTester(wnd);
-// helper.ClickCancel();
-// };
-//
-// 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 Migrate_UnsupportedSourceFileVersion_ThenLogsError()
-// {
-// // Setup
-// string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "UnsupportedVersion8.rtd");
-// string targetFile = $"{nameof(Migrate_UnsupportedSourceFileVersion_ThenLogsError)}";
-// string targetFilePath = Path.Combine(TestHelper.GetScratchPadPath(), testDirectory, targetFile);
-//
-// 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 = string.Empty;
-//
-// DialogBoxHandler = (name, wnd) =>
-// {
-// var helper = new SaveFileDialogTester(wnd);
-// helper.SaveFile(targetFilePath);
-// };
-//
-// // When
-// Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath);
-//
-// // Then
-// TestHelper.AssertLogMessages(call, messages =>
-// {
-// string[] msgs = messages.ToArray();
-// Assert.AreEqual(1, msgs.Length);
-// StringAssert.StartsWith(string.Format("Het migreren van het projectbestand '{0}' is mislukt: ", sourceFilePath), msgs[0]);
-// });
-// Assert.IsNull(actualTargetFilePath);
-// }
-//
-// mocks.VerifyAll();
-// }
+
+ [Test]
+ public void GivenMigratorAndSupportedFile_WhenContinuedAfterInquiryButCancelledSaveFileDialog_ThenFileMigrationCancelledAndLogsMessage()
+ {
+ // Given
+ 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(true);
+ inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null)).IgnoreArguments().Return(null);
+ mocks.ReplayAll();
+
+ var migrator = new RingtoetsProjectMigrator(inquiryHelper);
+ string actualTargetFilePath = string.Empty;
+
+ // When
+ 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]
+ public void Migrate_UnsupportedSourceFileVersion_MigrationFailsAndLogsError()
+ {
+ // Setup
+ string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, "UnsupportedVersion8.rtd");
+ string targetFile = $"{nameof(Migrate_UnsupportedSourceFileVersion_MigrationFailsAndLogsError)}";
+ string targetFilePath = Path.Combine(TestHelper.GetScratchPadPath(), testDirectory, targetFile);
+
+ 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 = string.Empty;
+
+ // Call
+ Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath);
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ string[] msgs = messages.ToArray();
+ Assert.AreEqual(1, msgs.Length);
+ StringAssert.StartsWith(string.Format("Het migreren van het projectbestand '{0}' is mislukt: ", sourceFilePath), msgs[0]);
+ });
+ Assert.IsNull(actualTargetFilePath);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Migrate_TargetFileSameAsSourceFile_MigrationFailsAndLogsError()
+ {
+ // Given
+ 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(true);
+ inquiryHelper.Expect(helper => helper.GetTargetFileLocation(null, null)).IgnoreArguments().Return(sourceFilePath);
+ mocks.ReplayAll();
+
+ var migrator = new RingtoetsProjectMigrator(inquiryHelper);
+
+ string actualTargetFilePath = string.Empty;
+
+ // When
+ Action call = () => actualTargetFilePath = migrator.Migrate(sourceFilePath);
+
+ // Then
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ string[] msgs = messages.ToArray();
+ Assert.AreEqual(1, msgs.Length);
+ StringAssert.StartsWith(string.Format("Het migreren van het projectbestand '{0}' is mislukt: ", sourceFilePath), msgs[0]);
+ });
+ Assert.IsNull(actualTargetFilePath);
+
+ mocks.VerifyAll();
+ }
}
}
\ No newline at end of file