Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs =================================================================== diff -u -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 -r4f89601cb9d77ff379727afd64f902a0aff74fa3 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs (.../ClosingStructuresCalculationEntityReadExtensions.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensions.cs (.../ClosingStructuresCalculationEntityReadExtensions.cs) (revision 4f89601cb9d77ff379727afd64f902a0aff74fa3) @@ -20,11 +20,10 @@ // All rights reserved. using System; +using System.Linq; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; using Ringtoets.ClosingStructures.Data; -using Ringtoets.Common.Data; -using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; namespace Application.Ringtoets.Storage.Read.ClosingStructures @@ -58,6 +57,12 @@ }; ReadInputParameters(calculation.InputParameters, entity, collector); + ClosingStructuresOutputEntity output = entity.ClosingStructuresOutputEntities.FirstOrDefault(); + if (output != null) + { + calculation.Output = output.Read(); + } + return calculation; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs =================================================================== diff -u -r04cb34562587c9b06345f2e639c57394e6a7d0a7 -r4f89601cb9d77ff379727afd64f902a0aff74fa3 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 4f89601cb9d77ff379727afd64f902a0aff74fa3) @@ -56,6 +56,7 @@ private readonly Dictionary closingStructures = CreateDictionary(); private readonly Dictionary stabilityPointStructures = CreateDictionary(); private readonly Dictionary> heightStructuresCalculations = CreateDictionary>(); + private readonly Dictionary> closingStructuresCalculations = CreateDictionary>(); private static Dictionary CreateDictionary() { @@ -997,6 +998,77 @@ #endregion + #region ClosingStructuresCalculationEntity: 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(ClosingStructuresCalculationEntity entity, StructuresCalculation model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + closingStructuresCalculations[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(ClosingStructuresCalculationEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + return closingStructuresCalculations.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(ClosingStructuresCalculationEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return closingStructuresCalculations[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion + #region StabilityPointStructureEntity: Read, Contains, Get /// Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs =================================================================== diff -u -r21b2f912e42c334efafdf907ad6f0c14b84187be -r4f89601cb9d77ff379727afd64f902a0aff74fa3 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision 21b2f912e42c334efafdf907ad6f0c14b84187be) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision 4f89601cb9d77ff379727afd64f902a0aff74fa3) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Linq; using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.TestUtil; @@ -164,7 +165,7 @@ Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); - Assert.IsFalse(calculation.HasOutput); + Assert.IsFalse(entity.HeightStructuresOutputEntities.Any()); } [Test] @@ -524,7 +525,7 @@ Assert.AreEqual(inputParameters.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); Assert.AreEqual(order, entity.Order); - Assert.IsFalse(calculation.HasOutput); + Assert.IsFalse(entity.ClosingStructuresOutputEntities.Any()); } [Test] Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs =================================================================== diff -u -r4b095752c115dd672400da5a4acc1560e4c9ce2c -r4f89601cb9d77ff379727afd64f902a0aff74fa3 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs (.../ClosingStructuresCalculationEntityReadExtensionsTest.cs) (revision 4b095752c115dd672400da5a4acc1560e4c9ce2c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ClosingStructures/ClosingStructuresCalculationEntityReadExtensionsTest.cs (.../ClosingStructuresCalculationEntityReadExtensionsTest.cs) (revision 4f89601cb9d77ff379727afd64f902a0aff74fa3) @@ -37,7 +37,7 @@ public class ClosingStructuresCalculationEntityReadExtensionsTest { [Test] - public void Read_ReadConversionColletorNull_ThrowArugumentNullException() + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() { // Setup var entity = new ClosingStructuresCalculationEntity(); @@ -141,6 +141,7 @@ Assert.AreEqual(entity.LevelCrestStructureNotClosingMean, inputParameters.LevelCrestStructureNotClosing.Mean.Value); Assert.AreEqual(entity.LevelCrestStructureNotClosingStandardDeviation, inputParameters.LevelCrestStructureNotClosing.StandardDeviation.Value); Assert.AreEqual(entity.ProbabilityOpenStructureBeforeFlooding, inputParameters.ProbabilityOpenStructureBeforeFlooding); + Assert.IsFalse(calculation.HasOutput); } [Test] @@ -272,5 +273,26 @@ // Assert Assert.AreSame(profile, calculation.InputParameters.ForeshoreProfile); } + + [Test] + public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput() + { + // Setup + var entity = new ClosingStructuresCalculationEntity + { + ClosingStructuresOutputEntities = + { + new ClosingStructuresOutputEntity() + } + }; + + var collector = new ReadConversionCollector(); + + // Call + StructuresCalculation calculation = entity.Read(collector); + + // Assert + Assert.IsTrue(calculation.HasOutput); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs =================================================================== diff -u -r04cb34562587c9b06345f2e639c57394e6a7d0a7 -r4f89601cb9d77ff379727afd64f902a0aff74fa3 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 04cb34562587c9b06345f2e639c57394e6a7d0a7) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 4f89601cb9d77ff379727afd64f902a0aff74fa3) @@ -1999,5 +1999,154 @@ } #endregion + + #region ClosingStructuresCalculationEntity: Read, Contains, Get + + [Test] + public void Contains_WithoutClosingStructuresCalculationEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Contains((ClosingStructuresCalculationEntity) null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_ClosingStructuresCalculationEntityAdded_ReturnsTrue() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new ClosingStructuresCalculationEntity(); + collector.Read(entity, new StructuresCalculation()); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoClosingStructuresCalculationEntityAdded_ReturnsFalse() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new ClosingStructuresCalculationEntity(); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherClosingStructuresCalculationEntityAdded_ReturnsFalse() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new ClosingStructuresCalculationEntity(); + collector.Read(new ClosingStructuresCalculationEntity(), new StructuresCalculation()); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_WithoutClosingStructuresCalculationEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Get((ClosingStructuresCalculationEntity) null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_ClosingStructuresCalculationEntityAdded_ReturnsClosingStructuresCalculation() + { + // Setup + var collector = new ReadConversionCollector(); + var calculation = new StructuresCalculation(); + var entity = new ClosingStructuresCalculationEntity(); + collector.Read(entity, calculation); + + // Call + var result = collector.Get(entity); + + // Assert + Assert.AreSame(calculation, result); + } + + [Test] + public void Get_NoClosingStructuresCalculationEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new ClosingStructuresCalculationEntity(); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherClosingStructuresCalculationEntityAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new ClosingStructuresCalculationEntity(); + collector.Read(new ClosingStructuresCalculationEntity(), new StructuresCalculation()); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Read_WithNullClosingStructuresCalculationEntity_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_WithNullClosingStructuresCalculation_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(new ClosingStructuresCalculationEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + #endregion } } \ No newline at end of file