Index: Application/Riskeer/src/Application.Riskeer/App.xaml.cs =================================================================== diff -u -r77da36c3f350a8b9ffe4c419ce00843569271f24 -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Application/Riskeer/src/Application.Riskeer/App.xaml.cs (.../App.xaml.cs) (revision 77da36c3f350a8b9ffe4c419ce00843569271f24) +++ Application/Riskeer/src/Application.Riskeer/App.xaml.cs (.../App.xaml.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -129,7 +129,7 @@ SupportEmailAddressUrl = "https://www.helpdeskwater.nl/onderwerpen/applicaties-modellen/applicaties-per/omgevings/omgevings/riskeer/contact/vraag-ringtoets/", SupportPhoneNumberUrl = "https://www.helpdeskwater.nl/secundaire-navigatie/contact/", ManualFilePath = "Gebruikershandleiding Riskeer 21.1.1.pdf", - OnNewProjectCreatedAction = (g, project) => new AssessmentSectionFromFileHandler(g.MainWindow, g.DocumentViewController).AddAssessmentSectionFromFile((RiskeerProject) project) + OnNewProjectCreatedAction = (g, project) => new AssessmentSectionFromFileHandler(g.ActiveParentWindow, g.DocumentViewController).AddAssessmentSectionFromFile((RiskeerProject) project) }; var mainWindow = new MainWindow(); Index: Core/Gui/src/Core.Gui/Commands/StorageCommandHandler.cs =================================================================== diff -u -rc15e5afd6206771891eb4295392897b9772a84be -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/src/Core.Gui/Commands/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision c15e5afd6206771891eb4295392897b9772a84be) +++ Core/Gui/src/Core.Gui/Commands/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -41,32 +41,32 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(StorageCommandHandler)); - private readonly IWin32Window dialogParent; + private readonly IMainWindowController mainWindowController; private readonly IProjectOwner projectOwner; private readonly IStoreProject projectPersister; private readonly IProjectFactory projectFactory; private readonly IMigrateProject projectMigrator; private readonly IInquiryHelper inquiryHelper; /// - /// Initializes a new instance of the class. + /// Creates a new instance of . /// /// Class responsible to storing and loading the application project. /// Class responsible for the migration of the application projects. /// The factory to use when creating new projects. /// The class owning the application project. /// The object facilitating user interaction. - /// Controller for UI. + /// The object owning the parent Controller for UI. public StorageCommandHandler(IStoreProject projectStorage, IMigrateProject projectMigrator, IProjectFactory projectFactory, IProjectOwner projectOwner, - IInquiryHelper inquiryHelper, IWin32Window dialogParent) + IInquiryHelper inquiryHelper, IMainWindowController mainWindowController) { - this.dialogParent = dialogParent; - this.projectOwner = projectOwner; - this.inquiryHelper = inquiryHelper; projectPersister = projectStorage; this.projectMigrator = projectMigrator; this.projectFactory = projectFactory; + this.projectOwner = projectOwner; + this.inquiryHelper = inquiryHelper; + this.mainWindowController = mainWindowController; } public bool HandleUnsavedChanges() @@ -123,7 +123,7 @@ Title = Resources.OpenFileDialog_Title }) { - if (openFileDialog.ShowDialog(dialogParent) != DialogResult.Cancel && HandleUnsavedChanges()) + if (openFileDialog.ShowDialog(mainWindowController.ActiveParentWindow) != DialogResult.Cancel && HandleUnsavedChanges()) { return openFileDialog.FileName; } @@ -157,7 +157,7 @@ } var activity = new SaveProjectActivity(project, filePath, false, projectPersister, projectOwner); - ActivityProgressDialogRunner.Run(dialogParent, activity); + ActivityProgressDialogRunner.Run(mainWindowController.ActiveParentWindow, activity); return activity.State == ActivityState.Finished; } @@ -173,7 +173,7 @@ } var activity = new SaveProjectActivity(project, filePath, true, projectPersister, projectOwner); - ActivityProgressDialogRunner.Run(dialogParent, activity); + ActivityProgressDialogRunner.Run(mainWindowController.ActiveParentWindow, activity); return activity.State == ActivityState.Finished; } @@ -267,7 +267,7 @@ ProjectStorage = projectPersister }; var activity = new OpenProjectActivity(openProjectProperties, migrationProperties); - ActivityProgressDialogRunner.Run(dialogParent, activity); + ActivityProgressDialogRunner.Run(mainWindowController.ActiveParentWindow, activity); return activity.State == ActivityState.Finished; } Index: Core/Gui/src/Core.Gui/Forms/StartScreen/StartScreen.xaml.cs =================================================================== diff -u -r90e6ceb054e3c6826246e33aa9fe19f7aeedc444 -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/src/Core.Gui/Forms/StartScreen/StartScreen.xaml.cs (.../StartScreen.xaml.cs) (revision 90e6ceb054e3c6826246e33aa9fe19f7aeedc444) +++ Core/Gui/src/Core.Gui/Forms/StartScreen/StartScreen.xaml.cs (.../StartScreen.xaml.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -20,16 +20,24 @@ // All rights reserved. using System; +using System.Windows.Interop; using MahApps.Metro.Controls; +using IWin32Window = System.Windows.Forms.IWin32Window; namespace Core.Gui.Forms.StartScreen { /// /// Interaction logic for . /// - public partial class StartScreen : MetroWindow + public partial class StartScreen : MetroWindow, IWin32Window { /// + /// Class to help with hybrid winforms - WPF applications. Provides UI handle to + /// ensure common UI functionality such as maximizing works as expected. + /// + private readonly WindowInteropHelper windowInteropHelper; + + /// /// Creates a new instance of . /// /// The view model of the . @@ -44,7 +52,11 @@ InitializeComponent(); + windowInteropHelper = new WindowInteropHelper(this); + DataContext = viewModel; } + + public IntPtr Handle => windowInteropHelper.Handle; } } \ No newline at end of file Index: Core/Gui/src/Core.Gui/GuiCore.cs =================================================================== diff -u -r9d55d60780ac3dbab99349e06e14d1e7e2596b21 -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/src/Core.Gui/GuiCore.cs (.../GuiCore.cs) (revision 9d55d60780ac3dbab99349e06e14d1e7e2596b21) +++ Core/Gui/src/Core.Gui/GuiCore.cs (.../GuiCore.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -27,7 +27,7 @@ using System.Globalization; using System.Linq; using System.Reflection; -using System.Windows; +using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Storage; @@ -51,6 +51,7 @@ using log4net; using log4net.Appender; using log4net.Repository.Hierarchy; +using Application = System.Windows.Application; using WindowsApplication = System.Windows.Forms.Application; namespace Core.Gui @@ -71,7 +72,6 @@ private bool isExiting; private StartScreen startScreen; - private bool startScreenShown; private bool creatingNewProject; /// @@ -134,7 +134,7 @@ viewCommandHandler = new ViewCommandHandler(this, this, this); StorageCommands = new StorageCommandHandler(projectStore, projectMigrator, projectFactory, - this, dialogBasedInquiryHelper, MainWindow); + this, dialogBasedInquiryHelper, this); importCommandHandler = new GuiImportHandler(MainWindow, Plugins.SelectMany(p => p.GetImportInfos()) .Concat(MapImportInfoFactory.Create()), @@ -345,7 +345,7 @@ startScreen.Closed += OnStartScreenClosed; startScreen.Show(); - startScreenShown = true; + ActiveParentWindow = startScreen; } private void OnNewProject() @@ -372,8 +372,9 @@ { startScreen.Closed -= OnStartScreenClosed; startScreen.Close(); - startScreenShown = false; + ActiveParentWindow = mainWindow; + mainWindow.Show(); } @@ -406,7 +407,7 @@ UpdateProjectData(); mainWindow.UpdateProjectExplorer(); - if (startScreenShown) + if (ActiveParentWindow is StartScreen) { ShowMainWindow(); } @@ -788,6 +789,8 @@ } } + public IWin32Window ActiveParentWindow { get; private set; } + private void UpdateProjectData() { mainWindow.Title = string.Format(CultureInfo.CurrentCulture, Index: Core/Gui/src/Core.Gui/IMainWindowController.cs =================================================================== diff -u -r434415295de74c310ce6d3cdd0100c28838cf9ea -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/src/Core.Gui/IMainWindowController.cs (.../IMainWindowController.cs) (revision 434415295de74c310ce6d3cdd0100c28838cf9ea) +++ Core/Gui/src/Core.Gui/IMainWindowController.cs (.../IMainWindowController.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Windows.Forms; using Core.Gui.Forms.MainWindow; namespace Core.Gui @@ -33,5 +34,10 @@ /// Gets main window of the graphical user interface. /// IMainWindow MainWindow { get; } + + /// + /// Gets the active parent window. + /// + IWin32Window ActiveParentWindow { get; } } } \ No newline at end of file Index: Core/Gui/test/Core.Gui.Test/Commands/StorageCommandHandlerTest.cs =================================================================== diff -u -rc15e5afd6206771891eb4295392897b9772a84be -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/test/Core.Gui.Test/Commands/StorageCommandHandlerTest.cs (.../StorageCommandHandlerTest.cs) (revision c15e5afd6206771891eb4295392897b9772a84be) +++ Core/Gui/test/Core.Gui.Test/Commands/StorageCommandHandlerTest.cs (.../StorageCommandHandlerTest.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -55,12 +55,13 @@ var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(oldProject); projectOwner.Stub(po => po.ProjectFilePath).Return(savedProjectPath); + var projectFactory = mocks.Stub(); projectFactory.Stub(pf => pf.CreateNewProject()).Return(newProject); projectOwner.Expect(po => po.SetProject(newProject, null)); var inquiryHelper = mocks.Stub(); - var mainWindowController = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); @@ -73,15 +74,15 @@ mainWindowController); // Call - Action call = () => storageCommandHandler.CreateNewProject(); + void Call() => storageCommandHandler.CreateNewProject(); // Assert Tuple[] expectedMessages = { Tuple.Create("Nieuw project aanmaken is gestart.", LogLevelConstant.Info), Tuple.Create("Nieuw project aanmaken is gelukt.", LogLevelConstant.Info) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 2); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 2); mocks.VerifyAll(); } @@ -106,12 +107,14 @@ var projectMigrator = mocks.Stub(); - var mainWindowController = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); projectOwner.Stub(po => po.ProjectFilePath).Return(someValidFilePath); var inquiryHelper = mocks.Stub(); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -129,7 +132,7 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.SaveProject(); + void Call() => result = storageCommandHandler.SaveProject(); // Assert Tuple[] expectedMessages = @@ -138,7 +141,7 @@ Tuple.Create(exceptionMessage, LogLevelConstant.Error), Tuple.Create("Opslaan van bestaand project is mislukt.", LogLevelConstant.Error) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 3); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 3); Assert.IsFalse(result); } @@ -162,12 +165,14 @@ var projectMigrator = mocks.Stub(); - var mainWindowController = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); projectOwner.Stub(po => po.ProjectFilePath).Return(someValidFilePath); var inquiryHelper = mocks.Stub(); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -185,10 +190,10 @@ // Call var result = false; - Action call = () => result = storageCommandHandler.SaveProject(); + void Call() => result = storageCommandHandler.SaveProject(); // Assert - TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create("Opslaan van bestaand project is gelukt.", LogLevelConstant.Info)); + TestHelper.AssertLogMessageWithLevelIsGenerated(Call, Tuple.Create("Opslaan van bestaand project is gelukt.", LogLevelConstant.Info)); Assert.IsTrue(result); } @@ -200,25 +205,25 @@ { // Setup const string fileName = "newProject"; - string pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; - string pathToMigratedFile = $"C://folder/directory/{fileName}-newerVersion.rtd"; + var pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; + var pathToMigratedFile = $"C://folder/directory/{fileName}-newerVersion.rtd"; var loadedProject = mocks.Stub(); var projectFactory = mocks.Stub(); var projectStorage = mocks.Stub(); projectStorage.Stub(ps => ps.LoadProject(pathToMigratedFile)) .Return(loadedProject); + var mainWindowController = mocks.Stub(); var projectMigrator = mocks.StrictMock(); using (mocks.Ordered()) { projectMigrator.Expect(pm => pm.ShouldMigrate(pathToSomeValidFile)).Return(MigrationRequired.Yes); projectMigrator.Expect(pm => pm.DetermineMigrationLocation(pathToSomeValidFile)).Return(pathToMigratedFile); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); projectMigrator.Expect(pm => pm.Migrate(pathToSomeValidFile, pathToMigratedFile)).Return(true); } - var mainWindowController = mocks.Stub(); - var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.SetProject(loadedProject, pathToMigratedFile)); @@ -240,15 +245,15 @@ // Call var result = false; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert Tuple[] expectedMessages = { Tuple.Create("Openen van project is gestart.", LogLevelConstant.Info), Tuple.Create("Openen van project is gelukt.", LogLevelConstant.Info) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 2); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 2); Assert.IsTrue(result); mocks.VerifyAll(); @@ -259,7 +264,7 @@ { // Setup const string fileName = "newProject"; - string pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; + var pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; var projectStorage = mocks.StrictMock(); @@ -276,8 +281,8 @@ projectOwner.Expect(po => po.SetProject(project, null)) .Repeat.Never(); - var mainWindowController = mocks.Stub(); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -301,7 +306,7 @@ { // Setup const string fileName = "newProject"; - string pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; + var pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; var projectStorage = mocks.StrictMock(); @@ -322,8 +327,8 @@ projectOwner.Expect(po => po.SetProject(project, null)) .Repeat.Never(); - var mainWindowController = mocks.Stub(); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -363,8 +368,8 @@ projectOwner.Stub(po => po.Project).Return(project); projectOwner.Stub(po => po.SetProject(project, null)); - var mainWindowController = mocks.Stub(); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -377,10 +382,10 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert - TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(errorMessage, LogLevelConstant.Error), 1); + TestHelper.AssertLogMessageWithLevelIsGenerated(Call, Tuple.Create(errorMessage, LogLevelConstant.Error), 1); Assert.IsFalse(result); mocks.VerifyAll(); } @@ -410,8 +415,8 @@ projectOwner.Stub(po => po.Project).Return(project); projectOwner.Expect(po => po.SetProject(project, null)); - var mainWindowController = mocks.Stub(); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -424,10 +429,10 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert - TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(errorMessage, LogLevelConstant.Error), 1); + TestHelper.AssertLogMessageWithLevelIsGenerated(Call, Tuple.Create(errorMessage, LogLevelConstant.Error), 1); Assert.IsFalse(result); mocks.VerifyAll(); } @@ -438,16 +443,18 @@ // Setup const string errorMessage = "I am an error message."; const string fileName = "newProject"; - string pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; - string pathToMigratedFile = $"C://folder/directory/{fileName}-newerVersion.rtd"; + var pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; + var pathToMigratedFile = $"C://folder/directory/{fileName}-newerVersion.rtd"; var projectStorage = mocks.StrictMock(); + var mainWindowController = mocks.Stub(); var projectMigrator = mocks.StrictMock(); using (mocks.Ordered()) { projectMigrator.Expect(pm => pm.ShouldMigrate(pathToSomeValidFile)).Return(MigrationRequired.Yes); projectMigrator.Expect(pm => pm.DetermineMigrationLocation(pathToSomeValidFile)).Return(pathToMigratedFile); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); projectMigrator.Expect(pm => pm.Migrate(pathToSomeValidFile, pathToMigratedFile)) .Throw(new ArgumentException(errorMessage)); } @@ -460,7 +467,6 @@ projectOwner.Stub(po => po.Project).Return(project); projectOwner.Expect(po => po.SetProject(project, null)); - var mainWindowController = mocks.Stub(); var inquiryHelper = mocks.Stub(); mocks.ReplayAll(); @@ -479,10 +485,10 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert - TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(errorMessage, LogLevelConstant.Error), 3); + TestHelper.AssertLogMessageWithLevelIsGenerated(Call, Tuple.Create(errorMessage, LogLevelConstant.Error), 3); Assert.IsFalse(result); mocks.VerifyAll(); } @@ -498,15 +504,20 @@ var projectStorage = mocks.Stub(); projectStorage.Stub(ps => ps.LoadProject(pathToSomeInvalidFile)) .Throw(new StorageException(goodErrorMessageText, new Exception("H@X!"))); + var projectMigrator = mocks.Stub(); projectMigrator.Stub(m => m.ShouldMigrate(pathToSomeInvalidFile)).Return(MigrationRequired.No); + var projectFactory = mocks.Stub(); projectFactory.Stub(pf => pf.CreateNewProject()).Return(project); - var mainWindowController = mocks.Stub(); + var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); projectOwner.Stub(po => po.SetProject(project, null)); + var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -524,7 +535,7 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeInvalidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeInvalidFile); // Assert Tuple[] expectedMessages = @@ -533,7 +544,7 @@ Tuple.Create(goodErrorMessageText, LogLevelConstant.Error), Tuple.Create("Openen van project is mislukt.", LogLevelConstant.Error) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 3); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 3); Assert.IsFalse(result); mocks.VerifyAll(); @@ -546,7 +557,6 @@ const string pathToSomeInvalidFile = ""; var project = mocks.Stub(); - var mainWindowController = mocks.Stub(); var projectStorage = mocks.Stub(); projectStorage.Stub(ps => ps.LoadProject(pathToSomeInvalidFile)) .Return(null); @@ -561,6 +571,8 @@ projectOwner.Stub(po => po.SetProject(project, null)); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -578,15 +590,15 @@ // Call var result = true; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeInvalidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeInvalidFile); // Assert Tuple[] expectedMessages = { Tuple.Create("Openen van project is gestart.", LogLevelConstant.Info), Tuple.Create("Openen van project is mislukt.", LogLevelConstant.Error) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 2); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 2); Assert.IsFalse(result); mocks.VerifyAll(); @@ -597,7 +609,7 @@ { // Setup const string fileName = "newProject"; - string pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; + var pathToSomeValidFile = $"C://folder/directory/{fileName}.rtd"; var loadedProject = mocks.Stub(); var projectFactory = mocks.Stub(); @@ -607,12 +619,14 @@ var projectMigrator = mocks.Stub(); projectMigrator.Stub(m => m.ShouldMigrate(pathToSomeValidFile)).Return(MigrationRequired.No); - var mainWindowController = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.SetProject(loadedProject, pathToSomeValidFile)); var inquiryHelper = mocks.Stub(); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -630,15 +644,15 @@ // Call var result = false; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert Tuple[] expectedMessages = { Tuple.Create("Openen van project is gestart.", LogLevelConstant.Info), Tuple.Create("Openen van project is gelukt.", LogLevelConstant.Info) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 2); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 2); Assert.IsTrue(result); mocks.VerifyAll(); @@ -664,14 +678,15 @@ var applicationSelection = mocks.Stub(); applicationSelection.Selection = originalProject; - var mainWindowController = mocks.Stub(); - var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(originalProject); projectOwner.Stub(po => po.ProjectFilePath).Return(""); projectOwner.Stub(po => po.SetProject(loadedProject, pathToSomeValidFile)); var inquiryHelper = mocks.Stub(); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -689,15 +704,15 @@ // Call var result = false; - Action call = () => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); + void Call() => result = storageCommandHandler.OpenExistingProject(pathToSomeValidFile); // Assert Tuple[] expectedMessages = { Tuple.Create("Openen van project is gestart.", LogLevelConstant.Info), Tuple.Create("Openen van project is gelukt.", LogLevelConstant.Info) }; - TestHelper.AssertLogMessagesWithLevelAreGenerated(call, expectedMessages, 2); + TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, expectedMessages, 2); Assert.IsTrue(result); mocks.VerifyAll(); @@ -708,17 +723,17 @@ public void GetExistingProjectFilePath_FilePathSelectedAndOkClicked_ReturnsSelectedFilePath() { // Setup - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); var projectStorage = mocks.Stub(); var projectMigrator = mocks.Stub(); - var projectOwner = mocks.Stub(); + var projectFactory = mocks.Stub(); + var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(null); projectStorage.Stub(ps => ps.HasStagedProjectChanges(null)).IgnoreArguments().Return(false); projectStorage.Stub(ps => ps.OpenProjectFileFilter).Return(string.Empty); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); string projectPath = TestHelper.GetScratchPadPath( @@ -752,12 +767,12 @@ public void GetExistingProjectFilePath_NoFilePathSelectedAndCancelClicked_ReturnsFilePathNull() { // Setup - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); var projectStorage = mocks.Stub(); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -785,13 +800,13 @@ public void HandleUnsavedChanges_NoProjectSet_ReturnsTrue() { // Setup - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); var projectStorage = mocks.Stub(); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(null); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -810,20 +825,20 @@ mocks.VerifyAll(); } - + [Test] public void HandleUnsavedChanges_ProjectSetNoChange_ReturnsTrue() { // Setup - var mainWindowController = mocks.Stub(); var project = mocks.Stub(); - var projectFactory = mocks.Stub(); var projectStorage = mocks.Stub(); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); projectOwner.Stub(po => po.ProjectFilePath).Return(""); var inquiryHelper = mocks.Stub(); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -848,9 +863,6 @@ public void HandleUnsavedChanges_ProjectSetWithChangeCancelPressed_ReturnsFalse() { // Setup - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); - var project = mocks.Stub(); const string projectName = "Project"; project.Name = projectName; @@ -862,6 +874,7 @@ projectStorage.Expect(ps => ps.UnstageProject()); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); @@ -871,6 +884,7 @@ inquiryHelper.Expect(h => h.InquirePerformOptionalStep("Project afsluiten", $"Sla wijzigingen in het project op: {projectName}?")) .Return(OptionalStepResult.Cancel); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -895,9 +909,6 @@ public void HandleUnsavedChangesProjectSetWithChangeNoPressed_ReturnsTrue() { // Setup - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); - var project = mocks.Stub(); const string projectName = "Project"; project.Name = projectName; @@ -909,6 +920,7 @@ projectStorage.Expect(ps => ps.UnstageProject()); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); @@ -918,6 +930,7 @@ inquiryHelper.Expect(h => h.InquirePerformOptionalStep("Project afsluiten", $"Sla wijzigingen in het project op: {projectName}?")) .Return(OptionalStepResult.SkipOptionalStep); + var mainWindowController = mocks.Stub(); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -946,9 +959,6 @@ string someValidFilePath = TestHelper.GetScratchPadPath(nameof(HandleUnsavedChanges_ProjectSetWithChangeYesPressed_ReturnsTrue)); using (new FileDisposeHelper(someValidFilePath)) { - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); - var project = mocks.Stub(); project.Name = projectName; @@ -960,6 +970,7 @@ projectStorage.Expect(p => p.SaveProjectAs(someValidFilePath)); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); @@ -969,6 +980,9 @@ inquiryHelper.Expect(h => h.InquirePerformOptionalStep("Project afsluiten", $"Sla wijzigingen in het project op: {projectName}?")) .Return(OptionalStepResult.PerformOptionalStep); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( @@ -1003,9 +1017,6 @@ const string projectName = "Project"; string someValidFilePath = TestHelper.GetScratchPadPath(nameof(HandleUnsavedChanges_ProjectSetWithChangeYesFileDoesNotExist_ReturnsTrue)); - var mainWindowController = mocks.Stub(); - var projectFactory = mocks.Stub(); - var project = mocks.Stub(); project.Name = projectName; @@ -1018,6 +1029,7 @@ projectStorage.Expect(p => p.SaveProjectAs(someValidFilePath)); var projectMigrator = mocks.Stub(); + var projectFactory = mocks.Stub(); var projectOwner = mocks.Stub(); projectOwner.Stub(po => po.Project).Return(project); @@ -1030,6 +1042,9 @@ .Return(OptionalStepResult.PerformOptionalStep); inquiryHelper.Expect(h => h.GetTargetFileLocation(fileFilter, projectName)) .Return(someValidFilePath); + + var mainWindowController = mocks.Stub(); + mainWindowController.Stub(mwc => mwc.ActiveParentWindow).Return(mocks.Stub()); mocks.ReplayAll(); var storageCommandHandler = new StorageCommandHandler( Index: Core/Gui/test/Core.Gui.Test/Forms/StartScreen/StartScreenTest.cs =================================================================== diff -u -r90e6ceb054e3c6826246e33aa9fe19f7aeedc444 -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/test/Core.Gui.Test/Forms/StartScreen/StartScreenTest.cs (.../StartScreenTest.cs) (revision 90e6ceb054e3c6826246e33aa9fe19f7aeedc444) +++ Core/Gui/test/Core.Gui.Test/Forms/StartScreen/StartScreenTest.cs (.../StartScreenTest.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -21,6 +21,7 @@ using System; using System.Threading; +using System.Windows.Forms; using Core.Gui.Forms.StartScreen; using MahApps.Metro.Controls; using NUnit.Framework; @@ -53,6 +54,7 @@ // Assert Assert.IsInstanceOf(startScreen); + Assert.IsInstanceOf(startScreen); Assert.AreSame(viewModel, startScreen.DataContext); } } Index: Core/Gui/test/Core.Gui.Test/GuiCoreTest.cs =================================================================== diff -u -r4cd36cfdb9ddea498762088f113df2277ca62333 -r59a9a7de8b9239192db7ecf50bff988240c70b74 --- Core/Gui/test/Core.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 4cd36cfdb9ddea498762088f113df2277ca62333) +++ Core/Gui/test/Core.Gui.Test/GuiCoreTest.cs (.../GuiCoreTest.cs) (revision 59a9a7de8b9239192db7ecf50bff988240c70b74) @@ -40,6 +40,7 @@ using Core.Gui.Forms.MessageWindow; using Core.Gui.Forms.ProjectExplorer; using Core.Gui.Forms.PropertyGridView; +using Core.Gui.Forms.StartScreen; using Core.Gui.Forms.ViewHost; using Core.Gui.Plugin; using Core.Gui.Settings; @@ -599,7 +600,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void Run_WithFile_LoadProjectFromFile() + public void Run_WithFile_LoadProjectFromFileAndShowMainWindow() { // Setup const string fileName = "SomeFile"; @@ -644,6 +645,8 @@ Assert.AreSame(project, gui.Project); Assert.AreEqual(fileName, gui.Project.Name); + Assert.IsInstanceOf(gui.ActiveParentWindow); + var expectedTitle = $"{fileName} - {fixedSettings.ApplicationName} {SettingsHelper.Instance.ApplicationVersion}"; Assert.AreEqual(expectedTitle, mainWindow.Title); Assert.AreSame(gui.Project, mainWindow.ProjectExplorer.Data); @@ -654,7 +657,7 @@ [Test] [Apartment(ApartmentState.STA)] - public void Run_LoadingFromOutdatedFileAndMigrationCancelled_NoProjectSetAndMainWindowNotShown() + public void Run_LoadingFromOutdatedFileAndMigrationCancelled_NoProjectSetAndStartScreenShown() { // Setup const string fileName = "SomeFile"; @@ -673,16 +676,13 @@ { gui.Plugins.Add(new TestPlugin()); - var mainWindowShownCounter = 0; - mainWindow.Loaded += (sender, args) => mainWindowShownCounter++; - // Call gui.Run(testFile); // Assert Assert.IsNull(gui.ProjectFilePath); Assert.IsNull(gui.Project); - Assert.AreEqual(0, mainWindowShownCounter); + Assert.IsInstanceOf(gui.ActiveParentWindow); } mocks.VerifyAll(); @@ -853,7 +853,7 @@ [TestCase(" ")] [TestCase(null)] [Apartment(ApartmentState.STA)] - public void Run_WithoutFile_NoProjectSetAndMainWindowNotShown(string path) + public void Run_WithoutFile_NoProjectSetAndStartScreenShown(string path) { // Setup var mocks = new MockRepository(); @@ -869,16 +869,13 @@ { gui.Plugins.Add(new TestPlugin()); - var mainWindowShownCounter = 0; - mainWindow.Loaded += (sender, args) => mainWindowShownCounter++; - // Call gui.Run(path); // Assert Assert.IsNull(gui.ProjectFilePath); Assert.IsNull(gui.Project); - Assert.AreEqual(0, mainWindowShownCounter); + Assert.IsInstanceOf(gui.ActiveParentWindow); } mocks.VerifyAll();