Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs
===================================================================
diff -u -rb190a14336e0d8fe9aec34e81a68194081c76155 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision b190a14336e0d8fe9aec34e81a68194081c76155)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -235,7 +235,7 @@
var failureMechanismSection = collector.Get(sectionResultEntity.FailureMechanismSectionEntity);
var result = failureMechanism.SectionResults.Single(sr => ReferenceEquals(sr.Section, failureMechanismSection));
- sectionResultEntity.Read(result);
+ sectionResultEntity.Read(result, collector);
}
}
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensions.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensions.cs (.../GrassCoverErosionInwardsSectionResultEntityReadExtensions.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/GrassCoverErosionInwardsSectionResultEntityReadExtensions.cs (.../GrassCoverErosionInwardsSectionResultEntityReadExtensions.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -40,7 +40,7 @@
/// The target of the read operation.
/// The object keeping track of read operations.
/// A new .
- /// Thrown when is null.
+ /// Thrown when any input parameter is null.
internal static void Read(this GrassCoverErosionInwardsSectionResultEntity entity, GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult, ReadConversionCollector collector)
{
if (collector == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs
===================================================================
diff -u -rfc8042d95d25d97f3e8a85fdd557771f718229f8 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (.../HeightStructuresCalculationEntityReadExtensions.cs) (revision fc8042d95d25d97f3e8a85fdd557771f718229f8)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensions.cs (.../HeightStructuresCalculationEntityReadExtensions.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -49,6 +49,10 @@
{
throw new ArgumentNullException("collector");
}
+ if (collector.Contains(entity))
+ {
+ return collector.Get(entity);
+ }
var calculation = new StructuresCalculation
{
@@ -63,6 +67,8 @@
calculation.Output = output.Read();
}
+ collector.Read(entity, calculation);
+
return calculation;
}
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensions.cs
===================================================================
diff -u -rcc91baaea7dfcc12765017b57ffc768c7d02f7a1 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensions.cs (.../HeightStructuresSectionResultEntityReadExtensions.cs) (revision cc91baaea7dfcc12765017b57ffc768c7d02f7a1)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensions.cs (.../HeightStructuresSectionResultEntityReadExtensions.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -27,27 +27,39 @@
namespace Application.Ringtoets.Storage.Read.HeightStructures
{
///
- /// This class defines extension methods for read operations for a based on the
- /// .
+ /// This class defines extension methods for read operations for a
+ /// based on the .
///
internal static class HeightStructuresSectionResultEntityReadExtensions
{
///
- /// Reads the and use the information to construct a
- /// .
+ /// Reads the and use the information
+ /// to construct a .
///
- /// The to create for.
+ /// The to
+ /// create for.
/// The target of the read operation.
+ /// The object keeping track of read operations.
/// A new .
- /// Thrown when is null.
- internal static void Read(this HeightStructuresSectionResultEntity entity, HeightStructuresFailureMechanismSectionResult sectionResult)
+ /// Thrown when any input parameter is null.
+ internal static void Read(this HeightStructuresSectionResultEntity entity, HeightStructuresFailureMechanismSectionResult sectionResult,
+ ReadConversionCollector collector)
{
if (sectionResult == null)
{
throw new ArgumentNullException("sectionResult");
}
+ if (collector == null)
+ {
+ throw new ArgumentNullException("collector");
+ }
sectionResult.AssessmentLayerOne = Convert.ToBoolean(entity.LayerOne);
sectionResult.AssessmentLayerThree = (RoundedDouble) entity.LayerThree.ToNullAsNaN();
+
+ if (entity.HeightStructuresCalculationEntity != null)
+ {
+ sectionResult.Calculation = entity.HeightStructuresCalculationEntity.Read(collector);
+ }
}
}
}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs
===================================================================
diff -u -r41a37c93cb0b3e36ff7023c9f42b4e6225598b55 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 41a37c93cb0b3e36ff7023c9f42b4e6225598b55)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -26,6 +26,7 @@
using Ringtoets.ClosingStructures.Data;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.Structures;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HydraRing.Data;
@@ -54,6 +55,7 @@
private readonly Dictionary heightStructures = CreateDictionary();
private readonly Dictionary closingStructures = CreateDictionary();
private readonly Dictionary stabilityPointStructures = CreateDictionary();
+ private readonly Dictionary> heightStructuresCalculations = CreateDictionary>();
private static Dictionary CreateDictionary()
{
@@ -852,6 +854,77 @@
#endregion
+ #region HeightStructuresCalculationEntity: Read, Contains, Get
+
+ ///
+ /// Registers a read operation for
+ /// and the that was constructed
+ /// with the information.
+ ///
+ /// The
+ /// that was read.
+ /// The that
+ /// was constructed.
+ /// Thrown when any input parameter is null.
+ internal void Read(HeightStructuresCalculationEntity entity, StructuresCalculation model)
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException("entity");
+ }
+ if (model == null)
+ {
+ throw new ArgumentNullException("model");
+ }
+
+ heightStructuresCalculations[entity] = model;
+ }
+
+ ///
+ /// Checks whether a read operation has been registered for a given .
+ ///
+ /// The to check for.
+ /// true if the was read before, false otherwise.
+ /// Thrown when is null.
+ internal bool Contains(HeightStructuresCalculationEntity entity)
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException("entity");
+ }
+ return heightStructuresCalculations.ContainsKey(entity);
+ }
+
+ ///
+ /// Obtains the which was read
+ /// for the given .
+ ///
+ /// The for which a read
+ /// operation has been registered.
+ /// The constructed .
+ /// Thrown when is null.
+ /// Thrown when no read operation has
+ /// been registered for .
+ /// Use
+ /// to find out whether a read operation has been registered for .
+ internal StructuresCalculation Get(HeightStructuresCalculationEntity entity)
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException("entity");
+ }
+ try
+ {
+ return heightStructuresCalculations[entity];
+ }
+ catch (KeyNotFoundException e)
+ {
+ throw new InvalidOperationException(e.Message, e);
+ }
+ }
+
+ #endregion
+
#region ClosingStructureEntity: Read, Contains, Get
///
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs
===================================================================
diff -u -rfc8042d95d25d97f3e8a85fdd557771f718229f8 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (.../HeightStructuresCalculationEntityReadExtensionsTest.cs) (revision fc8042d95d25d97f3e8a85fdd557771f718229f8)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresCalculationEntityReadExtensionsTest.cs (.../HeightStructuresCalculationEntityReadExtensionsTest.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -184,6 +184,30 @@
Assert.IsTrue(calculation.HasOutput);
}
+ [Test]
+ public void Read_CalculationEntityAlreadyRead_ReturnReadCalculation()
+ {
+ // Setup
+ var entity = new HeightStructuresCalculationEntity
+ {
+ HeightStructuresOutputEntities =
+ {
+ new HeightStructuresOutputEntity()
+ }
+ };
+
+ var calculation = new StructuresCalculation();
+
+ var collector = new ReadConversionCollector();
+ collector.Read(entity, calculation);
+
+ // Call
+ StructuresCalculation returnedCalculation = entity.Read(collector);
+
+ // Assert
+ Assert.AreSame(calculation, returnedCalculation);
+ }
+
private static void AssertRoundedDouble(double? entityValue, RoundedDouble roundedDouble)
{
Assert.AreEqual((RoundedDouble) entityValue.ToNullAsNaN(), roundedDouble, roundedDouble.GetAccuracy());
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs
===================================================================
diff -u -rfdd03cdaf7c9eed6fccaa5aa591f71deddcb2b74 -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs (.../HeightStructuresSectionResultEntityReadExtensionsTest.cs) (revision fdd03cdaf7c9eed6fccaa5aa591f71deddcb2b74)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HeightStructures/HeightStructuresSectionResultEntityReadExtensionsTest.cs (.../HeightStructuresSectionResultEntityReadExtensionsTest.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -25,6 +25,7 @@
using Application.Ringtoets.Storage.Read.HeightStructures;
using Application.Ringtoets.Storage.TestUtil;
using NUnit.Framework;
+using Ringtoets.Common.Data.Structures;
using Ringtoets.HeightStructures.Data;
namespace Application.Ringtoets.Storage.Test.Read.HeightStructures
@@ -39,14 +40,29 @@
var entity = new HeightStructuresSectionResultEntity();
// Call
- TestDelegate call = () => entity.Read(null);
+ TestDelegate call = () => entity.Read(null, new ReadConversionCollector());
// Assert
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("sectionResult", paramName);
}
[Test]
+ public void Read_CollectorIsNull_ThrowArgumentNullException()
+ {
+ // Setup
+ var entity = new HeightStructuresSectionResultEntity();
+
+ // Call
+ TestDelegate call = () => entity.Read(new HeightStructuresFailureMechanismSectionResult(
+ new TestFailureMechanismSection()), null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("collector", paramName);
+ }
+
+ [Test]
[TestCase(true)]
[TestCase(false)]
public void Read_WithDecimalParameterValues_ReturnHeightStructuresSectionResultWithDoubleParameterValues(bool layerOne)
@@ -67,12 +83,14 @@
var sectionResult = new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection());
// Call
- entity.Read(sectionResult);
+ entity.Read(sectionResult, collector);
// Assert
Assert.AreEqual(layerOne, sectionResult.AssessmentLayerOne);
Assert.AreEqual(layerThree, sectionResult.AssessmentLayerThree, 1e-6);
Assert.IsNotNull(sectionResult);
+
+ Assert.IsNull(sectionResult.Calculation);
}
[Test]
@@ -91,10 +109,37 @@
var sectionResult = new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection());
// Call
- entity.Read(sectionResult);
+ entity.Read(sectionResult, collector);
// Assert
Assert.IsNaN(sectionResult.AssessmentLayerThree);
}
+
+ [Test]
+ public void Read_CalculationEntitySet_ReturnHeightStructuresSectionResultWithCalculation()
+ {
+ // Setup
+ var calculation = new StructuresCalculation();
+
+ var failureMechanismSectionEntity = new FailureMechanismSectionEntity();
+ var calculationEntity = new HeightStructuresCalculationEntity();
+
+ var collector = new ReadConversionCollector();
+ collector.Read(failureMechanismSectionEntity, new TestFailureMechanismSection());
+ collector.Read(calculationEntity, calculation);
+
+ var entity = new HeightStructuresSectionResultEntity
+ {
+ FailureMechanismSectionEntity = failureMechanismSectionEntity,
+ HeightStructuresCalculationEntity = calculationEntity
+ };
+ var sectionResult = new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection());
+
+ // Call
+ entity.Read(sectionResult, collector);
+
+ // Assert
+ Assert.AreSame(calculation, sectionResult.Calculation);
+ }
}
}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs
===================================================================
diff -u -ra3906d39b799530a0e38750705dc49abaa037c9d -r04cb34562587c9b06345f2e639c57394e6a7d0a7
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision a3906d39b799530a0e38750705dc49abaa037c9d)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7)
@@ -28,6 +28,7 @@
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.Data.TestUtil;
using Ringtoets.Common.Data.DikeProfiles;
+using Ringtoets.Common.Data.Structures;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Data.TestUtil;
@@ -1849,5 +1850,154 @@
}
#endregion
+
+ #region HeightStructuresCalculationEntity: Read, Contains, Get
+
+ [Test]
+ public void Contains_WithoutHeightStructuresCalculationEntity_ThrowsArgumentNullException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+
+ // Call
+ TestDelegate test = () => collector.Contains((HeightStructuresCalculationEntity) null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("entity", paramName);
+ }
+
+ [Test]
+ public void Contains_HeightStructuresCalculationEntityAdded_ReturnsTrue()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var entity = new HeightStructuresCalculationEntity();
+ collector.Read(entity, new StructuresCalculation());
+
+ // Call
+ var result = collector.Contains(entity);
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void Contains_NoHeightStructuresCalculationEntityAdded_ReturnsFalse()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var entity = new HeightStructuresCalculationEntity();
+
+ // Call
+ var result = collector.Contains(entity);
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void Contains_OtherHeightStructuresCalculationEntityAdded_ReturnsFalse()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var entity = new HeightStructuresCalculationEntity();
+ collector.Read(new HeightStructuresCalculationEntity(), new StructuresCalculation());
+
+ // Call
+ var result = collector.Contains(entity);
+
+ // Assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void Get_WithoutHeightStructuresCalculationEntity_ThrowsArgumentNullException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+
+ // Call
+ TestDelegate test = () => collector.Get((HeightStructuresCalculationEntity) null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("entity", paramName);
+ }
+
+ [Test]
+ public void Get_HeightStructuresCalculationEntityAdded_ReturnsHeightStructuresCalculation()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var calculation = new StructuresCalculation();
+ var entity = new HeightStructuresCalculationEntity();
+ collector.Read(entity, calculation);
+
+ // Call
+ var result = collector.Get(entity);
+
+ // Assert
+ Assert.AreSame(calculation, result);
+ }
+
+ [Test]
+ public void Get_NoHeightStructuresCalculationEntityAdded_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var entity = new HeightStructuresCalculationEntity();
+
+ // Call
+ TestDelegate test = () => collector.Get(entity);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void Get_OtherHeightStructuresCalculationEntityAdded_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+ var entity = new HeightStructuresCalculationEntity();
+ collector.Read(new HeightStructuresCalculationEntity(), new StructuresCalculation());
+
+ // Call
+ TestDelegate test = () => collector.Get(entity);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void Read_WithNullHeightStructuresCalculationEntity_ThrowsArgumentNullException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+
+ // Call
+ TestDelegate test = () => collector.Read(null, new StructuresCalculation());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("entity", paramName);
+ }
+
+ [Test]
+ public void Read_WithNullHeightStructuresCalculation_ThrowsArgumentNullException()
+ {
+ // Setup
+ var collector = new ReadConversionCollector();
+
+ // Call
+ TestDelegate test = () => collector.Read(new HeightStructuresCalculationEntity(), null);
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("model", paramName);
+ }
+
+ #endregion
}
}
\ No newline at end of file