Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs =================================================================== diff -u -r670a9b8a6d2f8308fe58a8c1a406e8e909ae6cb0 -r81020313d965645986c0c89675374b16ae968f6b --- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision 670a9b8a6d2f8308fe58a8c1a406e8e909ae6cb0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision 81020313d965645986c0c89675374b16ae968f6b) @@ -486,5 +486,267 @@ }); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjectsArray); } + + [Test] + public void RemoveStochasticSoilProfileFromInput_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput( + null, + new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, -1)); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveStochasticSoilProfileFromInput_WithoutSoilProfile_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput( + new PipingFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("soilProfile", exception.ParamName); + } + + [Test] + public void RemoveStochasticSoilProfileFromInput_NoCalculationsWithProfile_ReturnNoAffectedObjects() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + StochasticSoilProfile profileToDelete = null; + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + input.StochasticSoilProfile = null; + } + } + + // Call + IEnumerable affected = PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete); + + // Assert + Assert.IsEmpty(affected); + } + + [Test] + public void RemoveStochasticSoilProfileFromInput_NoCalculationsWithOutputWithProfile_ReturnInputWithoutProfile() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + StochasticSoilProfile profileToDelete = null; + + var expectedInputs = new List(); + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + pipingCalculationScenario.ClearOutput(); + expectedInputs.Add(input); + } + } + + // Call + IEnumerable affected = PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete); + + // Assert + CollectionAssert.AreEquivalent(expectedInputs, affected); + CollectionAssert.IsEmpty(affected.Cast().Where(a => a.StochasticSoilProfile != null)); + } + + [Test] + public void RemoveStochasticSoilProfileFromInput_CalculationWithOutputWithProfile_ReturnInputWithoutProfileAndCalculation() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + + var expectedAffectedObjects = new List(); + + StochasticSoilProfile profileToDelete = null; + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + if (pipingCalculationScenario.HasOutput) + { + expectedAffectedObjects.Add(pipingCalculationScenario); + } + expectedAffectedObjects.Add(input); + } + } + // Call + IEnumerable affected = PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete); + + // Assert + CollectionAssert.AreEquivalent(expectedAffectedObjects, affected); + CollectionAssert.IsEmpty(affected.OfType().Where(a => a.StochasticSoilProfile != null)); + CollectionAssert.IsEmpty(affected.OfType().Where(a => a.HasOutput)); + } + + [Test] + public void ClearStochasticSoilProfileDependentData_WithoutFailureMechanism_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData( + null, + new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, -1)); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void ClearStochasticSoilProfileDependentData_WithoutSoilProfile_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData( + new PipingFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("soilProfile", exception.ParamName); + } + + [Test] + public void ClearStochasticSoilProfileDependentData_NoCalculationsWithProfile_ReturnNoAffectedObjects() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + StochasticSoilProfile profileToDelete = null; + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + input.StochasticSoilProfile = null; + } + } + + // Call + IEnumerable affected = PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, profileToDelete); + + // Assert + Assert.IsEmpty(affected); + } + + [Test] + public void ClearStochasticSoilProfileDependentData_NoCalculationsWithOutputWithProfile_ReturnInput() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + StochasticSoilProfile profileToDelete = null; + + var expectedInputs = new List(); + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + pipingCalculationScenario.ClearOutput(); + expectedInputs.Add(input); + } + } + + // Call + IEnumerable affected = PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, profileToDelete); + + // Assert + CollectionAssert.AreEquivalent(expectedInputs, affected); + CollectionAssert.IsEmpty(affected.Cast().Where(a => a.StochasticSoilProfile == null)); + } + + [Test] + public void ClearStochasticSoilProfileDependentData_CalculationWithOutputWithProfile_ReturnInputAndCalculation() + { + // Setup + PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations(); + IEnumerable calculations = failureMechanism + .Calculations + .Cast(); + + var expectedAffectedObjects = new List(); + + StochasticSoilProfile profileToDelete = null; + + foreach (PipingCalculationScenario pipingCalculationScenario in calculations) + { + PipingInput input = pipingCalculationScenario.InputParameters; + StochasticSoilProfile currentProfile = input.StochasticSoilProfile; + if (profileToDelete == null) + { + profileToDelete = currentProfile; + } + if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) + { + if (pipingCalculationScenario.HasOutput) + { + expectedAffectedObjects.Add(pipingCalculationScenario); + } + expectedAffectedObjects.Add(input); + } + } + // Call + IEnumerable affected = PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, profileToDelete); + + // Assert + CollectionAssert.AreEquivalent(expectedAffectedObjects, affected); + CollectionAssert.IsEmpty(affected.OfType().Where(a => a.StochasticSoilProfile == null)); + CollectionAssert.IsEmpty(affected.OfType().Where(a => a.HasOutput)); + } } } \ No newline at end of file