Index: Core/Common/test/Core.Common.Gui.Test/Commands/StorageCommandHandlerTest.cs =================================================================== diff -u -r7963bd77ea5540754906c7e994f2687e33a89dde -rb9f76ee42529d5cba29ae9a1cf955af2fb2fb29d --- Core/Common/test/Core.Common.Gui.Test/Commands/StorageCommandHandlerTest.cs (.../StorageCommandHandlerTest.cs) (revision 7963bd77ea5540754906c7e994f2687e33a89dde) +++ Core/Common/test/Core.Common.Gui.Test/Commands/StorageCommandHandlerTest.cs (.../StorageCommandHandlerTest.cs) (revision b9f76ee42529d5cba29ae9a1cf955af2fb2fb29d) @@ -469,8 +469,6 @@ .Return(loadedProject); var projectMigrator = mocks.Stub(); - projectMigrator.Stub(pm => pm.ShouldMigrate(pathToSomeValidFile)).Return(false); - var mainWindowController = mocks.Stub(); var projectOwner = mocks.Stub(); @@ -515,7 +513,6 @@ .Return(loadedProject); var projectMigrator = mocks.Stub(); - projectMigrator.Stub(pm => pm.ShouldMigrate(pathToSomeValidFile)).Return(false); var applicationSelection = mocks.Stub(); applicationSelection.Selection = originalProject; Index: Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs =================================================================== diff -u -r7963bd77ea5540754906c7e994f2687e33a89dde -rb9f76ee42529d5cba29ae9a1cf955af2fb2fb29d --- Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 7963bd77ea5540754906c7e994f2687e33a89dde) +++ Core/Common/test/Core.Common.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision b9f76ee42529d5cba29ae9a1cf955af2fb2fb29d) @@ -510,7 +510,7 @@ { // Setup const string fileName = "SomeFile"; - string testFile = string.Format("{0}.rtd", fileName); + string testFile = $"{fileName}.rtd"; var mocks = new MockRepository(); var projectStore = mocks.Stub(); @@ -551,11 +551,165 @@ [Test] [Apartment(ApartmentState.STA)] + public void Run_LoadingFromOutdatedFileAndMigrationCancelled_LogErrorAndLoadDefaultProjectInstead() + { + // Setup + const string fileName = "SomeFile"; + string testFile = $"{fileName}.rtd"; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + + var projectMigrator = mocks.Stub(); + projectMigrator.Stub(pm => pm.ShouldMigrate(testFile)).Return(true); + projectMigrator.Stub(pm => pm.Migrate(testFile)).Return(null); + + const string expectedProjectName = "Project"; + var project = mocks.Stub(); + project.Name = expectedProjectName; + var projectFactory = mocks.Stub(); + projectFactory.Stub(ph => ph.CreateNewProject()).Return(project); + + mocks.ReplayAll(); + + var fixedSettings = new GuiCoreSettings + { + MainWindowTitle = "
" + }; + + using (var mainWindow = new MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) + { + // Call + Action call = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Openen van bestaand Ringtoetsproject...", + "Het is niet gelukt om het Ringtoetsproject te laden.", + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); + + Assert.IsNull(gui.ProjectFilePath); + var expectedTitle = $"{expectedProjectName} - {fixedSettings.MainWindowTitle} {SettingsHelper.Instance.ApplicationVersion}"; + Assert.AreEqual(expectedTitle, mainWindow.Title); + } + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Run_LoadingFromOutdatedAndShouldMigrateThrowsArgumentException_LogErrorAndLoadDefaultProjectInstead() + { + // Setup + const string fileName = "SomeFile"; + string testFile = $"{fileName}.rtd"; + + const string expectedErrorMessage = "You shall not migrate!"; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + + var projectMigrator = mocks.Stub(); + projectMigrator.Stub(pm => pm.ShouldMigrate(testFile)) + .Throw(new ArgumentException(expectedErrorMessage)); + + const string expectedProjectName = "Project"; + var project = mocks.Stub(); + project.Name = expectedProjectName; + var projectFactory = mocks.Stub(); + projectFactory.Stub(ph => ph.CreateNewProject()).Return(project); + + mocks.ReplayAll(); + + var fixedSettings = new GuiCoreSettings + { + MainWindowTitle = "
" + }; + + using (var mainWindow = new MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) + { + // Call + Action call = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Openen van bestaand Ringtoetsproject...", + expectedErrorMessage, + "Het is niet gelukt om het Ringtoetsproject te laden.", + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); + + Assert.IsNull(gui.ProjectFilePath); + var expectedTitle = $"{expectedProjectName} - {fixedSettings.MainWindowTitle} {SettingsHelper.Instance.ApplicationVersion}"; + Assert.AreEqual(expectedTitle, mainWindow.Title); + } + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Run_LoadingFromOutdatedAndMigrateThrowsArgumentException_LogErrorAndLoadDefaultProjectInstead() + { + // Setup + const string fileName = "SomeFile"; + string testFile = $"{fileName}.rtd"; + + const string expectedErrorMessage = "You shall not migrate!"; + + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + + var projectMigrator = mocks.Stub(); + projectMigrator.Stub(pm => pm.ShouldMigrate(testFile)).Return(true); + projectMigrator.Stub(pm => pm.Migrate(testFile)) + .Throw(new ArgumentException(expectedErrorMessage)); + + const string expectedProjectName = "Project"; + var project = mocks.Stub(); + project.Name = expectedProjectName; + var projectFactory = mocks.Stub(); + projectFactory.Stub(ph => ph.CreateNewProject()).Return(project); + + mocks.ReplayAll(); + + var fixedSettings = new GuiCoreSettings + { + MainWindowTitle = "
" + }; + + using (var mainWindow = new MainWindow()) + using (var gui = new GuiCore(mainWindow, projectStore, projectMigrator, projectFactory, fixedSettings)) + { + // Call + Action call = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Openen van bestaand Ringtoetsproject...", + expectedErrorMessage, + "Het is niet gelukt om het Ringtoetsproject te laden.", + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); + + Assert.IsNull(gui.ProjectFilePath); + var expectedTitle = $"{expectedProjectName} - {fixedSettings.MainWindowTitle} {SettingsHelper.Instance.ApplicationVersion}"; + Assert.AreEqual(expectedTitle, mainWindow.Title); + } + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] public void Run_LoadingFromFileThrowsStorageException_LogErrorAndLoadDefaultProjectInstead() { // Setup const string fileName = "SomeFile"; - string testFile = string.Format("{0}.rtd", fileName); + string testFile = $"{fileName}.rtd"; const string storageExceptionText = "";