Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs =================================================================== diff -u -r41a37c93cb0b3e36ff7023c9f42b4e6225598b55 -r0c84eb5ded5af71c3982410db8d00ad4fcc572bd --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 41a37c93cb0b3e36ff7023c9f42b4e6225598b55) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PersistenceRegistry.cs (.../PersistenceRegistry.cs) (revision 0c84eb5ded5af71c3982410db8d00ad4fcc572bd) @@ -27,6 +27,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; @@ -56,6 +57,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() { @@ -308,6 +310,20 @@ Register(stabilityPointStructures, entity, model); } + /// + /// Registers a create operation for and the + /// that was constructed with the information. + /// + /// The + /// to be registered. + /// The to + /// be registered. + /// Thrown when any input parameter is null. + internal void Register(HeightStructuresCalculationEntity entity, StructuresCalculation model) + { + Register(heightStructuresCalculations, entity, model); + } + #endregion #region Contains Methods @@ -444,6 +460,17 @@ return ContainsValue(stabilityPointStructures, model); } + /// + /// Checks whether a create operations has been registered for the given . + /// + /// The to check for. + /// true if the was registered before, false otherwise. + /// Thrown when is null. + internal bool Contains(StructuresCalculation model) + { + return ContainsValue(heightStructuresCalculations, model); + } + #endregion #region Get Methods @@ -649,6 +676,23 @@ return Get(stabilityPointStructures, model); } + /// + /// Obtains the which was + /// registered for the given . + /// + /// The for + /// which a read operation has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no create operation + /// has been registered for . + /// Use to find out + /// whether a create operation has been registered for . + internal HeightStructuresCalculationEntity Get(StructuresCalculation model) + { + return Get(heightStructuresCalculations, model); + } + #endregion } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -r41a37c93cb0b3e36ff7023c9f42b4e6225598b55 -r0c84eb5ded5af71c3982410db8d00ad4fcc572bd --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 41a37c93cb0b3e36ff7023c9f42b4e6225598b55) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 0c84eb5ded5af71c3982410db8d00ad4fcc572bd) @@ -29,6 +29,7 @@ using Ringtoets.ClosingStructures.Data.TestUtil; 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.HeightStructures.Data.TestUtil; @@ -649,7 +650,7 @@ var registry = new PersistenceRegistry(); // Call - TestDelegate call = () => registry.Contains((ClosingStructure)null); + TestDelegate call = () => registry.Contains((ClosingStructure) null); // Assert string paramName = Assert.Throws(call).ParamName; @@ -710,7 +711,7 @@ var registry = new PersistenceRegistry(); // Call - TestDelegate call = () => registry.Contains((StabilityPointStructure)null); + TestDelegate call = () => registry.Contains((StabilityPointStructure) null); // Assert string paramName = Assert.Throws(call).ParamName; @@ -764,6 +765,67 @@ Assert.IsFalse(result); } + [Test] + public void Contains_WithoutHeightStructuresCalculation_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => registry.Contains((StructuresCalculation) null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_HeightStructuresCalculationAdded_ReturnsTrue() + { + // Setup + var calculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + registry.Register(new HeightStructuresCalculationEntity(), calculation); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_OtherHeightStructuresCalculationAdded_ReturnsFalse() + { + // Setup + var calculation = new StructuresCalculation(); + + var otherCalculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + registry.Register(new HeightStructuresCalculationEntity(), otherCalculation); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_NoHeightStructuresCalculationAdded_ReturnsFalse() + { + // Setup + var calculation = new StructuresCalculation(); + + var registry = new PersistenceRegistry(); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsFalse(result); + } + #endregion #region Get methods @@ -1381,7 +1443,7 @@ var registry = new PersistenceRegistry(); // Call - TestDelegate call = () => registry.Get((StabilityPointStructure)null); + TestDelegate call = () => registry.Get((StabilityPointStructure) null); // Assert string paramName = Assert.Throws(call).ParamName; @@ -1437,6 +1499,69 @@ Assert.AreSame(registeredEntity, retrievedEntity); } + [Test] + public void Get_WithoutHeightStructuresCalculation_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => registry.Get((StructuresCalculation) null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Get_NoHeightStructuresCalculationAdded_ThrowsInvalidOperationException() + { + // Setup + var calculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => registry.Get(calculation); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Get_OtherHeightStructuresCalculationAdded_ThrowsInvalidOperationException() + { + // Setup + var calculation = new StructuresCalculation(); + var registeredCalculation = new StructuresCalculation(); + var registeredEntity = new HeightStructuresCalculationEntity(); + + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, registeredCalculation); + + // Call + TestDelegate call = () => registry.Get(calculation); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Get_HeightStructuresCalculationAdded_ReturnsEntity() + { + // Setup + var calculation = new StructuresCalculation(); + var registeredEntity = new HeightStructuresCalculationEntity(); + + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, calculation); + + // Call + HeightStructuresCalculationEntity retrievedEntity = registry.Get(calculation); + + // Assert + Assert.AreSame(registeredEntity, retrievedEntity); + } + #endregion #region Register methods @@ -1682,7 +1807,6 @@ Assert.AreEqual("model", paramName); } - [Test] public void Register_WithNullStabilityPointStructure_ThrowsArgumentNullException() { @@ -1697,6 +1821,20 @@ Assert.AreEqual("model", paramName); } + [Test] + public void Register_WithNullHeightStructuresCalculation_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new HeightStructuresCalculationEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + #endregion } } \ No newline at end of file