Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -r3ce69e451a97f622288b172d1dcef1ac3fbc9bc1 -r4729996da3de69c24738bc39a0ee95fb3909e0c8 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 3ce69e451a97f622288b172d1dcef1ac3fbc9bc1) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 4729996da3de69c24738bc39a0ee95fb3909e0c8) @@ -116,10 +116,6 @@ {D951D6DA-FE83-4920-9FDB-63BF96480B54} Ringtoets.Common.Service - - {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} - Ringtoets.Common.Utils - {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs =================================================================== diff -u -r3ce69e451a97f622288b172d1dcef1ac3fbc9bc1 -r4729996da3de69c24738bc39a0ee95fb3909e0c8 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs (.../RingtoetsCommonDataSynchronizationServicesTest.cs) (revision 3ce69e451a97f622288b172d1dcef1ac3fbc9bc1) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataSynchronizationServicesTest.cs (.../RingtoetsCommonDataSynchronizationServicesTest.cs) (revision 4729996da3de69c24738bc39a0ee95fb3909e0c8) @@ -24,14 +24,14 @@ using Core.Common.Base; using Core.Common.Base.Geometry; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Utils; using Enumerable = System.Linq.Enumerable; namespace Ringtoets.Common.Service.Test @@ -116,11 +116,8 @@ [Test] public void ClearCalculationOutput_CalculationNull_ThrowsArgumentNullException() { - // Setup - StructuresCalculation calculation = null; - // Call - TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); + TestDelegate test = () => RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(null); // Assert var exception = Assert.Throws(test); @@ -131,18 +128,19 @@ public void ClearCalculationOutput_WithCalculation_ClearsOutput() { // Setup - var calculation = new StructuresCalculation - { - Output = new ProbabilityAssessmentOutput(1, 1, 1, 1, 1) - }; + var mocks = new MockRepository(); + var calculation = mocks.StrictMock(); + calculation.Expect(c => c.HasOutput).Return(true); + calculation.Expect(c => c.ClearOutput()); + mocks.ReplayAll(); // Call IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: - Assert.IsNull(calculation.Output); + mocks.VerifyAll(); CollectionAssert.AreEqual(new[] { @@ -154,16 +152,18 @@ public void ClearCalculationOutput_CalculationWithoutOutput_DoNothing() { // Setup - var calculation = new StructuresCalculation - { - Output = null - }; + var mocks = new MockRepository(); + var calculation = mocks.StrictMock(); + calculation.Expect(c => c.HasOutput).Return(false); + mocks.ReplayAll(); // Call IEnumerable changedObjects = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation); // Assert CollectionAssert.IsEmpty(changedObjects); + + mocks.VerifyAll(); } [Test] @@ -173,21 +173,21 @@ var foreshoreProfileToBeRemoved = new TestForeshoreProfile(new Point2D(0, 0)); var foreshoreProfile = new TestForeshoreProfile(new Point2D(1, 1)); - var calculation1 = new StructuresCalculation + var calculation1 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfile } }; - var calculation2 = new StructuresCalculation + var calculation2 = new StructuresCalculation { InputParameters = { ForeshoreProfile = foreshoreProfileToBeRemoved } }; - var calculation3 = new StructuresCalculation + var calculation3 = new StructuresCalculation { InputParameters = { @@ -203,7 +203,7 @@ }; // Call - IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile( + IEnumerable affectedObjects = RingtoetsCommonDataSynchronizationService.ClearForeshoreProfile( calculations, foreshoreProfileToBeRemoved); // Assert @@ -454,51 +454,30 @@ CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } - private class TestInput : ICalculationInput + private class TestSectionResult : StructuresFailureMechanismSectionResult { - public void Attach(IObserver observer) + public TestSectionResult(Point2D point2D) : base(new FailureMechanismSection($"Location {point2D}", new[] { - throw new NotImplementedException(); - } - - public void Detach(IObserver observer) - { - throw new NotImplementedException(); - } - - public void NotifyObservers() - { - throw new NotImplementedException(); - } + point2D, + point2D + })) + { } } - private class SimpleStructuresInput : StructuresInputBase + private class TestStructureInput : StructuresInputBase { - protected override void UpdateStructureParameters() {} + protected override void UpdateStructureParameters() { } } - } - public class TestSectionResult : StructuresFailureMechanismSectionResult - { - public TestSectionResult(Point2D point2D) : base(new FailureMechanismSection($"Location {point2D}", new[] + private class TestStructure : StructureBase { - point2D, - point2D - })) {} + public TestStructure(string id, Point2D location) : base(new ConstructionProperties + { + Name = $"{id} name", + Id = id, + Location = location + }) + { } + } } - - public class TestStructureInput : StructuresInputBase - { - protected override void UpdateStructureParameters() {} - } - - public class TestStructure : StructureBase - { - public TestStructure(string id, Point2D location) : base(new ConstructionProperties - { - Name = $"{id} name", - Id = id, - Location = location - }) {} - } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs =================================================================== diff -u -r5f48c2f099a9ffd0e55b86aea0b356a226a1918f -r4729996da3de69c24738bc39a0ee95fb3909e0c8 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision 5f48c2f099a9ffd0e55b86aea0b356a226a1918f) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.IO/StabilityPointStructuresImporter.cs (.../StabilityPointStructuresImporter.cs) (revision 4729996da3de69c24738bc39a0ee95fb3909e0c8) @@ -24,12 +24,15 @@ using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.Base.IO; +using Core.Common.Base.Properties; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; 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 { /// @@ -54,12 +57,21 @@ protected override void CreateSpecificStructures(ICollection structureLocations, Dictionary> groupedStructureParameterRows) { - IEnumerable importedStabilityPointStructures = CreateStabilityPointStructures(structureLocations.ToList(), groupedStructureParameterRows); + IEnumerable importedStabilityPointStructures = + CreateStabilityPointStructures(structureLocations.ToList(), groupedStructureParameterRows).ToArray(); - foreach (StabilityPointStructure stabilityPointStructure in importedStabilityPointStructures) + IEnumerable knownIds = ImportTarget.Select(t => t.Id).Intersect(importedStabilityPointStructures.Select(s => s.Id)).ToArray(); + if (knownIds.Any()) { - ImportTarget.Add(stabilityPointStructure); + string duplicateFeatures = string.Join(", ", knownIds); + string exceptionMessage = string.Format( + Resources.ObservableUniqueItemCollectionWithSourcePath_ValidateItems_TypeDescriptor_0_must_have_unique_FeatureDescription_1_Found_duplicate_items_DuplicateFeatures_2, + RingtoetsCommonDataResources.StructureCollection_TypeDescriptor, + RingtoetsCommonDataResources.StructureCollection_UniqueFeature_id_FeatureDescription, + duplicateFeatures); + throw new UpdateDataException(exceptionMessage); } + ImportTarget.AddRange(importedStabilityPointStructures); } private IEnumerable CreateStabilityPointStructures(IEnumerable structureLocations, Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.IO.Test/StabilityPointStructuresImporterTest.cs =================================================================== diff -u -r5f48c2f099a9ffd0e55b86aea0b356a226a1918f -r4729996da3de69c24738bc39a0ee95fb3909e0c8 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.IO.Test/StabilityPointStructuresImporterTest.cs (.../StabilityPointStructuresImporterTest.cs) (revision 5f48c2f099a9ffd0e55b86aea0b356a226a1918f) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.IO.Test/StabilityPointStructuresImporterTest.cs (.../StabilityPointStructuresImporterTest.cs) (revision 4729996da3de69c24738bc39a0ee95fb3909e0c8) @@ -33,6 +33,7 @@ using Ringtoets.Common.IO.FileImporters; using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Data.TestUtil; namespace Ringtoets.StabilityPointStructures.IO.Test { @@ -276,6 +277,45 @@ DistributionAssert.AreEqual(defaultStructure.AreaFlowApertures, importedStructure.AreaFlowApertures); } + [Test] + public void Import_StructureWithSameIdAlreadyImporterd_FalseAndImportTargetNotUpdated() + { + // Setup + var messageProvider = mocks.Stub(); + var errorText = "Failed"; + messageProvider.Stub(m => m.GetUpdateDataFailedLogMessageText(null)).IgnoreArguments().Return(errorText); + messageProvider.Stub(m => m.GetAddDataToModelProgressText()).Return("Progress"); + mocks.ReplayAll(); + + string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpRandomCaseHeaderCsv", "Kunstwerken.shp"); + + var referencePoints = new List + { + new Point2D(154493.618, 568995.991), + new Point2D(156844.169, 574771.498), + new Point2D(157910.502, 579115.458), + new Point2D(163625.153, 585151.261) + }; + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(referencePoints); + var importTarget = new ObservableList + { + new TestStabilityPointStructure("KWK_3"), + new TestStabilityPointStructure("KWK_4") + }; + var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider); + + var importResult = true; + + // Call + Action import = () => importResult = structuresImporter.Import(); + + // Assert + TestHelper.AssertLogMessageWithLevelIsGenerated(import, Tuple.Create(errorText, LogLevelConstant.Error)); + Assert.IsFalse(importResult); + Assert.AreEqual(2, importTarget.Count); + } + private static ReferenceLine CreateReferenceLine() { var referencePoints = new List