Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs =================================================================== diff -u -r9fc9b8a4905a7420454e1bde2279f90d954501db -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs (.../HydraulicBoundaryDatabaseProperties.cs) (revision 9fc9b8a4905a7420454e1bde2279f90d954501db) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/HydraulicBoundaryDatabaseProperties.cs (.../HydraulicBoundaryDatabaseProperties.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -51,19 +51,28 @@ private const int usePreprocessorPropertyIndex = 11; private const int preprocessorDirectoryPropertyIndex = 12; + private readonly IHydraulicLocationConfigurationDatabaseImportHandler hydraulicLocationConfigurationDatabaseImportHandler; + /// /// Creates a new instance of . /// /// The hydraulic boundary database to show the properties for. - /// Thrown when - /// is null. - public HydraulicBoundaryDatabaseProperties(HydraulicBoundaryDatabase hydraulicBoundaryDatabase) + /// The handler to update the hydraulic location configuration settings. + /// Thrown when any parameter is null. + public HydraulicBoundaryDatabaseProperties(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, + IHydraulicLocationConfigurationDatabaseImportHandler hydraulicLocationConfigurationDatabaseImportHandler) { if (hydraulicBoundaryDatabase == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); } + if (hydraulicLocationConfigurationDatabaseImportHandler == null) + { + throw new ArgumentNullException(nameof(hydraulicLocationConfigurationDatabaseImportHandler)); + } + + this.hydraulicLocationConfigurationDatabaseImportHandler = hydraulicLocationConfigurationDatabaseImportHandler; Data = hydraulicBoundaryDatabase; } @@ -83,12 +92,17 @@ [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.HydraulicLocationConfigurationSettings_FilePath_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.HydraulicLocationConfigurationSettings_FilePath_Description))] + [Editor(typeof(FolderNameEditor), typeof(UITypeEditor))] public string HlcdFilePath { get { - return data.HydraulicLocationConfigurationSettings.FilePath ?? string.Empty; + return data.HydraulicLocationConfigurationSettings.FilePath ?? string.Empty; } + set + { + hydraulicLocationConfigurationDatabaseImportHandler.OnNewFilePathSet(data, value); + } } [PropertyOrder(scenarioNamePropertyIndex)] @@ -148,7 +162,6 @@ get { return data.HydraulicLocationConfigurationSettings.RiverDischarge ?? string.Empty; - } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/IHydraulicLocationConfigurationDatabaseImportHandler.cs (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -0,0 +1,40 @@ +// Copyright (C) Stichting Deltares 2018. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using Ringtoets.Common.Data.Hydraulics; + +namespace Ringtoets.Integration.Forms.PropertyClasses +{ + /// + /// Interface for an object that can properly import a . + /// + public interface IHydraulicLocationConfigurationDatabaseImportHandler + { + /// + /// Imports the information from the + /// and updates the . + /// + /// The + /// to update. + /// The file path to import the data from. + void OnNewFilePathSet(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, string hlcdFilePath); + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r65fe0d5aa5f9ecb431c41da8f2a4a96137cd57da -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 65fe0d5aa5f9ecb431c41da8f2a4a96137cd57da) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -82,6 +82,7 @@ + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseImportHandler.cs (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -0,0 +1,38 @@ +// Copyright (C) Stichting Deltares 2018. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Integration.Forms.PropertyClasses; + +namespace Ringtoets.Integration.Plugin.Handlers +{ + /// + /// Class that can properly import . + /// + public class HydraulicLocationConfigurationDatabaseImportHandler : IHydraulicLocationConfigurationDatabaseImportHandler + { + public void OnNewFilePathSet(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, string hlcdFilePath) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj =================================================================== diff -u -r3ef793ff9988c152c373edf9a821bb50e88db36f -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 3ef793ff9988c152c373edf9a821bb50e88db36f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -37,6 +37,7 @@ + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r1f1993456901354dd2eba30de8469139157f8bd0 -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 1f1993456901354dd2eba30de8469139157f8bd0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -303,7 +303,7 @@ }; yield return new PropertyInfo { - CreateInstance = context => new HydraulicBoundaryDatabaseProperties(context.WrappedData) + CreateInstance = context => new HydraulicBoundaryDatabaseProperties(context.WrappedData, new HydraulicLocationConfigurationDatabaseImportHandler()) }; yield return new PropertyInfo { Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs =================================================================== diff -u -r91b1add51add98f13fcb62329808ed838d07d371 -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs (.../HydraulicBoundaryDatabasePropertiesTest.cs) (revision 91b1add51add98f13fcb62329808ed838d07d371) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/HydraulicBoundaryDatabasePropertiesTest.cs (.../HydraulicBoundaryDatabasePropertiesTest.cs) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.ComponentModel; using Core.Common.Base; using Core.Common.Gui.PropertyBag; @@ -48,17 +49,53 @@ private const int preprocessorDirectoryPropertyIndex = 12; [Test] + public void Constructor_HydraulicBoundaryDatabaseNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => new HydraulicBoundaryDatabaseProperties(null, importHandler); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hydraulicBoundaryDatabase", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_HydraulicLocationConfigurationDatabaseImportHandlerNull_ThrowsArgumentNullException() + { + // Setup + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + // Call + TestDelegate call = () => new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("hydraulicLocationConfigurationDatabaseImportHandler", exception.ParamName); + } + + [Test] public void Constructor_ExpectedValues() { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert Assert.IsInstanceOf>(properties); Assert.AreSame(hydraulicBoundaryDatabase, properties.Data); + mocks.VerifyAll(); } [Test] @@ -68,6 +105,10 @@ const bool usePreprocessor = true; const string preprocessorDirectory = @"C:\preprocessor"; + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { CanUsePreprocessor = true, @@ -76,25 +117,30 @@ }; // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert Assert.AreEqual(usePreprocessor, properties.UsePreprocessor); Assert.AreEqual(preprocessorDirectory, properties.PreprocessorDirectory); Assert.AreEqual(preprocessorDirectory, properties.PreprocessorDirectoryReadOnly); + mocks.VerifyAll(); } [Test] public void GetProperties_WithUnlinkedDatabase_ReturnsExpectedValues() { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); // Precondition Assert.IsFalse(hydraulicBoundaryDatabase.IsLinked()); // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert Assert.IsEmpty(properties.HrdFilePath); @@ -108,19 +154,24 @@ Assert.IsEmpty(properties.WindDirection); Assert.IsEmpty(properties.WindSpeed); Assert.IsEmpty(properties.Comment); + mocks.VerifyAll(); } [Test] public void GetProperties_WithLinkedDatabase_ReturnsExpectedValues() { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + HydraulicBoundaryDatabase hydraulicBoundaryDatabase = CreateLinkedHydraulicBoundaryDatabase(); // Precondition Assert.IsTrue(hydraulicBoundaryDatabase.IsLinked()); // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert Assert.AreEqual(hydraulicBoundaryDatabase.FilePath, properties.HrdFilePath); @@ -136,6 +187,7 @@ Assert.AreEqual(configurationSettings.WindDirection, properties.WindDirection); Assert.AreEqual(configurationSettings.WindSpeed, properties.WindSpeed); Assert.AreEqual(configurationSettings.Comment, properties.Comment); + mocks.VerifyAll(); } [Test] @@ -144,6 +196,10 @@ public void Constructor_CanUsePreprocessorTrue_PropertiesHaveExpectedAttributesValues(bool usePreprocessor) { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { CanUsePreprocessor = true, @@ -152,7 +208,7 @@ }; // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); @@ -248,16 +304,21 @@ "Locatie preprocessor bestanden", "Locatie waar de preprocessor bestanden opslaat.", !usePreprocessor); + mocks.VerifyAll(); } [Test] public void Constructor_CanUsePreprocessorFalse_PropertiesHaveExpectedAttributesValues() { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); @@ -340,17 +401,19 @@ "Overig", "Overige informatie.", true); + mocks.VerifyAll(); } [Test] - public void UsePreprocessor_SetNewValue_ValueSetToHydraulicBoundaryDatabaseAndObserversNotified([Values(true, false)] bool usePreprocessor) + [TestCase(true)] + [TestCase(false)] + public void UsePreprocessor_SetNewValue_ValueSetToHydraulicBoundaryDatabaseAndObserversNotified(bool usePreprocessor) { // Setup var mocks = new MockRepository(); + var importHandler = mocks.Stub(); var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); - mocks.ReplayAll(); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase @@ -360,7 +423,7 @@ PreprocessorDirectory = "Preprocessor" }; - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); hydraulicBoundaryDatabase.Attach(observer); @@ -376,6 +439,10 @@ public void PreprocessorDirectory_SetNewValue_ValueSetToHydraulicBoundaryDatabase() { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + const string newPreprocessorDirectory = @"C:/path"; var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { @@ -384,21 +451,48 @@ PreprocessorDirectory = "Preprocessor" }; - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Call properties.PreprocessorDirectory = newPreprocessorDirectory; // Assert Assert.AreEqual(newPreprocessorDirectory, hydraulicBoundaryDatabase.PreprocessorDirectory); + mocks.VerifyAll(); } [Test] + public void HlcdFilePath_SetNewValue_CallsHydraulicLocationConfigurationDatabaseImportHandler() + { + // Setup + const string hlcdFilePath = @"C:/path/HlcdFilePath"; + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var mocks = new MockRepository(); + var importHandler = mocks.StrictMock(); + importHandler.Expect(ih => ih.OnNewFilePathSet(hydraulicBoundaryDatabase, hlcdFilePath)); + mocks.ReplayAll(); + + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); + + // Call + properties.HlcdFilePath = hlcdFilePath; + + // Assert + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] public void DynamicVisibleValidationMethod_DependingOnCanUsePreprocessorAndUsePreprocessor_ReturnExpectedVisibility( [Values(true, false)] bool canUsePreprocessor, [Values(true, false)] bool usePreprocessor) { // Setup + var mocks = new MockRepository(); + var importHandler = mocks.Stub(); + mocks.ReplayAll(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); if (canUsePreprocessor) @@ -409,13 +503,14 @@ } // Call - var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase); + var properties = new HydraulicBoundaryDatabaseProperties(hydraulicBoundaryDatabase, importHandler); // Assert Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.HrdFilePath))); Assert.AreEqual(canUsePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.UsePreprocessor))); Assert.AreEqual(canUsePreprocessor && usePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectory))); Assert.AreEqual(canUsePreprocessor && !usePreprocessor, properties.DynamicVisibleValidationMethod(nameof(properties.PreprocessorDirectoryReadOnly))); + mocks.VerifyAll(); } private static HydraulicBoundaryDatabase CreateLinkedHydraulicBoundaryDatabase() Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/HydraulicLocationConfigurationDatabaseImportHandlerTest.cs (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -0,0 +1,41 @@ +// Copyright (C) Stichting Deltares 2018. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using NUnit.Framework; +using Ringtoets.Integration.Forms.PropertyClasses; +using Ringtoets.Integration.Plugin.Handlers; + +namespace Ringtoets.Integration.Plugin.Test.Handlers +{ + [TestFixture] + public class HydraulicLocationConfigurationDatabaseImportHandlerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var importHandler = new HydraulicLocationConfigurationDatabaseImportHandler(); + + // Assert + Assert.IsInstanceOf(importHandler); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r3ef793ff9988c152c373edf9a821bb50e88db36f -r9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 3ef793ff9988c152c373edf9a821bb50e88db36f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 9d11b4cca5a37e2ac37fe22b6c8a46c93631d4e1) @@ -58,6 +58,7 @@ +