Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -r56a1b0ad79756583461f17301d0edcd79a1d0de4 -r1ea7670876fef947ed0481b9c19e5b26893352a6
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 56a1b0ad79756583461f17301d0edcd79a1d0de4)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1ea7670876fef947ed0481b9c19e5b26893352a6)
@@ -1038,6 +1038,16 @@
}
///
+ /// Looks up a localized string similar to Het importeren van kunstwerken is mislukt: {0}.
+ ///
+ public static string IStructureUpdateStrategy_UpdateStructuresWithImportedData_Importing_Structures_failed_Reason_0 {
+ get {
+ return ResourceManager.GetString("IStructureUpdateStrategy_UpdateStructuresWithImportedData_Importing_Structures_fa" +
+ "iled_Reason_0", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Een gemiddelde van '{0}' is ongeldig voor stochast '{1}'..
///
public static string IVariationCoefficientDistributionExtensions_TrySetMean_Mean_0_is_invalid_for_Stochast_1_ {
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u -r56a1b0ad79756583461f17301d0edcd79a1d0de4 -r1ea7670876fef947ed0481b9c19e5b26893352a6
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 56a1b0ad79756583461f17301d0edcd79a1d0de4)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 1ea7670876fef947ed0481b9c19e5b26893352a6)
@@ -643,4 +643,7 @@
Er is geen kunstwerk opgegeven om de stochast '{0}' aan toe te voegen.
+
+ Het importeren van kunstwerken is mislukt: {0}
+
\ No newline at end of file
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureReplaceDataStrategy.cs
===================================================================
diff -u -r8b389428ece343431969fce2e902a7b241f2b372 -r1ea7670876fef947ed0481b9c19e5b26893352a6
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureReplaceDataStrategy.cs (.../HeightStructureReplaceDataStrategy.cs) (revision 8b389428ece343431969fce2e902a7b241f2b372)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureReplaceDataStrategy.cs (.../HeightStructureReplaceDataStrategy.cs) (revision 1ea7670876fef947ed0481b9c19e5b26893352a6)
@@ -26,6 +26,7 @@
using Ringtoets.Common.Data.Exceptions;
using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Common.IO.Exceptions;
+using Ringtoets.Common.IO.Properties;
using Ringtoets.Common.IO.Structures;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Service;
@@ -48,15 +49,17 @@
: base(failureMechanism) {}
public IEnumerable UpdateStructuresWithImportedData(StructureCollection targetDataCollection,
- IEnumerable readStructures, string sourceFilePath)
+ IEnumerable readStructures,
+ string sourceFilePath)
{
try
{
return ReplaceTargetCollectionWithImportedData(targetDataCollection, readStructures, sourceFilePath);
}
catch (UpdateDataException e)
{
- string message = string.Format("Het importeren van kunstwerken is mislukt: {0}", e.Message);
+ string message = string.Format(Resources.IStructureUpdateStrategy_UpdateStructuresWithImportedData_Importing_Structures_failed_Reason_0,
+ e.Message);
throw new StructureUpdateException(message, e);
}
}
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureReplaceDataStrategyTest.cs
===================================================================
diff -u -r8b389428ece343431969fce2e902a7b241f2b372 -r1ea7670876fef947ed0481b9c19e5b26893352a6
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureReplaceDataStrategyTest.cs (.../HeightStructureReplaceDataStrategyTest.cs) (revision 8b389428ece343431969fce2e902a7b241f2b372)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureReplaceDataStrategyTest.cs (.../HeightStructureReplaceDataStrategyTest.cs) (revision 1ea7670876fef947ed0481b9c19e5b26893352a6)
@@ -23,9 +23,15 @@
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
+using Core.Common.Base.Geometry;
using NUnit.Framework;
using Ringtoets.Common.Data;
+using Ringtoets.Common.Data.Exceptions;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.Structures;
+using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Data.UpdateDataStrategies;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.Structures;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Data.TestUtil;
@@ -119,9 +125,10 @@
const string newSourcePath = "some/other/path";
// Call
- IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(targetCollection,
- Enumerable.Empty(),
- newSourcePath);
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ targetCollection,
+ Enumerable.Empty(),
+ newSourcePath);
// Assert
CollectionAssert.AreEqual(new IObservable[]
@@ -136,7 +143,7 @@
public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure()
{
// Setup
- var importedHeightStructures = new[]
+ var importedStructures = new[]
{
new TestHeightStructure()
};
@@ -145,18 +152,188 @@
var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);
// Call
- IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(failureMechanism.HeightStructures,
- importedHeightStructures,
- sourceFilePath);
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ failureMechanism.HeightStructures,
+ importedStructures,
+ sourceFilePath);
// Assert
StructureCollection actualCollection = failureMechanism.HeightStructures;
- CollectionAssert.AreEqual(importedHeightStructures, actualCollection);
+ CollectionAssert.AreEqual(importedStructures, actualCollection);
CollectionAssert.AreEqual(new[]
{
actualCollection
}, affectedObjects);
Assert.AreEqual(sourceFilePath, actualCollection.SourcePath);
}
+
+ [Test]
+ public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData()
+ {
+ // Setup
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ failureMechanism.HeightStructures.AddRange(new[]
+ {
+ new TestHeightStructure("Original", "id")
+ }, sourceFilePath);
+
+ var importedStructure = new TestHeightStructure("Imported", "Different id");
+
+ var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+
+ // Call
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ failureMechanism.HeightStructures,
+ new[]
+ {
+ importedStructure
+ }, sourceFilePath);
+
+ // Assert
+ CollectionAssert.AreEqual(new[]
+ {
+ failureMechanism.HeightStructures
+ }, affectedObjects);
+
+ var expected = new[]
+ {
+ importedStructure
+ };
+ CollectionAssert.AreEqual(expected, failureMechanism.HeightStructures);
+ }
+
+ [Test]
+ public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject()
+ {
+ // Setup
+ var structure = new TestHeightStructure();
+
+ var calculation = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structure
+ },
+ Output = new TestStructuresOutput()
+ };
+
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
+ failureMechanism.HeightStructures.AddRange(new[]
+ {
+ structure
+ }, sourceFilePath);
+
+ var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+
+ // Call
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ failureMechanism.HeightStructures,
+ Enumerable.Empty(),
+ sourceFilePath).ToArray();
+
+ // Assert
+ Assert.IsFalse(calculation.HasOutput);
+ Assert.IsNull(calculation.InputParameters.Structure);
+ CollectionAssert.AreEquivalent(new IObservable[]
+ {
+ calculation,
+ calculation.InputParameters,
+ failureMechanism.HeightStructures
+ }, affectedObjects);
+ }
+
+ [Test]
+ public void UpdateStructuresWithImportedData_CalculationWithSectionResultAndStructure_DataUpdatedAndReturnsAffectedObject()
+ {
+ // Setup
+ var location = new Point2D(1, 1);
+ var structure = new TestHeightStructure(location);
+
+ var calculation = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structure
+ }
+ };
+
+ var failureMechanism = new HeightStructuresFailureMechanism
+ {
+ CalculationsGroup =
+ {
+ Children =
+ {
+ calculation
+ }
+ }
+ };
+
+ failureMechanism.AddSection(new FailureMechanismSection("SectionResult", new[]
+ {
+ location
+ }));
+ HeightStructuresFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults.First();
+ sectionResult.Calculation = calculation;
+
+ failureMechanism.HeightStructures.AddRange(new[]
+ {
+ structure
+ }, sourceFilePath);
+
+ var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+
+ // Call
+ IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(
+ failureMechanism.HeightStructures,
+ Enumerable.Empty(),
+ sourceFilePath).ToArray();
+
+ // Assert
+ Assert.IsNull(sectionResult.Calculation);
+ Assert.IsNull(calculation.InputParameters.Structure);
+ CollectionAssert.AreEquivalent(new IObservable[]
+ {
+ calculation.InputParameters,
+ sectionResult,
+ failureMechanism.HeightStructures
+ }, affectedObjects);
+ }
+
+ [Test]
+ public void UpdateStructuresWithImportedData_ImportedDataContainsDuplicateIds_ThrowsUpdateException()
+ {
+ // Setup
+ const string duplicateId = "I am a duplicate id";
+ HeightStructure[] importedHeightStructures =
+ {
+ new TestHeightStructure("name", duplicateId),
+ new TestHeightStructure("Other name", duplicateId)
+ };
+
+ var targetCollection = new StructureCollection();
+ var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());
+
+ // Call
+ TestDelegate call = () => strategy.UpdateStructuresWithImportedData(targetCollection,
+ importedHeightStructures,
+ sourceFilePath);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ string expectedMessage = "Het importeren van kunstwerken is mislukt: " +
+ "Kunstwerken moeten een unieke id hebben. " +
+ $"Gevonden dubbele elementen: {duplicateId}.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
}
}
\ No newline at end of file