Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs =================================================================== diff -u -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 -r968ff30159efb3fbf0a698100bfcf6aaff83fa7e --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs (.../IHydraulicLocationConfigurationDatabaseImportHandler.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs (.../IHydraulicLocationConfigurationDatabaseImportHandler.cs) (revision 968ff30159efb3fbf0a698100bfcf6aaff83fa7e) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.Integration.Forms.PropertyClasses @@ -35,6 +36,7 @@ /// The /// to update. /// The file path to import the data from. + /// Thrown when any parameter is null. void OnNewFilePathSet(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, string hlcdFilePath); } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs =================================================================== diff -u -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 -r968ff30159efb3fbf0a698100bfcf6aaff83fa7e --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs (.../HydraulicLocationConfigurationDatabaseImportHandler.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs (.../HydraulicLocationConfigurationDatabaseImportHandler.cs) (revision 968ff30159efb3fbf0a698100bfcf6aaff83fa7e) @@ -20,8 +20,13 @@ // All rights reserved. using System; +using System.Windows.Forms; +using Core.Common.Base.Service; +using Core.Common.Gui.Forms.ProgressDialog; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Integration.Forms.PropertyClasses; +using Ringtoets.Integration.IO.Handlers; +using Ringtoets.Integration.IO.Importers; namespace Ringtoets.Integration.Plugin.Handlers { @@ -30,9 +35,51 @@ /// public class HydraulicLocationConfigurationDatabaseImportHandler : IHydraulicLocationConfigurationDatabaseImportHandler { + private readonly IWin32Window viewParent; + private readonly IHydraulicLocationConfigurationDatabaseUpdateHandler updateHandler; + + /// + /// Creates a new instance of . + /// + /// The parent of the view. + /// The object responsible for updating the . + /// Thrown when any argument is null. + public HydraulicLocationConfigurationDatabaseImportHandler(IWin32Window viewParent, + IHydraulicLocationConfigurationDatabaseUpdateHandler updateHandler) + { + if (viewParent == null) + { + throw new ArgumentNullException(nameof(viewParent)); + } + + if (updateHandler == null) + { + throw new ArgumentNullException(nameof(updateHandler)); + } + + this.viewParent = viewParent; + this.updateHandler = updateHandler; + } + public void OnNewFilePathSet(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, string hlcdFilePath) { - throw new NotImplementedException(); + if (hydraulicBoundaryDatabase == null) + { + throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); + } + + if (hlcdFilePath == null) + { + throw new ArgumentNullException(nameof(hlcdFilePath)); + } + + var importSettingsActivity = new FileImportActivity( + new HydraulicLocationConfigurationDatabaseImporter(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings, + updateHandler, + hydraulicBoundaryDatabase, + hlcdFilePath), + string.Empty); + ActivityProgressDialogRunner.Run(viewParent, importSettingsActivity); } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 -r968ff30159efb3fbf0a698100bfcf6aaff83fa7e --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 968ff30159efb3fbf0a698100bfcf6aaff83fa7e) @@ -89,6 +89,7 @@ using Ringtoets.Integration.Forms.Views.SectionResultRows; using Ringtoets.Integration.Forms.Views.SectionResultViews; using Ringtoets.Integration.IO.Exporters; +using Ringtoets.Integration.IO.Importers; using Ringtoets.Integration.Plugin.FileImporters; using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.Integration.Plugin.Merge; @@ -112,7 +113,6 @@ using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; using GuiResources = Core.Common.Gui.Properties.Resources; -using HydraulicBoundaryDatabaseImporter = Ringtoets.Integration.IO.Importers.HydraulicBoundaryDatabaseImporter; namespace Ringtoets.Integration.Plugin { @@ -303,7 +303,9 @@ }; yield return new PropertyInfo { - CreateInstance = context => new HydraulicBoundaryDatabaseProperties(context.WrappedData, new HydraulicLocationConfigurationDatabaseImportHandler()) + CreateInstance = context => new HydraulicBoundaryDatabaseProperties(context.WrappedData, + new HydraulicLocationConfigurationDatabaseImportHandler(Gui.MainWindow, + new HydraulicLocationConfigurationDatabaseUpdateHandler(context.AssessmentSection))) }; yield return new PropertyInfo { @@ -457,7 +459,10 @@ context.AssessmentSection, context.GetNormFunc, context.CategoryBoundaryName), - AfterCreate = (view, context) => { view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; } + AfterCreate = (view, context) => + { + view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; + } }; yield return new ViewInfo, WaveHeightCalculationsView> @@ -471,7 +476,10 @@ context.AssessmentSection, context.GetNormFunc, context.CategoryBoundaryName), - AfterCreate = (view, context) => { view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; } + AfterCreate = (view, context) => + { + view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; + } }; yield return new ViewInfo @@ -1736,7 +1744,10 @@ RingtoetsCommonFormsResources.Calculate_All, Resources.AssessmentSection_Calculate_All_ToolTip, RingtoetsCommonFormsResources.CalculateAllIcon, - (sender, args) => { ActivityProgressDialogRunner.Run(Gui.MainWindow, AssessmentSectionCalculationActivityFactory.CreateActivities(nodeData)); }); + (sender, args) => + { + ActivityProgressDialogRunner.Run(Gui.MainWindow, AssessmentSectionCalculationActivityFactory.CreateActivities(nodeData)); + }); var importItem = new StrictContextMenuItem( GuiResources.Import, Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs =================================================================== diff -u -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 -r968ff30159efb3fbf0a698100bfcf6aaff83fa7e --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs (.../HydraulicLocationConfigurationDatabaseImportHandlerTest.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs (.../HydraulicLocationConfigurationDatabaseImportHandlerTest.cs) (revision 968ff30159efb3fbf0a698100bfcf6aaff83fa7e) @@ -19,23 +19,154 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows.Forms; +using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabase; +using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.PropertyClasses; +using Ringtoets.Integration.IO.Handlers; using Ringtoets.Integration.Plugin.Handlers; +using Ringtoets.Integration.TestUtil; namespace Ringtoets.Integration.Plugin.Test.Handlers { [TestFixture] public class HydraulicLocationConfigurationDatabaseImportHandlerTest { + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Plugin); + private static readonly string testDataDirectory = Path.Combine(testDataPath, nameof(HydraulicLocationConfigurationDatabaseImportHandler)); + [Test] + public void Constructor_ViewParentNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var updateHandler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new HydraulicLocationConfigurationDatabaseImportHandler(null, updateHandler); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("viewParent", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_UpdateHandlerNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var viewParent = mocks.Stub(); + var updateHandler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new HydraulicLocationConfigurationDatabaseImportHandler(viewParent, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("updateHandler", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] public void Constructor_ExpectedValues() { + // Setup + var mocks = new MockRepository(); + var viewParent = mocks.Stub(); + var updateHandler = mocks.Stub(); + mocks.ReplayAll(); + // Call - var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(); + var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(viewParent, updateHandler); // Assert Assert.IsInstanceOf(importHandler); + mocks.VerifyAll(); } + + [Test] + public void OnNewFilePathSet_HydraulicBoundaryDatabaseNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var viewParent = mocks.Stub(); + var updateHandler = mocks.Stub(); + mocks.ReplayAll(); + + var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(viewParent, updateHandler); + + // Call + TestDelegate call = () => importHandler.OnNewFilePathSet(null, string.Empty); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hydraulicBoundaryDatabase", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void OnNewFilePathSet_HlcdFilePathNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var viewParent = mocks.Stub(); + var updateHandler = mocks.Stub(); + mocks.ReplayAll(); + + var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(viewParent, updateHandler); + + // Call + TestDelegate call = () => importHandler.OnNewFilePathSet(new HydraulicBoundaryDatabase(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hlcdFilePath", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void OnNewFilePathSet_WithValidFilePath_SetsHydraulicLocationConfigurationDatabaseSettings() + { + // Setup + string newHlcdFilePath = Path.Combine(testDataDirectory, "hlcdWithScenarioInformation.sqlite"); + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + DataImportHelper.ImportHydraulicBoundaryDatabase(assessmentSection, + Path.Combine(testDataDirectory, "complete.sqlite")); + + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; + + var mocks = new MockRepository(); + var viewParent = mocks.Stub(); + var updateHandler = mocks.StrictMock(); + updateHandler.Expect(uh => uh.InquireConfirmation()).Return(true); + updateHandler.Expect(uh => uh.Update(Arg.Is.Same(hydraulicBoundaryDatabase), + Arg.Is.NotNull, + Arg.Is.Equal(newHlcdFilePath))) + .WhenCalled(invoke => + { + Assert.AreEqual(1, (IEnumerable) invoke.Arguments[1]); + }); + mocks.ReplayAll(); + + var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(viewParent, updateHandler); + + // Call + importHandler.OnNewFilePathSet(hydraulicBoundaryDatabase, newHlcdFilePath); + + // Assert + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/test-data/HydraulicLocationConfigurationDatabaseImportHandler/HLCD.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/test-data/HydraulicLocationConfigurationDatabaseImportHandler/complete.config.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/test-data/HydraulicLocationConfigurationDatabaseImportHandler/complete.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/test-data/HydraulicLocationConfigurationDatabaseImportHandler/hlcdWithScenarioInformation.sqlite =================================================================== diff -u Binary files differ