Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs (.../ClosingStructuresImporter.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/ClosingStructuresImporter.cs (.../ClosingStructuresImporter.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data; @@ -39,8 +38,6 @@ /// public class ClosingStructuresImporter : StructuresImporter { - private readonly IStructureUpdateStrategy structureUpdateStrategy; - /// /// Creates a new instance of . /// @@ -56,27 +53,11 @@ string filePath, IImporterMessageProvider messageProvider, IStructureUpdateStrategy updateStrategy) - : base(importTarget, referenceLine, filePath, messageProvider, updateStrategy) - { - if (updateStrategy == null) - { - throw new ArgumentNullException(nameof(updateStrategy)); - } - structureUpdateStrategy = updateStrategy; - } + : base(importTarget, referenceLine, filePath, messageProvider, updateStrategy) {} - protected override IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows) + protected override IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) { - return structureUpdateStrategy.UpdateStructuresWithImportedData(ImportTarget, - CreateClosingStructures(structureLocations.ToList(), - groupedStructureParameterRows), - FilePath); - } - - private IEnumerable CreateClosingStructures(IEnumerable structureLocations, - IDictionary> groupedStructureParameterRows) - { var closingStructures = new List(); foreach (StructureLocation structureLocation in structureLocations) { Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -52,6 +52,7 @@ { private readonly ReferenceLine referenceLine; private readonly IImporterMessageProvider messageProvider; + private readonly IStructureUpdateStrategy structureUpdateStrategy; private IEnumerable updatedInstances; /// @@ -85,6 +86,7 @@ this.referenceLine = referenceLine; this.messageProvider = messageProvider; + this.structureUpdateStrategy = structureUpdateStrategy; } protected override bool OnImport() @@ -137,17 +139,6 @@ base.DoPostImportUpdates(); } - /// - /// Create structure objects from location and geometry data and use this to update the current data model. - /// - /// The read structure locations. - /// The read structure parameters, grouped by location identifier. - /// Collection of all objects that were changed due to the update. - /// Thrown when the validation of the structure fails. - /// Thrown when updating the structures failed. - protected abstract IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows); - protected RoundedDouble GetStandardDeviation(StructuresParameterRow structuresParameterRow, string structureName) { if (structuresParameterRow.VarianceType == VarianceType.CoefficientOfVariation) @@ -198,6 +189,9 @@ } } + protected abstract IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows); + private string GetStructureDataCsvFilePath() { return Path.ChangeExtension(FilePath, ".csv"); @@ -372,5 +366,21 @@ { return Math2D.ConvertLinePointsToLineSegments(linePoints); } + + /// + /// Updates the import target with the imported structures. + /// + /// The read structure locations. + /// The read structure properties. + /// An with affected items. + /// Thrown when applying the strategy failed. + private IEnumerable UpdateWithCreatedStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) + { + return structureUpdateStrategy.UpdateStructuresWithImportedData(ImportTarget, + CreateStructures(structureLocations.ToList(), + groupedStructureParameterRows), + FilePath); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -595,6 +595,52 @@ } [Test] + public void Import_ValidImportFile_CallsUpdateStrategyWithExpectedArguments() + { + // Setup + var targetCollection = new StructureCollection(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", + "Kunstwerken.shp")); + + var createdStructures = new[] + { + new TestStructure() + }; + + var messageProvider = mocks.Stub(); + var updateStrategy = mocks.StrictMock>(); + updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .WhenCalled(i => + { + Assert.AreSame(targetCollection, i.Arguments[0]); + Assert.AreSame(createdStructures, i.Arguments[1]); + Assert.AreSame(filePath, i.Arguments[2]); + }); + mocks.ReplayAll(); + + ReferenceLine referenceLine = CreateReferenceLine(); + + var importer = new TestStructuresImporter(targetCollection, + referenceLine, + filePath, + updateStrategy, + messageProvider) + { + CreatedTestStructures = createdStructures + }; + + // Call + importer.Import(); + + // Assert + Assert.IsTrue(importer.CreateStructuresCalled); + + // Further assertions done in the TearDown + } + + [Test] public void Import_IllegalCsvFile_ReturnsFalse() { // Setup @@ -627,6 +673,9 @@ messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(""); messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText("Kunstwerken")).Return("error {0}"); var updateStrategy = mocks.Stub>(); + updateStrategy.Expect(us => us.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .Throw(new UpdateDataException("Exception message")); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, @@ -638,10 +687,7 @@ referenceLine, filePath, updateStrategy, - messageProvider) - { - UpdateWithCreatedStructuresAction = () => { throw new UpdateDataException("Exception message"); } - }; + messageProvider); var importResult = true; @@ -659,31 +705,33 @@ { // Setup var messageProvider = mocks.Stub(); - var updateStrategy = mocks.Stub>(); + var observableA = mocks.StrictMock(); observableA.Expect(o => o.NotifyObservers()); var observableB = mocks.StrictMock(); observableB.Expect(o => o.NotifyObservers()); + + var updateStrategy = mocks.StrictMock>(); + updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .Return(new[] + { + observableA, + observableB + }); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); ReferenceLine referenceLine = CreateReferenceLine(); - IObservable[] observables = - { - observableA, - observableB - }; + var importer = new TestStructuresImporter(new StructureCollection(), referenceLine, filePath, updateStrategy, - messageProvider) - { - UpdateWithCreatedStructuresAction = () => observables - }; + messageProvider); importer.Import(); @@ -884,15 +932,17 @@ private class TestStructuresImporter : StructuresImporter { - public Func> UpdateWithCreatedStructuresAction; - public TestStructuresImporter(StructureCollection importTarget, ReferenceLine referenceLine, string filePath, IStructureUpdateStrategy structureUpdateStrategy, IImporterMessageProvider messageProvider) : base(importTarget, referenceLine, filePath, messageProvider, structureUpdateStrategy) {} + public IEnumerable CreatedTestStructures { private get; set; } = Enumerable.Empty(); + + public bool CreateStructuresCalled { get; private set; } + public new RoundedDouble GetStandardDeviation(StructuresParameterRow parameter, string structureName) { return base.GetStandardDeviation(parameter, structureName); @@ -903,10 +953,12 @@ return base.GetCoefficientOfVariation(parameter, structureName); } - protected override IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows) + protected override IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) { - return UpdateWithCreatedStructuresAction?.Invoke(); + CreateStructuresCalled = true; + + return CreatedTestStructures; } } } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; @@ -39,8 +38,6 @@ /// public class HeightStructuresImporter : StructuresImporter { - private readonly IStructureUpdateStrategy structureUpdateStrategy; - /// /// Creates a new instance of . /// @@ -54,27 +51,11 @@ public HeightStructuresImporter(StructureCollection importTarget, ReferenceLine referenceLine, string filePath, IImporterMessageProvider messageProvider, IStructureUpdateStrategy structureUpdateStrategy) - : base(importTarget, referenceLine, filePath, messageProvider, structureUpdateStrategy) - { - if (structureUpdateStrategy == null) - { - throw new ArgumentNullException(nameof(structureUpdateStrategy)); - } - this.structureUpdateStrategy = structureUpdateStrategy; - } + : base(importTarget, referenceLine, filePath, messageProvider, structureUpdateStrategy) {} - protected override IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows) + protected override IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) { - return structureUpdateStrategy.UpdateStructuresWithImportedData(ImportTarget, - CreateHeightStructures(structureLocations.ToList(), - groupedStructureParameterRows), - FilePath); - } - - private IEnumerable CreateHeightStructures(IEnumerable structureLocations, - IDictionary> groupedStructureParameterRows) - { var heightStructures = new List(); foreach (StructureLocation structureLocation in structureLocations) { Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -22,15 +22,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO.FileImporters; using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Structures; using Ringtoets.StabilityPointStructures.Data; -using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.StabilityPointStructures.IO { @@ -40,8 +38,6 @@ /// public class StabilityPointStructuresImporter : StructuresImporter { - private readonly IStructureUpdateStrategy structureUpdateStrategy; - /// /// Creates a new instance of . /// @@ -57,23 +53,11 @@ string filePath, IImporterMessageProvider messageProvider, IStructureUpdateStrategy updateStrategy) - : base(importTarget, referenceLine, filePath, messageProvider, updateStrategy) - { - structureUpdateStrategy = updateStrategy; - } + : base(importTarget, referenceLine, filePath, messageProvider, updateStrategy) {} - protected override IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows) + protected override IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) { - return structureUpdateStrategy.UpdateStructuresWithImportedData(ImportTarget, - CreateStabilityPointStructures(structureLocations.ToList(), - groupedStructureParameterRows), - FilePath); - } - - private IEnumerable CreateStabilityPointStructures(IEnumerable structureLocations, - IDictionary> groupedStructureParameterRows) - { var stabilityPointStructures = new List(); foreach (StructureLocation structureLocation in structureLocations) {