Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -r15b08c6afb3375830f4cfa1bff8150e828d6e66e -r21b2f912e42c334efafdf907ad6f0c14b84187be --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 15b08c6afb3375830f4cfa1bff8150e828d6e66e) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 21b2f912e42c334efafdf907ad6f0c14b84187be) @@ -826,6 +826,66 @@ Assert.IsFalse(result); } + [Test] + public void Contains_WithoutClosingStructuresCalculation_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_ClosingStructuresCalculationAdded_ReturnsTrue() + { + // Setup + var calculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + registry.Register(new ClosingStructuresCalculationEntity(), calculation); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_OtherClosingStructuresCalculationAdded_ReturnsFalse() + { + // Setup + var calculation = new StructuresCalculation(); + + var otherCalculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + registry.Register(new ClosingStructuresCalculationEntity(), otherCalculation); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_NoClosingStructuresCalculationAdded_ReturnsFalse() + { + // Setup + var calculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + + // Call + bool result = registry.Contains(calculation); + + // Assert + Assert.IsFalse(result); + } + #endregion #region Get methods @@ -1562,6 +1622,69 @@ Assert.AreSame(registeredEntity, retrievedEntity); } + [Test] + public void Get_WithoutClosingStructuresCalculation_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_NoClosingStructuresCalculationAdded_ThrowsInvalidOperationException() + { + // Setup + var calculation = new StructuresCalculation(); + var registry = new PersistenceRegistry(); + + // Call + TestDelegate call = () => registry.Get(calculation); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Get_OtherClosingStructuresCalculationAdded_ThrowsInvalidOperationException() + { + // Setup + var calculation = new StructuresCalculation(); + var registeredCalculation = new StructuresCalculation(); + var registeredEntity = new ClosingStructuresCalculationEntity(); + + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, registeredCalculation); + + // Call + TestDelegate call = () => registry.Get(calculation); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Get_ClosingStructuresCalculationAdded_ReturnsEntity() + { + // Setup + var calculation = new StructuresCalculation(); + var registeredEntity = new ClosingStructuresCalculationEntity(); + + var registry = new PersistenceRegistry(); + registry.Register(registeredEntity, calculation); + + // Call + ClosingStructuresCalculationEntity retrievedEntity = registry.Get(calculation); + + // Assert + Assert.AreSame(registeredEntity, retrievedEntity); + } + #endregion #region Register methods @@ -1877,6 +2000,34 @@ Assert.AreEqual("model", paramName); } + [Test] + public void Register_WithNullClosingStructuresCalculationEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new TestClosingStructuresCalculation()); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullClosingStructuresCalculation_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new ClosingStructuresCalculationEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + #endregion } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs =================================================================== diff -u -rbce62ec6102f15b0dbb1328fd9d14063fd21c978 -r21b2f912e42c334efafdf907ad6f0c14b84187be --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision bce62ec6102f15b0dbb1328fd9d14063fd21c978) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/StructuresCalculationCreateExtensionsTest.cs (.../StructuresCalculationCreateExtensionsTest.cs) (revision 21b2f912e42c334efafdf907ad6f0c14b84187be) @@ -163,6 +163,8 @@ Assert.AreEqual((short) input.BreakWater.Type, entity.BreakWaterType); Assert.AreEqual(Convert.ToByte(input.UseBreakWater), entity.UseBreakWater); Assert.AreEqual(Convert.ToByte(input.UseForeshore), entity.UseForeshore); + + Assert.IsFalse(calculation.HasOutput); } [Test] @@ -521,6 +523,8 @@ Assert.AreEqual(inputParameters.LevelCrestStructureNotClosing.StandardDeviation.Value, entity.LevelCrestStructureNotClosingStandardDeviation); Assert.AreEqual(inputParameters.ProbabilityOpenStructureBeforeFlooding, entity.ProbabilityOpenStructureBeforeFlooding); Assert.AreEqual(order, entity.Order); + + Assert.IsFalse(calculation.HasOutput); } [Test] @@ -705,6 +709,27 @@ Assert.IsNotNull(entity.ForeshoreProfileEntity); } + [Test] + public void CreateForClosingStructures_CalculationWithOutput_ReturnEntity() + { + // Setup + var random = new Random(160); + var calculation = new StructuresCalculation + { + Output = new ProbabilityAssessmentOutput(random.NextDouble(), random.NextDouble(), + random.NextDouble(), random.NextDouble(), + random.NextDouble()) + }; + + var registry = new PersistenceRegistry(); + + // Call + ClosingStructuresCalculationEntity entity = calculation.CreateForClosingStructures(registry, 0); + + // Assert + Assert.AreEqual(1, entity.ClosingStructuresOutputEntities.Count); + } + #endregion } } \ No newline at end of file