Index: Core/Common/test/Core.Common.Gui.Test/Forms/MessageWindow/MessageWindowLogAppenderTest.cs =================================================================== diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Core/Common/test/Core.Common.Gui.Test/Forms/MessageWindow/MessageWindowLogAppenderTest.cs (.../MessageWindowLogAppenderTest.cs) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5) +++ Core/Common/test/Core.Common.Gui.Test/Forms/MessageWindow/MessageWindowLogAppenderTest.cs (.../MessageWindowLogAppenderTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1,6 +1,8 @@ using System; using System.Globalization; using Core.Common.Gui.Forms.MessageWindow; +using Core.Common.Gui.TestUtil; +using Core.Common.TestUtil; using log4net.Core; using log4net.Util; using NUnit.Framework; @@ -43,16 +45,16 @@ } [Test] - [TestCase(LogLevel.Off)] - [TestCase(LogLevel.Fatal)] - [TestCase(LogLevel.Error)] - [TestCase(LogLevel.Warn)] - [TestCase(LogLevel.Info)] - [TestCase(LogLevel.Debug)] - public void DoAppend_AppenderEnabled_ForwardAllMessagesToMessageWindow(LogLevel logLevel) + [TestCase(LogLevelConstant.Off)] + [TestCase(LogLevelConstant.Fatal)] + [TestCase(LogLevelConstant.Error)] + [TestCase(LogLevelConstant.Warn)] + [TestCase(LogLevelConstant.Info)] + [TestCase(LogLevelConstant.Debug)] + public void DoAppend_AppenderEnabled_ForwardAllMessagesToMessageWindow(LogLevelConstant logLevel) { // Setup - Level level = CreateLog4NetLevel(logLevel); + Level level = logLevel.ToLog4NetLevel(); var dataTime = DateTime.Now; const string message = ""; @@ -92,7 +94,7 @@ const string expectedText = "Gestart in 1,20 seconden."; - Level level = CreateLog4NetLevel(LogLevel.Warn); + Level level = LogLevelConstant.Warn.ToLog4NetLevel(); var dataTime = DateTime.Now; var logEvent = new LoggingEvent(null, null, "", Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, messageText, formatArgument), @@ -126,7 +128,7 @@ const string messageText = "Gestart in {5:f2} seconden."; const double formatArgument = 1.2; - Level level = CreateLog4NetLevel(LogLevel.Warn); + Level level = LogLevelConstant.Warn.ToLog4NetLevel(); var dataTime = DateTime.Now; var logEvent = new LoggingEvent(null, null, "", Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, messageText, formatArgument), @@ -159,7 +161,7 @@ // Setup const string messageText = "Gestart in {5:f2} seconden."; - Level level = CreateLog4NetLevel(LogLevel.Warn); + Level level = LogLevelConstant.Warn.ToLog4NetLevel(); var dataTime = DateTime.Now; var logEvent = new LoggingEvent(null, null, "", Level.Warn, new SystemStringFormat(CultureInfo.InvariantCulture, messageText, null), @@ -194,7 +196,7 @@ messageText, Environment.NewLine, "Controleer logbestand voor meer informatie (\"Bestand\"->\"Help\"->\"Log tonen\")."); var exception = new Exception(); - Level level = CreateLog4NetLevel(LogLevel.Error); + Level level = LogLevelConstant.Error.ToLog4NetLevel(); var dataTime = DateTime.Now; var logEvent = new LoggingEvent(null, null, "", Level.Error, messageText, exception); @@ -220,16 +222,16 @@ } [Test] - [TestCase(LogLevel.Off)] - [TestCase(LogLevel.Fatal)] - [TestCase(LogLevel.Error)] - [TestCase(LogLevel.Warn)] - [TestCase(LogLevel.Info)] - [TestCase(LogLevel.Debug)] - public void DoAppend_AppenderDisabled_MessagesNotForwardedToMessageWindow(LogLevel logLevel) + [TestCase(LogLevelConstant.Off)] + [TestCase(LogLevelConstant.Fatal)] + [TestCase(LogLevelConstant.Error)] + [TestCase(LogLevelConstant.Warn)] + [TestCase(LogLevelConstant.Info)] + [TestCase(LogLevelConstant.Debug)] + public void DoAppend_AppenderDisabled_MessagesNotForwardedToMessageWindow(LogLevelConstant logLevel) { // Setup - Level level = CreateLog4NetLevel(logLevel); + Level level = logLevel.ToLog4NetLevel(); var dataTime = DateTime.Now; const string message = ""; @@ -259,16 +261,16 @@ } [Test] - [TestCase(LogLevel.Off)] - [TestCase(LogLevel.Fatal)] - [TestCase(LogLevel.Error)] - [TestCase(LogLevel.Warn)] - [TestCase(LogLevel.Info)] - [TestCase(LogLevel.Debug)] - public void Enabled_FromFalseToTrue_ForwardAllCachedMessagesToMessageWindow(LogLevel logLevel) + [TestCase(LogLevelConstant.Off)] + [TestCase(LogLevelConstant.Fatal)] + [TestCase(LogLevelConstant.Error)] + [TestCase(LogLevelConstant.Warn)] + [TestCase(LogLevelConstant.Info)] + [TestCase(LogLevelConstant.Debug)] + public void Enabled_FromFalseToTrue_ForwardAllCachedMessagesToMessageWindow(LogLevelConstant logLevel) { // Setup - Level level = CreateLog4NetLevel(logLevel); + Level level = logLevel.ToLog4NetLevel(); var dataTime = DateTime.Today; const string message = ""; @@ -300,16 +302,16 @@ } [Test] - [TestCase(LogLevel.Off)] - [TestCase(LogLevel.Fatal)] - [TestCase(LogLevel.Error)] - [TestCase(LogLevel.Warn)] - [TestCase(LogLevel.Info)] - [TestCase(LogLevel.Debug)] - public void MessageWindow_FromNullToProperInstance_ForwardAllCachedMessagesToMessageWindow(LogLevel logLevel) + [TestCase(LogLevelConstant.Off)] + [TestCase(LogLevelConstant.Fatal)] + [TestCase(LogLevelConstant.Error)] + [TestCase(LogLevelConstant.Warn)] + [TestCase(LogLevelConstant.Info)] + [TestCase(LogLevelConstant.Debug)] + public void MessageWindow_FromNullToProperInstance_ForwardAllCachedMessagesToMessageWindow(LogLevelConstant logLevel) { // Setup - Level level = CreateLog4NetLevel(logLevel); + Level level = logLevel.ToLog4NetLevel(); var dataTime = DateTime.Today; const string message = ""; @@ -338,36 +340,5 @@ // Assert mocks.VerifyAll(); } - - private Level CreateLog4NetLevel(LogLevel level) - { - switch (level) - { - case LogLevel.Off: - return Level.Off; - case LogLevel.Fatal: - return Level.Fatal; - case LogLevel.Error: - return Level.Error; - case LogLevel.Warn: - return Level.Warn; - case LogLevel.Info: - return Level.Info; - case LogLevel.Debug: - return Level.Debug; - default: - throw new NotImplementedException(); - } - } - - public enum LogLevel - { - Off, - Fatal, - Error, - Warn, - Info, - Debug - } } } \ No newline at end of file Index: Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj =================================================================== diff -u -r2ae1c9433c3c28b32105b9778b682b5e512a0f00 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision 2ae1c9433c3c28b32105b9778b682b5e512a0f00) +++ Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -88,6 +88,7 @@ + True Index: Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs =================================================================== diff -u --- Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs (revision 0) +++ Core/Common/test/Core.Common.TestUtil/LogLevelConstant.cs (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -0,0 +1,39 @@ +using System; +using log4net.Core; + +namespace Core.Common.TestUtil +{ + public enum LogLevelConstant + { + Off, + Fatal, + Error, + Warn, + Info, + Debug + } + + public static class LogLevelConstantExtensions + { + public static Level ToLog4NetLevel(this LogLevelConstant level) + { + switch (level) + { + case LogLevelConstant.Off: + return Level.Off; + case LogLevelConstant.Fatal: + return Level.Fatal; + case LogLevelConstant.Error: + return Level.Error; + case LogLevelConstant.Warn: + return Level.Warn; + case LogLevelConstant.Info: + return Level.Info; + case LogLevelConstant.Debug: + return Level.Debug; + default: + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs =================================================================== diff -u -r654d3a712eedbdeea718dc0448c5544f09e053cd -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 654d3a712eedbdeea718dc0448c5544f09e053cd) +++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -254,7 +254,7 @@ public static void AssertLogMessages(Action action, Action> assertLogMessages) { var renderedMessages = GetAllRenderedMessages(action); - assertLogMessages(renderedMessages); + assertLogMessages(renderedMessages.Select(rm => rm.Item1)); } /// @@ -353,6 +353,65 @@ Assert.AreEqual(expectedCustomMessage, message); } + /// + /// Method used to check if a collection of messages have occured in the log. + /// This function allowed checking log messages being generated like + /// without having to rerun the action for every single message. Fails the test when any of checks fail. + /// + /// Action to be performed while recording the log. + /// The message that should occur in the log with a certain log level. + /// Optional: assert that log has this number of messages. + /// + public static void AssertLogMessageWithLevelIsGenerated(Action action, Tuple message, int? expectedLogMessageCount = null) + { + AssertLogMessagesWithLevelAreGenerated(action, new[] + { + message + }, expectedLogMessageCount); + } + + /// + /// Method used to check if a collection of messages have occured in the log. + /// This function allowed checking log messages being generated like + /// without having to rerun the action for every single message. Fails the test when any of checks fail. + /// + /// Action to be performed while recording the log + /// The collection of messages that should occur in the log + /// Optional: assert that log has this number of messages. + /// + public static void AssertLogMessagesWithLevelAreGenerated(Action action, IEnumerable> messages, int? expectedLogMessageCount = null) + { + var renderedMessages = GetAllRenderedMessages(action); + + AssertExpectedMessagesInRenderedMessages(messages, renderedMessages); + if (expectedLogMessageCount != null) + { + Assert.AreEqual((int) expectedLogMessageCount, renderedMessages.Count()); + } + } + + private static void AssertExpectedMessagesInRenderedMessages(IEnumerable messages, IEnumerable> renderedMessages) + { + foreach (string message in messages) + { + CollectionAssert.Contains(renderedMessages.Select(rm => rm.Item1), message); + } + } + + /// + /// Checks if all messages from occur in + /// + /// The collection of expected messages + /// The collection of messages in the log + private static void AssertExpectedMessagesInRenderedMessages(IEnumerable> messages, IEnumerable> renderedMessages) + { + var messagesWithLog4NetLevel = messages.Select(m => Tuple.Create(m.Item1, m.Item2.ToLog4NetLevel())); + foreach (Tuple message in messagesWithLog4NetLevel) + { + CollectionAssert.Contains(renderedMessages, message); + } + } + private static void AssertContextMenuStripContainsItem(ToolStripItemCollection items, int position, string text, string toolTip, Image icon, bool enabled = true) { Assert.Less(position, items.Count); @@ -448,44 +507,15 @@ return 1.0f; } - /// - /// Checks if all messages from occur in - /// - /// The collection of expected messages - /// The collection of messages in the log - private static void AssertExpectedMessagesInRenderedMessages(IEnumerable messages, IEnumerable renderedMessages) + private static IEnumerable> GetAllRenderedMessages(Action action) { - foreach (string message in messages) - { - CollectionAssert.Contains(renderedMessages, message); - } - } - - /// - /// Checks if none of the messages from occurs in - /// - /// The collection of unwanted messages - /// The collection of log messages in the log - private static void AssertUnwantedMessagesNotInRenderedMessages(IEnumerable messages, IEnumerable renderedMessages) - { - foreach (var renderedMessage in renderedMessages) - { - if (messages.Contains(renderedMessage)) - { - Assert.Fail("Message \"{0}\" found in messages of log4net", renderedMessage); - } - } - } - - private static IEnumerable GetAllRenderedMessages(Action action) - { var memoryAppender = new MemoryAppender(); BasicConfigurator.Configure(memoryAppender); LogHelper.SetLoggingLevel(Level.All); action(); - var renderedMessages = memoryAppender.GetEvents().Select(le => le.RenderedMessage).ToList(); + var renderedMessages = memoryAppender.GetEvents().Select(le => Tuple.Create(le.RenderedMessage, le.Level)).ToList(); memoryAppender.Close(); LogHelper.ResetLogging(); Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -85,7 +85,7 @@ using (var hydraulicBoundaryDatabaseImporter = new HydraulicBoundaryDatabaseImporter()) { hydraulicBoundaryDatabaseImporter.ValidateAndConnectTo(Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "HRD dutch coast south.sqlite")); - hydraulicBoundaryDatabaseImporter.Import(new HydraulicBoundaryDatabaseContext(demoAssessmentSection)); + hydraulicBoundaryDatabaseImporter.Import(demoAssessmentSection); } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/HydraulicBoundaryDatabaseContext.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/HydraulicBoundaryDatabaseContext.cs (.../HydraulicBoundaryDatabaseContext.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/HydraulicBoundaryDatabaseContext.cs (.../HydraulicBoundaryDatabaseContext.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -32,7 +32,7 @@ /// /// Presentation object for all data required to configure an instance of . /// - public class HydraulicBoundaryDatabaseContext : Observable + public class HydraulicBoundaryDatabaseContext : IObservable { private readonly IAssessmentSection parent; @@ -92,5 +92,24 @@ } #endregion + + #region IObservable + + public void Attach(IObserver observer) + { + Parent.Attach(observer); + } + + public void Detach(IObserver observer) + { + Parent.Detach(observer); + } + + public void NotifyObservers() + { + Parent.NotifyObservers(); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/HydraulicBoundaryDatabaseImporter.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/HydraulicBoundaryDatabaseImporter.cs (.../HydraulicBoundaryDatabaseImporter.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/HydraulicBoundaryDatabaseImporter.cs (.../HydraulicBoundaryDatabaseImporter.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -75,6 +75,7 @@ /// Gets the version of the database. /// /// The database version. + /// Thrown when the version could not be obtained from the database. public string GetHydraulicBoundaryDatabaseVersion() { return hydraulicBoundaryDatabaseReader.GetVersion(); @@ -84,10 +85,12 @@ /// Creates a new instance of , based upon the data read from /// the hydraulic boundary database file, and saved into . /// - /// to set the newly + /// to set the newly /// created . /// True if the import was successful, false otherwise. - public bool Import(HydraulicBoundaryDatabaseContext targetItem) + /// The reader has not been initialized by calling + /// . + public bool Import(IAssessmentSection targetItem) { if (hydraulicBoundaryDatabaseReader == null) { @@ -101,7 +104,7 @@ return false; } - AddImportedDataToModel(targetItem.Parent, importResult); + AddImportedDataToModel(targetItem, importResult); log.Info(Resources.HydraulicBoundaryDatabaseImporter_Import_All_hydraulic_locations_read); return true; } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.17929 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -197,5 +197,15 @@ return ResourceManager.GetString("RingtoetsGuiPlugin_Error_during_assessment_level_calculation", resourceCulture); } } + + /// + /// Looks up a localized string similar to Hydraulische randvoorwaarden database kon niet gevonden worden op locatie {0}.. + /// + public static string RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_database_could_not_be_found_on_path_0_ { + get { + return ResourceManager.GetString("RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_databas" + + "e_could_not_be_found_on_path_0_", resourceCulture); + } + } } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx =================================================================== diff -u -rb79e419a1fcdf3d80760ea4bc35ac354525911d2 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision b79e419a1fcdf3d80760ea4bc35ac354525911d2) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Properties/Resources.resx (.../Resources.resx) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -163,4 +163,7 @@ Er is een fout opgetreden tijdens de berekening: inspecteer het logbestand. + + Hydraulische randvoorwaarden database kon niet gevonden worden op locatie {0}. + \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -28,6 +28,7 @@ using System.Windows.Forms; using Core.Common.Base.Data; using Core.Common.Controls.TreeView; +using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; using Core.Common.Gui.Forms.ProgressDialog; @@ -66,9 +67,9 @@ /// /// The GUI plugin for the Ringtoets application. /// - public class RingtoetsGuiPlugin : GuiPlugin + public class RingtoetsGuiPlugin : Core.Common.Gui.Plugin.GuiPlugin { - private static readonly ILog log = LogManager.GetLogger(typeof(GuiPlugin)); + private static readonly ILog log = LogManager.GetLogger(typeof(Core.Common.Gui.Plugin.GuiPlugin)); public override IRibbonCommandHandler RibbonCommandHandler { @@ -78,6 +79,53 @@ } } + public override IGui Gui + { + get + { + return base.Gui; + } + set + { + RemoveOnOpenProjectListener(base.Gui); + base.Gui = value; + AddOnOpenProjectListener(value); + } + } + + private void RemoveOnOpenProjectListener(IProjectOwner projectOwner) + { + if (projectOwner != null) + { + projectOwner.ProjectOpened -= VerifyHydraulicBoundaryDatabasePath; + } + } + + private void AddOnOpenProjectListener(IProjectOwner projectOwner) + { + if (projectOwner != null) + { + projectOwner.ProjectOpened += VerifyHydraulicBoundaryDatabasePath; + } + } + + private void VerifyHydraulicBoundaryDatabasePath(Project project) + { + var sectionsWithDatabase = project.Items.OfType().Where(i => i.HydraulicBoundaryDatabase != null); + foreach (IAssessmentSection section in sectionsWithDatabase) + { + string selectedFile = section.HydraulicBoundaryDatabase.FilePath; + try + { + CreateHydraulicDatabaseImporter(selectedFile); + } + catch (CriticalFileReadException) + { + log.WarnFormat(Resources.RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_database_could_not_be_found_on_path_0_, selectedFile); + } + } + } + /// /// Returns all instances provided for data of . /// @@ -506,7 +554,7 @@ var connectionItem = new StrictContextMenuItem( RingtoetsFormsResources.HydraulicBoundaryDatabase_Connect, RingtoetsFormsResources.HydraulicBoundaryDatabase_Connect_ToolTip, - RingtoetsCommonFormsResources.DatabaseIcon, (sender, args) => { SelectDatabaseFile(nodeData); }); + RingtoetsCommonFormsResources.DatabaseIcon, (sender, args) => { SelectDatabaseFile(nodeData.Parent); }); var designWaterLevelItem = new StrictContextMenuItem( RingtoetsFormsResources.DesignWaterLevel_Calculate, @@ -520,7 +568,6 @@ ActivityProgressDialogRunner.Run(Gui.MainWindow, activities); nodeData.Parent.NotifyObservers(); - nodeData.NotifyObservers(); } ); @@ -543,7 +590,7 @@ .Build(); } - private void SelectDatabaseFile(HydraulicBoundaryDatabaseContext nodeData) + private void SelectDatabaseFile(IAssessmentSection assessmentSection) { var windowTitle = RingtoetsFormsResources.SelectHydraulicBoundaryDatabaseFile_Title; using (var dialog = new OpenFileDialog @@ -557,50 +604,63 @@ { if (dialog.ShowDialog(Gui.MainWindow) == DialogResult.OK) { - ValidateAndImportSelectedFile(nodeData, dialog.FileName); + try + { + ValidateAndImportSelectedFile(dialog.FileName, assessmentSection); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message, exception); + } } } } - private static void ValidateAndImportSelectedFile(HydraulicBoundaryDatabaseContext nodeData, string selectedFile) + /// + /// Attempts to update the based on the . + /// + /// The file to use to import a from. + /// The to which the imported will be assigned. + /// A new which is connected to the . + /// Thrown when the importer could not be created for the selected file. + private static void ValidateAndImportSelectedFile(string selectedFile, IAssessmentSection assessmentSection) { - var hydraulicBoundaryLocationsImporter = new HydraulicBoundaryDatabaseImporter(); + var hydraulicBoundaryLocationsImporter = CreateHydraulicDatabaseImporter(selectedFile); - string newVersion; - try + if (assessmentSection.HydraulicBoundaryDatabase != null) { - hydraulicBoundaryLocationsImporter.ValidateAndConnectTo(selectedFile); + var newVersion = hydraulicBoundaryLocationsImporter.GetHydraulicBoundaryDatabaseVersion(); - if (nodeData.Parent.HydraulicBoundaryDatabase == null) + var currentVersion = assessmentSection.HydraulicBoundaryDatabase.Version; + var currentFilePath = assessmentSection.HydraulicBoundaryDatabase.FilePath; + + if (currentVersion != newVersion && HasClearCalculationConfirmation()) { - ImportSelectedFile(nodeData, hydraulicBoundaryLocationsImporter); - return; + ClearCalculations(assessmentSection); + ImportSelectedFile(assessmentSection, hydraulicBoundaryLocationsImporter); } - - newVersion = hydraulicBoundaryLocationsImporter.GetHydraulicBoundaryDatabaseVersion(); + else if (currentFilePath != selectedFile) + { + SetBoundaryDatabaseData(assessmentSection, selectedFile); + } } - catch (CriticalFileReadException exception) + else { - log.Error(exception.Message, exception); - return; + ImportSelectedFile(assessmentSection, hydraulicBoundaryLocationsImporter); } + } - var currentVersion = nodeData.Parent.HydraulicBoundaryDatabase.Version; - var currentFilePath = nodeData.Parent.HydraulicBoundaryDatabase.FilePath; - - // Compare - if (currentVersion != newVersion) - { - // Show dialog - ShowCleanDialog(nodeData, hydraulicBoundaryLocationsImporter); - return; - } - - if (currentFilePath != selectedFile) - { - // Only set the new file path. Don't import the complete database. - SetBoundaryDatabaseData(nodeData, selectedFile); - } + /// + /// Attempts to connect a new to the . + /// + /// The file to use to import a from. + /// A new which is connected to the . + /// Thrown when the importer could not be created for the selected file. + private static HydraulicBoundaryDatabaseImporter CreateHydraulicDatabaseImporter(string selectedFile) + { + var hydraulicBoundaryLocationsImporter = new HydraulicBoundaryDatabaseImporter(); + hydraulicBoundaryLocationsImporter.ValidateAndConnectTo(selectedFile); + return hydraulicBoundaryLocationsImporter; } private static TargetProbabilityCalculationActivity CreateHydraRingActivity(IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation, string hlcdDirectory) @@ -627,20 +687,14 @@ } } - private static void ShowCleanDialog(HydraulicBoundaryDatabaseContext nodeData, - HydraulicBoundaryDatabaseImporter hydraulicBoundaryLocationsImporter) + private static bool HasClearCalculationConfirmation() { var confirmation = MessageBox.Show( RingtoetsFormsResources.Delete_Calculations_Text, BaseResources.Confirm, MessageBoxButtons.OKCancel); - if (confirmation == DialogResult.OK) - { - ClearCalculations(nodeData.Parent); - - ImportSelectedFile(nodeData, hydraulicBoundaryLocationsImporter); - } + return (confirmation == DialogResult.OK); } private static void ClearCalculations(IAssessmentSection nodeData) @@ -657,25 +711,23 @@ log.Info(RingtoetsFormsResources.Calculations_Deleted); } - private static void ImportSelectedFile(HydraulicBoundaryDatabaseContext nodeData, - HydraulicBoundaryDatabaseImporter hydraulicBoundaryLocationsImporter) + private static void ImportSelectedFile(IAssessmentSection assessmentSection, HydraulicBoundaryDatabaseImporter hydraulicBoundaryLocationsImporter) { - if (hydraulicBoundaryLocationsImporter.Import(nodeData)) + if (hydraulicBoundaryLocationsImporter.Import(assessmentSection)) { - SetBoundaryDatabaseData(nodeData); + SetBoundaryDatabaseData(assessmentSection); } } - private static void SetBoundaryDatabaseData(HydraulicBoundaryDatabaseContext nodeData, string selectedFile = null) + private static void SetBoundaryDatabaseData(IAssessmentSection assessmentSection, string selectedFile = null) { if (!String.IsNullOrEmpty(selectedFile)) { - nodeData.Parent.HydraulicBoundaryDatabase.FilePath = selectedFile; + assessmentSection.HydraulicBoundaryDatabase.FilePath = selectedFile; } - nodeData.Parent.NotifyObservers(); - nodeData.NotifyObservers(); - log.InfoFormat(RingtoetsFormsResources.RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path_0_linked, nodeData.Parent.HydraulicBoundaryDatabase.FilePath); + assessmentSection.NotifyObservers(); + log.InfoFormat(RingtoetsFormsResources.RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path_0_linked, assessmentSection.HydraulicBoundaryDatabase.FilePath); } #endregion Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionCommentContextTreeNodeInfoTest.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionCommentContextTreeNodeInfoTest.cs (.../AssessmentSectionCommentContextTreeNodeInfoTest.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionCommentContextTreeNodeInfoTest.cs (.../AssessmentSectionCommentContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Drawing; using System.Linq; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -39,26 +38,21 @@ public class AssessmentSectionCommentContextTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(CommentContext)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Assert Assert.AreEqual(typeof(CommentContext), info.TagType); Assert.IsNull(info.EnsureVisibleOnCreate); @@ -76,62 +70,88 @@ Assert.IsNull(info.OnDrop); Assert.IsNull(info.ForeColor); } +} [Test] public void Text_Always_ReturnsName() { // Setup var assessmentSectionMock = mocks.StrictMock(); - var context = new CommentContext(assessmentSectionMock); mocks.ReplayAll(); - // Call - var text = info.Text(context); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual("Opmerkingen", text); + var context = new CommentContext(assessmentSectionMock); + + // Call + var text = info.Text(context); + + // Assert + Assert.AreEqual("Opmerkingen", text); + + mocks.VerifyAll(); + } } [Test] public void Image_Always_ReturnsSetImage() { // Setup var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); var context = new CommentContext(assessmentSectionMock); - mocks.ReplayAll(); + // Call + var image = info.Image(context); - // Call - var image = info.Image(context); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + mocks.VerifyAll(); + } } [Test] public void ContextMenuStrip_Always_CallsBuilder() { // Setup - var mocks = new MockRepository(); - var gui = mocks.StrictMultiMock(); - var treeViewControl = mocks.StrictMock(); - var menuBuilderMock = mocks.StrictMock(); + using (var plugin = new RingtoetsGuiPlugin()) + { + var gui = mocks.StrictMock(); + var treeViewControl = mocks.StrictMock(); + var menuBuilderMock = mocks.StrictMock(); - gui.Expect(g => g.Get(null, treeViewControl)).Return(menuBuilderMock); + gui.Expect(g => g.Get(null, treeViewControl)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); - menuBuilderMock.Expect(mb => mb.Build()).Return(null); + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); - mocks.ReplayAll(); + var info = GetInfo(plugin); - plugin.Gui = gui; + mocks.ReplayAll(); - // Call - info.ContextMenuStrip(null, null, treeViewControl); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(null, null, treeViewControl); + } + // Assert mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(Core.Common.Gui.Plugin.GuiPlugin gui) + { + return gui.GetTreeNodeInfos().First(tni => tni.TagType == typeof(CommentContext)); + } } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -36,7 +36,6 @@ using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; -using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using RingtoetsIntegrationFormsResources = Ringtoets.Integration.Forms.Properties.Resources; @@ -46,36 +45,32 @@ public class AssessmentSectionTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IAssessmentSection)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(IAssessmentSection), info.TagType); - Assert.IsNull(info.ForeColor); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(IAssessmentSection), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -89,12 +84,16 @@ mocks.ReplayAll(); - // Call - var text = info.Text(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(testName, text); + // Call + var text = info.Text(assessmentSection); + // Assert + Assert.AreEqual(testName, text); + } mocks.VerifyAll(); } @@ -106,12 +105,16 @@ mocks.ReplayAll(); - // Call - var image = info.Image(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.AssessmentSectionFolderIcon, image); + // Call + var image = info.Image(assessmentSection); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsIntegrationFormsResources.AssessmentSectionFolderIcon, image); + } mocks.VerifyAll(); } @@ -123,12 +126,16 @@ mocks.ReplayAll(); - // Call - var result = info.EnsureVisibleOnCreate(assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.IsTrue(result); + // Call + var result = info.EnsureVisibleOnCreate(assessmentSection); + // Assert + Assert.IsTrue(result); + } mocks.VerifyAll(); } @@ -149,34 +156,37 @@ assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(failureMechanisms); mocks.ReplayAll(); - // Call - var objects = info.ChildNodeObjects(assessmentSection).ToArray(); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + var objects = info.ChildNodeObjects(assessmentSection).ToArray(); - // Assert - Assert.AreEqual(6, objects.Length); - var referenceLineContext = (ReferenceLineContext) objects[0]; - Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); - Assert.AreSame(assessmentSection, referenceLineContext.Parent); + // Assert + Assert.AreEqual(6, objects.Length); + var referenceLineContext = (ReferenceLineContext) objects[0]; + Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData); + Assert.AreSame(assessmentSection, referenceLineContext.Parent); - var contributionContext = (FailureMechanismContributionContext)objects[1]; - Assert.AreSame(contribution, contributionContext.WrappedData); - Assert.AreSame(assessmentSection, contributionContext.Parent); + var contributionContext = (FailureMechanismContributionContext) objects[1]; + Assert.AreSame(contribution, contributionContext.WrappedData); + Assert.AreSame(assessmentSection, contributionContext.Parent); - var context = (HydraulicBoundaryDatabaseContext) objects[2]; - Assert.AreSame(assessmentSection.HydraulicBoundaryDatabase, context.Parent.HydraulicBoundaryDatabase); - Assert.AreSame(assessmentSection, context.Parent); + var context = (HydraulicBoundaryDatabaseContext) objects[2]; + Assert.AreSame(assessmentSection.HydraulicBoundaryDatabase, context.Parent.HydraulicBoundaryDatabase); + Assert.AreSame(assessmentSection, context.Parent); - var commentContext = (CommentContext)objects[3]; - Assert.AreSame(assessmentSection, commentContext.CommentContainer); + var commentContext = (CommentContext)objects[3]; + Assert.AreSame(assessmentSection, commentContext.CommentContainer); - var pipingFailureMechanismContext = (PipingFailureMechanismContext)objects[4]; - Assert.AreSame(failureMechanisms[0], pipingFailureMechanismContext.WrappedData); - Assert.AreSame(assessmentSection, pipingFailureMechanismContext.Parent); + var pipingFailureMechanismContext = (PipingFailureMechanismContext) objects[4]; + Assert.AreSame(failureMechanisms[0], pipingFailureMechanismContext.WrappedData); + Assert.AreSame(assessmentSection, pipingFailureMechanismContext.Parent); - var placeholderFailureMechanismContext = (FailureMechanismPlaceholderContext)objects[5]; - Assert.AreSame(failureMechanisms[1], placeholderFailureMechanismContext.WrappedData); - Assert.AreSame(assessmentSection, placeholderFailureMechanismContext.Parent); - + var placeholderFailureMechanismContext = (FailureMechanismPlaceholderContext) objects[5]; + Assert.AreSame(failureMechanisms[1], placeholderFailureMechanismContext.WrappedData); + Assert.AreSame(assessmentSection, placeholderFailureMechanismContext.Parent); + } mocks.VerifyAll(); } @@ -188,6 +198,8 @@ var treeViewControlMock = mocks.StrictMock(); var menuBuilderMock = mocks.StrictMock(); gui.Expect(g => g.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); @@ -205,23 +217,32 @@ mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + plugin.Gui = gui; - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); - + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } [Test] public void CanRename_Always_ReturnsTrue() { - // Call - var canRename = info.CanRename(null, null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.IsTrue(canRename); + // Call + var canRename = info.CanRename(null, null); + + // Assert + Assert.IsTrue(canRename); + } } [Test] @@ -233,23 +254,32 @@ mocks.ReplayAll(); - // Call - const string newName = "New Name"; - info.OnNodeRenamed(assessmentSection, newName); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + const string newName = "New Name"; + info.OnNodeRenamed(assessmentSection, newName); - // Assert - Assert.AreEqual(newName, assessmentSection.Name); + // Assert + Assert.AreEqual(newName, assessmentSection.Name); + } mocks.VerifyAll(); } [Test] public void CanRemove_Always_ReturnsTrue() { - // Call - var canRemove = info.CanRemove(null, null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + var canRemove = info.CanRemove(null, null); - // Assert - Assert.IsTrue(canRemove); + // Assert + Assert.IsTrue(canRemove); + } } [Test] @@ -267,12 +297,22 @@ project.Items.Add(assessmentSection); project.Attach(observerMock); - // Call - info.OnNodeRemoved(assessmentSection, project); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - CollectionAssert.DoesNotContain(project.Items, assessmentSection); + // Call + info.OnNodeRemoved(assessmentSection, project); + + // Assert + CollectionAssert.DoesNotContain(project.Items, assessmentSection); + } mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(IAssessmentSection)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/CategoryTreeFolderTreeNodeInfoTest.cs =================================================================== diff -u -r17574077c6720e02c10f23ac3a0354db35855a05 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/CategoryTreeFolderTreeNodeInfoTest.cs (.../CategoryTreeFolderTreeNodeInfoTest.cs) (revision 17574077c6720e02c10f23ac3a0354db35855a05) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/CategoryTreeFolderTreeNodeInfoTest.cs (.../CategoryTreeFolderTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -15,40 +15,36 @@ public class CategoryTreeFolderTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(CategoryTreeFolder)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(CategoryTreeFolder), info.TagType); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(CategoryTreeFolder), info.TagType); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -57,51 +53,71 @@ // Setup var testname = "testName"; var categoryTreeFolder = new CategoryTreeFolder(testname, new object[0]); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var text = info.Text(categoryTreeFolder); + // Call + var text = info.Text(categoryTreeFolder); - // Assert - Assert.AreEqual(testname, text); + // Assert + Assert.AreEqual(testname, text); + } } [Test] public void Image_TreeFolderOfCategoryGeneral_ReturnsGeneralFolderIcon() { // Setup var categoryTreeFolder = new CategoryTreeFolder("", new object[0]); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var image = info.Image(categoryTreeFolder); + // Call + var image = info.Image(categoryTreeFolder); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GeneralFolderIcon, image); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GeneralFolderIcon, image); + } } [Test] public void Image_TreeFolderOfCategoryInput_ReturnsInputFolderIcon() { // Setup var categoryTreeFolder = new CategoryTreeFolder("", new object[0], TreeFolderCategory.Input); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var image = info.Image(categoryTreeFolder); + // Call + var image = info.Image(categoryTreeFolder); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.InputFolderIcon, image); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.InputFolderIcon, image); + } } [Test] public void Image_TreeFolderOfCategoryOutput_ReturnsOutputFolderIcon() { // Setup var categoryTreeFolder = new CategoryTreeFolder("", new object[0], TreeFolderCategory.Output); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var image = info.Image(categoryTreeFolder); + // Call + var image = info.Image(categoryTreeFolder); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.OutputFolderIcon, image); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.OutputFolderIcon, image); + } } [Test] @@ -111,13 +127,21 @@ var object1 = new object(); var object2 = new object(); var categoryTreeFolder = new CategoryTreeFolder("", new[] { object1, object2 }); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var objects = info.ChildNodeObjects(categoryTreeFolder); + // Call + var objects = info.ChildNodeObjects(categoryTreeFolder); - // Assert - CollectionAssert.AreEqual(new[] { object1, object2 }, objects); - + // Assert + CollectionAssert.AreEqual(new[] + { + object1, + object2 + }, objects); + } mocks.VerifyAll(); } @@ -134,15 +158,27 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); gui.Expect(cmp => cmp.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - plugin.Gui = gui; + plugin.Gui = gui; - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); - + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } + + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(CategoryTreeFolder)); + } } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionContextTreeNodeInfoTest.cs (.../FailureMechanismContributionContextTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismContributionContextTreeNodeInfoTest.cs (.../FailureMechanismContributionContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -22,64 +22,70 @@ public class FailureMechanismContributionContextTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismContributionContext)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(FailureMechanismContributionContext), info.TagType); - Assert.IsNull(info.ForeColor); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.ChildNodeObjects); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(FailureMechanismContributionContext), info.TagType); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] public void Text_Always_ReturnsTextFromResource() { - // Call - var text = info.Text(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(RingtoetsIntegrationDataResources.FailureMechanismContribution_DisplayName, text); + // Call + var text = info.Text(null); + + // Assert + Assert.AreEqual(RingtoetsIntegrationDataResources.FailureMechanismContribution_DisplayName, text); + } } [Test] public void Image_Always_ReturnsSetImage() { - // Call - var image = info.Image(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + // Call + var image = info.Image(null); - mocks.VerifyAll(); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } } [Test] @@ -98,20 +104,32 @@ var gui = mocks.StrictMock(); gui.Expect(cmp => cmp.Get(contribution, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var context = new FailureMechanismContributionContext(contribution, assessmentSection); - plugin.Gui = gui; + + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(context, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(context, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismContributionContext)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs (.../FailureMechanismPlaceholderTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismPlaceholderTreeNodeInfoTest.cs (.../FailureMechanismPlaceholderTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -26,40 +26,36 @@ public class FailureMechanismPlaceholderTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismPlaceholderContext)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(FailureMechanismPlaceholderContext), info.TagType); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(FailureMechanismPlaceholderContext), info.TagType); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -73,32 +69,49 @@ var placeholder = new Placeholder(testName); var placeholderContext = new FailureMechanismPlaceholderContext(placeholder, assessmentSection); - // Call - var text = info.Text(placeholderContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(testName, text); + // Call + var text = info.Text(placeholderContext); + + // Assert + Assert.AreEqual(testName, text); + } mocks.VerifyAll(); } [Test] public void Image_Always_ReturnsSetImage() { - // Call - var image = info.Image(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.FailureMechanismIcon, image); + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.FailureMechanismIcon, image); + } } [Test] public void ForeColor_Always_ReturnsGrayText() { - // Call - var textColor = info.ForeColor(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } } [Test] @@ -108,36 +121,45 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var failureMechanism = new Placeholder("test"); - failureMechanism.AddSection(new FailureMechanismSection("A", new[]{ new Point2D(1,2), new Point2D(5,6) })); - var failureMechanismContext = new FailureMechanismPlaceholderContext(failureMechanism, assessmentSection); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + var failureMechanism = new Placeholder("test"); + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(1, 2), + new Point2D(5, 6) + })); + var failureMechanismContext = new FailureMechanismPlaceholderContext(failureMechanism, assessmentSection); - // Assert - Assert.AreEqual(2, children.Length); - var inputFolder = (CategoryTreeFolder)children[0]; - Assert.AreEqual("Invoer", inputFolder.Name); - Assert.AreEqual(TreeFolderCategory.Input, inputFolder.Category); + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); - var failureMechanismSectionsContext = (FailureMechanismSectionsContext)inputFolder.Contents[0]; - CollectionAssert.AreEqual(failureMechanism.Sections, failureMechanismSectionsContext.WrappedData); - Assert.AreSame(failureMechanism, failureMechanismSectionsContext.ParentFailureMechanism); - Assert.AreSame(assessmentSection, failureMechanismSectionsContext.ParentAssessmentSection); - CollectionAssert.AreEqual(new[] - { - failureMechanism.Locations, - failureMechanism.BoundaryConditions - }, inputFolder.Contents.Cast().Skip(1)); + // Assert + Assert.AreEqual(2, children.Length); + var inputFolder = (CategoryTreeFolder) children[0]; + Assert.AreEqual("Invoer", inputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputFolder.Category); - var outputFolder = (CategoryTreeFolder)children[1]; - Assert.AreEqual("Uitvoer", outputFolder.Name); - Assert.AreEqual(TreeFolderCategory.Output, outputFolder.Category); - - var failureMechanismResultsContext = (FailureMechanismSectionResultContext)outputFolder.Contents[0]; - Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); - Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.SectionResults); + var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputFolder.Contents[0]; + CollectionAssert.AreEqual(failureMechanism.Sections, failureMechanismSectionsContext.WrappedData); + Assert.AreSame(failureMechanism, failureMechanismSectionsContext.ParentFailureMechanism); + Assert.AreSame(assessmentSection, failureMechanismSectionsContext.ParentAssessmentSection); + CollectionAssert.AreEqual(new[] + { + failureMechanism.Locations, + failureMechanism.BoundaryConditions + }, inputFolder.Contents.Cast().Skip(1)); + + var outputFolder = (CategoryTreeFolder) children[1]; + Assert.AreEqual("Uitvoer", outputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputFolder.Category); + + var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputFolder.Contents[0]; + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.SectionResults); + } mocks.VerifyAll(); } @@ -162,14 +184,20 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); gui.Expect(cmp => cmp.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -183,19 +211,31 @@ var menuBuilderMock = new CustomItemsOnlyContextMenuBuilder(); gui.Expect(cmp => cmp.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var menu = info.ContextMenuStrip(null, null, treeViewControlMock); + plugin.Gui = gui; + // Call + var menu = info.ContextMenuStrip(null, null, treeViewControlMock); + + TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.Calculate_all, RingtoetsCommonFormsResources.Calculate_all_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, false); + TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.Clear_all_output, RingtoetsCommonFormsResources.Clear_all_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false); + } + // Assert mocks.VerifyAll(); + } - TestHelper.AssertContextMenuStripContainsItem(menu, 0, RingtoetsCommonFormsResources.Calculate_all, RingtoetsCommonFormsResources.Calculate_all_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, false); - TestHelper.AssertContextMenuStripContainsItem(menu, 1, RingtoetsCommonFormsResources.Clear_all_output, RingtoetsCommonFormsResources.Clear_all_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon, false); + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismPlaceholderContext)); } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionResultContextTreeNodeInfoTest.cs =================================================================== diff -u -rc116b4635603c6d5bbdedb837f68fd3839ece6ca -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionResultContextTreeNodeInfoTest.cs (.../FailureMechanismSectionResultContextTreeNodeInfoTest.cs) (revision c116b4635603c6d5bbdedb837f68fd3839ece6ca) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionResultContextTreeNodeInfoTest.cs (.../FailureMechanismSectionResultContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -104,6 +104,7 @@ var menuBuilderMock = mocks.StrictMock(); gui.Expect(g => g.Get(null, treeViewControl)).Return(menuBuilderMock); + gui.Expect(g => g.ProjectOpened += null).IgnoreArguments(); menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/FailureMechanismSectionsContextTreeNodeInfoTest.cs (.../FailureMechanismSectionsContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -25,63 +25,69 @@ public class FailureMechanismSectionsContextTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismSectionsContext)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(FailureMechanismSectionsContext), info.TagType); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.ChildNodeObjects); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(FailureMechanismSectionsContext), info.TagType); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] public void Text_Always_ReturnsName() { - // Call - var text = info.Text(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual("Vakindeling", text); + // Call + var text = info.Text(null); + + // Assert + Assert.AreEqual("Vakindeling", text); + } } [Test] public void Image_Always_ReturnSectionsIcon() { // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var image = info.Image(null); + // Call + var image = info.Image(null); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.Sections, image); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.Sections, image); + } } [Test] @@ -100,14 +106,20 @@ var gui = mocks.StrictMock(); gui.Expect(cmp => cmp.Get(context, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(context, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(context, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -123,11 +135,16 @@ var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); - // Call - Color color = info.ForeColor(context); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + // Call + Color color = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + } mocks.VerifyAll(); } @@ -149,12 +166,22 @@ var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); - // Call - Color color = info.ForeColor(context); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + // Call + Color color = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + } mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailureMechanismSectionsContext)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -13,9 +13,9 @@ using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Plugin; using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources; @@ -27,38 +27,33 @@ public class HydraulicBoundaryDatabaseContextTreeNodeInfoTest : NUnitFormTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Forms, "HydraulicBoundaryDatabase"); [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HydraulicBoundaryDatabaseContext)); } - [TearDown] - public override void TearDown() - { - plugin.Dispose(); - base.TearDown(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(HydraulicBoundaryDatabaseContext), info.TagType); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(HydraulicBoundaryDatabaseContext), info.TagType); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -72,33 +67,49 @@ var context = new HydraulicBoundaryDatabaseContext(assessmentSectionMock); - // Call - var text = info.Text(context); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(name, text); + // Call + var text = info.Text(context); + // Assert + Assert.AreEqual(name, text); + } mocks.VerifyAll(); } [Test] public void Image_Always_ReturnsGenericIcon() { - // Call - var image = info.Image(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } } [Test] public void CanRenameNode_Always_ReturnsFalse() { - // Call - var renameAllowed = info.CanRename(null, null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.IsFalse(renameAllowed); + // Call + var renameAllowed = info.CanRename(null, null); + + // Assert + Assert.IsFalse(renameAllowed); + } } [Test] @@ -124,14 +135,20 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(menuBuilderMock); + guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = guiMock; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(nodeData, null, treeViewControlMock); + plugin.Gui = guiMock; + // Call + info.ContextMenuStrip(nodeData, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -147,20 +164,26 @@ var nodeData = new HydraulicBoundaryDatabaseContext(assessmentSectionMock); guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = guiMock; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + plugin.Gui = guiMock; + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + + const string expectedItemText = "&Toetspeilen berekenen"; + const string expectedItemTooltip = "Er is geen hydraulische randvoorwaarden database beschikbaar om de toetspeilen te berekenen."; + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, expectedItemText, expectedItemTooltip, RingtoetsFormsResources.FailureMechanismIcon, false); + } // Assert mocks.VerifyAll(); // Expect no calls on arguments - - const string expectedItemText = "&Toetspeilen berekenen"; - const string expectedItemTooltip = "Er is geen hydraulische randvoorwaarden database beschikbaar om de toetspeilen te berekenen."; - TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, expectedItemText, expectedItemTooltip, RingtoetsFormsResources.FailureMechanismIcon, false); } [Test] @@ -175,21 +198,28 @@ nodeData.Parent.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = guiMock; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - nodeData.Parent.HydraulicBoundaryDatabase.FilePath = testDataPath; - var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + plugin.Gui = guiMock; + // Call + nodeData.Parent.HydraulicBoundaryDatabase.FilePath = testDataPath; + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + + const string expectedItemText = "&Toetspeilen berekenen"; + const string expectedItemTooltip = "Bereken de toetspeilen"; + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, expectedItemText, expectedItemTooltip, RingtoetsFormsResources.FailureMechanismIcon); + } // Assert mocks.VerifyAll(); // Expect no calls on arguments - const string expectedItemText = "&Toetspeilen berekenen"; - const string expectedItemTooltip = "Bereken de toetspeilen"; - TestHelper.AssertContextMenuStripContainsItem(contextMenu, 3, expectedItemText, expectedItemTooltip, RingtoetsFormsResources.FailureMechanismIcon); } [Test] @@ -221,14 +251,11 @@ FilePath = "D:/nonExistingDirectory/nonExistingFile", Version = "random" }; - var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), 10, 30000); - var assessmentSectionMock = mocks.Stub(); - assessmentSectionMock.Name = "Dummy"; - assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; - assessmentSectionMock.Stub(section => section.FailureMechanismContribution).Return(failureMechanismContribution); - assessmentSectionMock.Expect(section => section.NotifyObservers()); - + var assessmentSectionMock = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; var hydraulicBoundaryDatabaseContext = new HydraulicBoundaryDatabaseContext(assessmentSectionMock); hydraulicBoundaryDatabaseContextObserver.Expect(o => o.UpdateObserver()); @@ -239,35 +266,38 @@ hydraulicBoundaryDatabaseContext.Attach(hydraulicBoundaryDatabaseContextObserver); - plugin.Gui = gui; - - var contextMenuAdapter = info.ContextMenuStrip(hydraulicBoundaryDatabaseContext, null, treeViewControlMock); - - DialogBoxHandler = (name, wnd) => + using (var plugin = new RingtoetsGuiPlugin()) { - // Don't care about dialogs in this test. - }; + var info = GetInfo(plugin); + plugin.Gui = gui; - // When - Action action = () => { contextMenuAdapter.Items[contextMenuRunAssessmentLevelCalculationsIndex].PerformClick(); }; + var contextMenuAdapter = info.ContextMenuStrip(hydraulicBoundaryDatabaseContext, null, treeViewControlMock); - // Then - TestHelper.AssertLogMessages(action, messages => - { - var msgs = messages.GetEnumerator(); - Assert.IsTrue(msgs.MoveNext()); - StringAssert.StartsWith("Er is een fout opgetreden tijdens de berekening: inspecteer het logbestand.", msgs.Current); - Assert.IsTrue(msgs.MoveNext()); - StringAssert.StartsWith("Uitvoeren van 'Toetspeil berekenen voor locatie '100001'' is mislukt.", msgs.Current); - Assert.IsTrue(msgs.MoveNext()); - StringAssert.StartsWith("Er is een fout opgetreden tijdens de berekening: inspecteer het logbestand.", msgs.Current); - Assert.IsTrue(msgs.MoveNext()); - StringAssert.StartsWith("Uitvoeren van 'Toetspeil berekenen voor locatie '100002'' is mislukt.", msgs.Current); - }); + DialogBoxHandler = (name, wnd) => + { + // Don't care about dialogs in this test. + }; - Assert.IsNaN(hydraulicBoundaryLocation1.DesignWaterLevel); // No result set - Assert.AreEqual(4.2, hydraulicBoundaryLocation2.DesignWaterLevel); // Previous result not cleared + // When + Action action = () => { contextMenuAdapter.Items[contextMenuRunAssessmentLevelCalculationsIndex].PerformClick(); }; + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.GetEnumerator(); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Er is een fout opgetreden tijdens de berekening: inspecteer het logbestand.", msgs.Current); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Uitvoeren van 'Toetspeil berekenen voor locatie '100001'' is mislukt.", msgs.Current); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Er is een fout opgetreden tijdens de berekening: inspecteer het logbestand.", msgs.Current); + Assert.IsTrue(msgs.MoveNext()); + StringAssert.StartsWith("Uitvoeren van 'Toetspeil berekenen voor locatie '100002'' is mislukt.", msgs.Current); + }); + + Assert.IsNaN(hydraulicBoundaryLocation1.DesignWaterLevel); // No result set + Assert.AreEqual(4.2, hydraulicBoundaryLocation2.DesignWaterLevel); // Previous result not cleared + } mocks.VerifyAll(); } @@ -280,11 +310,15 @@ var hydraulicBoundaryDatabaseContext = new HydraulicBoundaryDatabaseContext(assessmentSection); - // Call - Color color = info.ForeColor(hydraulicBoundaryDatabaseContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + Color color = info.ForeColor(hydraulicBoundaryDatabaseContext); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + } mocks.VerifyAll(); } @@ -298,12 +332,21 @@ var hydraulicBoundaryDatabaseContext = new HydraulicBoundaryDatabaseContext(assessmentSection); - // Call - Color color = info.ForeColor(hydraulicBoundaryDatabaseContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + // Call + Color color = info.ForeColor(hydraulicBoundaryDatabaseContext); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + } mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HydraulicBoundaryDatabaseContext)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs =================================================================== diff -u -r08ab7af115b5bbad87eaffb9bc1b1c4379ec8738 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs (.../PlaceholderWithReadonlyNameTreeNodeInfoTest.cs) (revision 08ab7af115b5bbad87eaffb9bc1b1c4379ec8738) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/PlaceholderWithReadonlyNameTreeNodeInfoTest.cs (.../PlaceholderWithReadonlyNameTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -17,41 +17,37 @@ public class PlaceholderWithReadonlyNameTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PlaceholderWithReadonlyName)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(PlaceholderWithReadonlyName), info.TagType); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.ChildNodeObjects); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(PlaceholderWithReadonlyName), info.TagType); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -61,51 +57,80 @@ var testName = "ttt"; var placeholder = new PlaceholderWithReadonlyName(testName); - // Call - var text = info.Text(placeholder); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(testName, text); + // Call + var text = info.Text(placeholder); + + // Assert + Assert.AreEqual(testName, text); + } } [Test] public void Image_OutputPlaceHolder_ReturnsGenericInputOutputIcon() { - // Call - var image = info.Image(new OutputPlaceholder(string.Empty)); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + // Call + var image = info.Image(new OutputPlaceholder(string.Empty)); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } } [Test] public void Image_InputPlaceHolder_ReturnsGenericInputOutputIcon() { - // Call - var image = info.Image(new InputPlaceholder(string.Empty)); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + // Call + var image = info.Image(new InputPlaceholder(string.Empty)); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } } [Test] public void Image_PlaceHolder_ReturnsPlaceHolderIcon() { - // Call - var image = info.Image(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.PlaceholderIcon, image); + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.PlaceholderIcon, image); + } } [Test] public void ForeColor_Always_ReturnsGrayText() { - // Call - var textColor = info.ForeColor(null); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + // Call + var textColor = info.ForeColor(null); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); + } } [Test] @@ -127,14 +152,20 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); gui.Expect(cmp => cmp.Get(outputPlaceholder, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(outputPlaceholder, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(outputPlaceholder, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -157,14 +188,20 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); gui.Expect(cmp => cmp.Get(inputPlaceholder, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(inputPlaceholder, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(inputPlaceholder, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -184,16 +221,27 @@ menuBuilderMock.Expect(mb => mb.Build()).Return(null); gui.Expect(cmp => cmp.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PlaceholderWithReadonlyName)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs (.../ReferenceLineContextTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/ReferenceLineContextTreeNodeInfoTest.cs (.../ReferenceLineContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -24,41 +24,37 @@ public class ReferenceLineContextTreeNodeInfoTest { private MockRepository mocks; - private RingtoetsGuiPlugin plugin; - private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); - plugin = new RingtoetsGuiPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ReferenceLineContext)); } - [TearDown] - public void TearDown() - { - plugin.Dispose(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { - // Assert - Assert.AreEqual(typeof(ReferenceLineContext), info.TagType); - Assert.IsNull(info.EnsureVisibleOnCreate); - Assert.IsNull(info.ChildNodeObjects); - Assert.IsNull(info.CanRename); - Assert.IsNull(info.OnNodeRenamed); - Assert.IsNull(info.CanRemove); - Assert.IsNull(info.OnNodeRemoved); - Assert.IsNull(info.CanCheck); - Assert.IsNull(info.IsChecked); - Assert.IsNull(info.OnNodeChecked); - Assert.IsNull(info.CanDrag); - Assert.IsNull(info.CanDrop); - Assert.IsNull(info.CanInsert); - Assert.IsNull(info.OnDrop); + // Setup + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); + + // Assert + Assert.AreEqual(typeof(ReferenceLineContext), info.TagType); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } } [Test] @@ -70,12 +66,16 @@ var referenceLineContext = new ReferenceLineContext(assessmentSection); - // Call - var text = info.Text(referenceLineContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual("Referentielijn", text); + // Call + var text = info.Text(referenceLineContext); + // Assert + Assert.AreEqual("Referentielijn", text); + } mocks.VerifyAll(); } @@ -88,12 +88,16 @@ var referenceLineContext = new ReferenceLineContext(assessmentSection); - // Call - var image = info.Image(referenceLineContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ReferenceLineIcon, image); + // Call + var image = info.Image(referenceLineContext); + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ReferenceLineIcon, image); + } mocks.VerifyAll(); } @@ -105,16 +109,22 @@ var treeViewControlMock = mocks.StrictMock(); var menuBuilderMock = mocks.StrictMock(); gui.Expect(g => g.Get(null, treeViewControlMock)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); mocks.ReplayAll(); - plugin.Gui = gui; + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Call - info.ContextMenuStrip(null, null, treeViewControlMock); + plugin.Gui = gui; + // Call + info.ContextMenuStrip(null, null, treeViewControlMock); + } // Assert mocks.VerifyAll(); } @@ -128,11 +138,16 @@ var referenceLineContext = new ReferenceLineContext(assessmentSection); - // Call - Color color = info.ForeColor(referenceLineContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + // Call + Color color = info.ForeColor(referenceLineContext); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); + } mocks.VerifyAll(); } @@ -146,12 +161,22 @@ var referenceLineContext = new ReferenceLineContext(assessmentSection); - // Call - Color color = info.ForeColor(referenceLineContext); + using (var plugin = new RingtoetsGuiPlugin()) + { + var info = GetInfo(plugin); - // Assert - Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + // Call + Color color = info.ForeColor(referenceLineContext); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); + } mocks.VerifyAll(); } + + private TreeNodeInfo GetInfo(RingtoetsGuiPlugin guiPlugin) + { + return guiPlugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ReferenceLineContext)); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/HydraulicBoundaryDatabaseImporterTest.cs (.../HydraulicBoundaryDatabaseImporterTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -147,10 +147,8 @@ assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); mocks.ReplayAll(); - var context = new HydraulicBoundaryDatabaseContext(assessmentSection); - // Call - TestDelegate call = () => importer.Import(context); + TestDelegate call = () => importer.Import(assessmentSection); // Assert var exception = Assert.Throws(call); @@ -168,8 +166,6 @@ assessmentSection.Expect(section => section.NotifyObservers()); mocks.ReplayAll(); - var importTarget = new HydraulicBoundaryDatabaseContext(assessmentSection); - string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); // Precondition @@ -179,7 +175,7 @@ // Call var importResult = false; - Action call = () => importResult = importer.Import(importTarget); + Action call = () => importResult = importer.Import(assessmentSection); // Assert TestHelper.AssertLogMessages(call, messages => @@ -188,7 +184,7 @@ StringAssert.EndsWith("De hydraulische randvoorwaarden locaties zijn ingelezen.", messageArray[0]); }); Assert.IsTrue(importResult); - ICollection importedLocations = importTarget.Parent.HydraulicBoundaryDatabase.Locations; + ICollection importedLocations = assessmentSection.HydraulicBoundaryDatabase.Locations; Assert.AreEqual(18, importedLocations.Count); CollectionAssert.AllItemsAreNotNull(importedLocations); CollectionAssert.AllItemsAreUnique(importedLocations); @@ -204,8 +200,6 @@ assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); mocks.ReplayAll(); - var importTarget = new HydraulicBoundaryDatabaseContext(assessmentSection); - string corruptPath = Path.Combine(testDataPath, "corruptschema.sqlite"); var expectedLogMessage = string.Format("Fout bij het lezen van bestand '{0}': Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database. Het bestand wordt overgeslagen.", corruptPath); @@ -214,12 +208,12 @@ importer.ValidateAndConnectTo(corruptPath); // Call - Action call = () => importResult = importer.Import(importTarget); + Action call = () => importResult = importer.Import(assessmentSection); // Assert TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage, 1); Assert.IsFalse(importResult); - Assert.IsNull(importTarget.Parent.HydraulicBoundaryDatabase, "No HydraulicBoundaryDatabase object should be created when import from corrupt database."); + Assert.IsNull(assessmentSection.HydraulicBoundaryDatabase, "No HydraulicBoundaryDatabase object should be created when import from corrupt database."); mocks.VerifyAll(); } @@ -231,7 +225,6 @@ var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.Expect(section => section.NotifyObservers()).Repeat.Never(); - var importTarget = mocks.StrictMock(assessmentSection); mocks.ReplayAll(); string validFilePath = Path.Combine(testDataPath, "corruptschema.sqlite"); @@ -242,7 +235,7 @@ Assert.DoesNotThrow(precondition, "Precodition failed: ValidateAndConnectTo failed"); // Call - Action call = () => importResult = importer.Import(importTarget); + Action call = () => importResult = importer.Import(assessmentSection); // Assert string expectedMessage = new FileReaderErrorMessageBuilder(validFilePath) Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r3b5fac4302590ba12f652bc55979d7b0ce59fd87 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 3b5fac4302590ba12f652bc55979d7b0ce59fd87) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -98,6 +98,10 @@ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Utils + + {26214bd0-dafb-4cfc-8eb2-80c5d53c859e} + Core.Common.Gui.TestUtil + {d749ee4c-ce50-4c17-bf01-9a953028c126} Core.Common.TestUtil Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs =================================================================== diff -u -r5ef5e3e186036b4985798236624d86b2801b87d3 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision 5ef5e3e186036b4985798236624d86b2801b87d3) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsGuiPluginTest.cs (.../RingtoetsGuiPluginTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1,21 +1,27 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using Core.Common.Base.Data; using Core.Common.Base.Plugin; +using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Plugin; +using Core.Common.Gui.Settings; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Placeholder; +using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; @@ -31,25 +37,128 @@ [STAThread] // For creation of XAML UI component public void DefaultConstructor_ExpectedValues() { - // call + // Call using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { - // assert - Assert.IsInstanceOf(ringtoetsGuiPlugin); + // Assert + Assert.IsInstanceOf(ringtoetsGuiPlugin); Assert.IsInstanceOf(ringtoetsGuiPlugin.RibbonCommandHandler); } } [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithoutHydraulicBoundaryDatabase_ThenNoWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + // Call + Action action = () => gui.Project = new Project(); + + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } + } + + [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithHydraulicBoundaryDatabaseWithExistingLocation_ThenNoWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + var testDataDir = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryLocationReader"); + var testDataPath = Path.Combine(testDataDir, "complete.sqlite"); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + var project = new Project(); + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = testDataPath + } + }; + project.Items.Add(section); + + // Call + Action action = () => + { + gui.Project = project; + }; + + // Assert + TestHelper.AssertLogMessagesCount(action, 0); + } + } + + [Test] + [STAThread] // For creation of XAML UI component + public void GivenGuiPluginWithGuiSet_WhenProjectOnGuiChangesToProjectWithHydraulicBoundaryDatabaseWithNonExistingLocation_ThenWarning() + { + // Setup + var mocks = new MockRepository(); + var projectStore = mocks.Stub(); + mocks.ReplayAll(); + + using (var gui = new GuiCore(new MainWindow(), projectStore, new ApplicationCore(), new GuiCoreSettings())) + using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) + { + var project = new Project(); + var notExistingFile = "not_existing_file"; + + IAssessmentSection section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = notExistingFile + } + }; + project.Items.Add(section); + + ringtoetsGuiPlugin.Gui = gui; + gui.Run(); + + // Call + Action action = () => + { + gui.Project = project; + }; + + // Assert + string message = string.Format( + Properties.Resources.RingtoetsGuiPlugin_VerifyHydraulicBoundaryDatabasePath_Hydraulic_boundary_database_could_not_be_found_on_path_0_, + notExistingFile); + TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(message, LogLevelConstant.Warn)); + } + } + + [Test] public void GetPropertyInfos_ReturnsSupportedPropertyClasses() { - // setup + // Setup using (var guiPlugin = new RingtoetsGuiPlugin()) { - // call + // Call PropertyInfo[] propertyInfos = guiPlugin.GetPropertyInfos().ToArray(); - // assert + // Assert Assert.AreEqual(2, propertyInfos.Length); var assessmentSectionProperties = propertyInfos.Single(pi => pi.DataType == typeof(IAssessmentSection)); @@ -100,7 +209,7 @@ [Test] public void GetTreeNodeInfos_ReturnsSupportedTreeNodeInfos() { - // setup + // Setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); @@ -115,10 +224,10 @@ Gui = guiStub }) { - // call + // Call TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); - // assert + // Assert Assert.AreEqual(10, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(IAssessmentSection))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ReferenceLineContext))); Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.Designer.cs =================================================================== diff -u -rbff183a6d323111affe69f3afa19b9ada02c9375 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.Designer.cs (.../PipingSurfaceLineSelectionDialog.Designer.cs) (revision bff183a6d323111affe69f3afa19b9ada02c9375) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.Designer.cs (.../PipingSurfaceLineSelectionDialog.Designer.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -31,13 +31,13 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PipingSurfaceLineSelectionDialog)); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.OkButton = new System.Windows.Forms.Button(); - this.CancelButton = new System.Windows.Forms.Button(); + this.CustomCancelButton = new System.Windows.Forms.Button(); this.flowLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // // flowLayoutPanel1 // - this.flowLayoutPanel1.Controls.Add(this.CancelButton); + this.flowLayoutPanel1.Controls.Add(this.CustomCancelButton); this.flowLayoutPanel1.Controls.Add(this.OkButton); resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1"); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; @@ -51,10 +51,10 @@ // // CancelButton // - resources.ApplyResources(this.CancelButton, "CancelButton"); - this.CancelButton.Name = "CancelButton"; - this.CancelButton.UseVisualStyleBackColor = true; - this.CancelButton.Click += new System.EventHandler(this.CancelButtonOnClick); + resources.ApplyResources(this.CustomCancelButton, "CustomCancelButton"); + this.CustomCancelButton.Name = "CustomCancelButton"; + this.CustomCancelButton.UseVisualStyleBackColor = true; + this.CustomCancelButton.Click += new System.EventHandler(this.CancelButtonOnClick); // // PipingSurfaceLineSelectionDialog // @@ -70,7 +70,7 @@ #endregion private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.Button CancelButton; + private System.Windows.Forms.Button CustomCancelButton; private System.Windows.Forms.Button OkButton; } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.cs =================================================================== diff -u -re473fe41d29060803b0d8f560a48ec8b9618bea4 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.cs (.../PipingSurfaceLineSelectionDialog.cs) (revision e473fe41d29060803b0d8f560a48ec8b9618bea4) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.cs (.../PipingSurfaceLineSelectionDialog.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -41,7 +41,7 @@ protected override Button GetCancelButton() { - return CancelButton; + return CustomCancelButton; } private PipingSurfaceLineSelectionView PipingSurfaceLineSelectionView { get; set; } Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.resx =================================================================== diff -u -rbff183a6d323111affe69f3afa19b9ada02c9375 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.resx (.../PipingSurfaceLineSelectionDialog.resx) (revision bff183a6d323111affe69f3afa19b9ada02c9375) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingSurfaceLineSelectionDialog.resx (.../PipingSurfaceLineSelectionDialog.resx) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -118,29 +118,29 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 293, 3 - + 75, 23 - + 1 - + Annuleren - - CancelButton + + CustomCancelButton - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + flowLayoutPanel1 - + 0 Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingSurfaceLineSelectionDialogTest.cs =================================================================== diff -u -r5782c43794d78fe92cd8864cd8f8b0b53957ec06 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingSurfaceLineSelectionDialogTest.cs (.../PipingSurfaceLineSelectionDialogTest.cs) (revision 5782c43794d78fe92cd8864cd8f8b0b53957ec06) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingSurfaceLineSelectionDialogTest.cs (.../PipingSurfaceLineSelectionDialogTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using NUnit.Extensions.Forms; @@ -108,7 +107,7 @@ selectionView.Rows[0].Cells[0].Value = true; // When - var cancelButton = new ButtonTester("CancelButton", dialog); + var cancelButton = new ButtonTester("CustomCancelButton", dialog); cancelButton.Click(); // Then Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -1029,7 +1029,7 @@ selectionDialog = new FormTester(name).TheObject as PipingSurfaceLineSelectionDialog; grid = new ControlTester("SurfaceLineDataGrid", selectionDialog).TheObject as DataGridView; - new ButtonTester("CancelButton", selectionDialog).Click(); + new ButtonTester("CustomCancelButton", selectionDialog).Click(); }; var contextMenu = info.ContextMenuStrip(nodeData, parentData, treeViewControl); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs =================================================================== diff -u -rc2117f62d195ac85d35d4f983822acf401b66647 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision c2117f62d195ac85d35d4f983822acf401b66647) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingCalculationsViewTest.cs (.../PipingCalculationsViewTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -44,7 +44,7 @@ namespace Ringtoets.Piping.Forms.Test.Views { [TestFixture] - public class PipingCalculationsViewTest + public class PipingCalculationsViewTest : NUnitFormTest { private Form testForm; @@ -470,6 +470,89 @@ } [Test] + public void GivenPipingCalculationsView_WhenGenerateScenariosButtonClicked_ThenShowViewWithSurfaceLines() + { + // Given + var pipingCalculationsView = ShowPipingCalculationsView(); + var pipingFailureMechanism = new Data.Piping + { + SurfaceLines = + { + new RingtoetsPipingSurfaceLine(), + new RingtoetsPipingSurfaceLine() + }, + StochasticSoilModels = + { + new TestStochasticSoilModel() + } + }; + pipingCalculationsView.Piping = pipingFailureMechanism; + pipingCalculationsView.Data = pipingFailureMechanism.CalculationsGroup; + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + PipingSurfaceLineSelectionDialog selectionDialog = null; + DataGridView grid = null; + DialogBoxHandler = (name, wnd) => + { + selectionDialog = new FormTester(name).TheObject as PipingSurfaceLineSelectionDialog; + grid = new ControlTester("SurfaceLineDataGrid", selectionDialog).TheObject as DataGridView; + + new ButtonTester("CustomCancelButton", selectionDialog).Click(); + }; + + // When + button.Click(); + + // Then + Assert.NotNull(selectionDialog); + Assert.NotNull(grid); + Assert.AreEqual(2, grid.RowCount); + } + + [Test] + [TestCase("OkButton")] + [TestCase("CustomCancelButton")] + public void GivenPipingCalculationsViewGenerateScenariosButtonClicked_WhenDialogClosed_ThenNotifyCalculationGroup(string buttonName) + { + // Given + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var pipingCalculationsView = ShowPipingCalculationsView(); + var pipingFailureMechanism = new Data.Piping + { + SurfaceLines = + { + new RingtoetsPipingSurfaceLine(), + new RingtoetsPipingSurfaceLine() + }, + StochasticSoilModels = + { + new TestStochasticSoilModel() + } + }; + pipingCalculationsView.Piping = pipingFailureMechanism; + pipingCalculationsView.Data = pipingFailureMechanism.CalculationsGroup; + pipingFailureMechanism.CalculationsGroup.Attach(observer); + var button = new ButtonTester("buttonGenerateScenarios", testForm); + + DialogBoxHandler = (name, wnd) => + { + var selectionDialog = new FormTester(name).TheObject as PipingSurfaceLineSelectionDialog; + + // When + new ButtonTester(buttonName, selectionDialog).Click(); + }; + + button.Click(); + + // Then + mocks.VerifyAll(); + } + + [Test] public void GivenFailureMechanismWithoutSurfaceLinesAndSoilModels_WhenAddSoilModelAndNotify_ThenButtonDisabled() { // Given Index: Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs =================================================================== diff -u -ra9aafffab97152303562110b1d789bacb465ce24 -rfc38d18fc6ff1749476da0ea43281d5d80568283 --- Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs (.../PipingCalculationsViewIntegrationTest.cs) (revision a9aafffab97152303562110b1d789bacb465ce24) +++ Ringtoets/Piping/test/Ringtoets.Piping.Integration.Test/PipingCalculationsViewIntegrationTest.cs (.../PipingCalculationsViewIntegrationTest.cs) (revision fc38d18fc6ff1749476da0ea43281d5d80568283) @@ -148,7 +148,7 @@ using (var hydraulicBoundaryDatabaseImporter = new HydraulicBoundaryDatabaseImporter()) { hydraulicBoundaryDatabaseImporter.ValidateAndConnectTo(Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "HRD dutch coast south.sqlite")); - hydraulicBoundaryDatabaseImporter.Import(new HydraulicBoundaryDatabaseContext(assessmentSection)); + hydraulicBoundaryDatabaseImporter.Import(assessmentSection); } } }