public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentData() { // Setup HeightStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); object[] expectedRemovedObjects = failureMechanism.Sections.OfType <object>() .Concat(failureMechanism.SectionResults) .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) .Concat(failureMechanism.ForeshoreProfiles) .Concat(failureMechanism.HeightStructures) .ToArray(); // Call ClearResults results = HeightStructuresDataSynchronizationService.ClearReferenceLineDependentData(failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: CollectionAssert.IsEmpty(failureMechanism.Sections); CollectionAssert.IsEmpty(failureMechanism.SectionResults); CollectionAssert.IsEmpty(failureMechanism.CalculationsGroup.Children); CollectionAssert.IsEmpty(failureMechanism.ForeshoreProfiles); CollectionAssert.IsEmpty(failureMechanism.HeightStructures); IObservable[] array = results.ChangedObjects.ToArray(); Assert.AreEqual(5, array.Length); CollectionAssert.Contains(array, failureMechanism); CollectionAssert.Contains(array, failureMechanism.SectionResults); CollectionAssert.Contains(array, failureMechanism.CalculationsGroup); CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); CollectionAssert.Contains(array, failureMechanism.HeightStructures); CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects); }
public void RemoveStructure_FailureMechanismNull_ThrowsArgumentNullException() { // Call void Call() => HeightStructuresDataSynchronizationService.RemoveStructure(new TestHeightStructure(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void ClearReferenceLineDependentData_FailureMechanismNull_ThrowArgumentNullException() { // Call void Call() => HeightStructuresDataSynchronizationService.ClearReferenceLineDependentData(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithoutFailureMechanism_ThrowsArgumentNullException() { // Call void Call() => HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException() { // Call void Call() => HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithHydraulicBoundaryLocationAndOutput_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0); var calculation1 = new StructuresCalculation <HeightStructuresInput> { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation }, Output = new TestStructuresOutput() }; var calculation2 = new StructuresCalculation <HeightStructuresInput> { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation }, Output = new TestStructuresOutput() }; var calculation3 = new StructuresCalculation <HeightStructuresInput>(); failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call IEnumerable <IObservable> affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: foreach (StructuresCalculation <HeightStructuresInput> calculation in failureMechanism.Calculations.Cast <StructuresCalculation <HeightStructuresInput> >()) { Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation); Assert.IsNull(calculation.Output); } CollectionAssert.AreEquivalent(new IObservable[] { calculation1, calculation1.InputParameters, calculation2, calculation2.InputParameters }, affectedItems); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationWithoutOutputAndHydraulicBoundaryLocation_ReturnNoAffectedCalculations() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); var calculation1 = new StructuresCalculation <HeightStructuresInput>(); var calculation2 = new StructuresCalculation <HeightStructuresInput>(); var calculation3 = new StructuresCalculation <HeightStructuresInput>(); failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call IEnumerable <IObservable> affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); // Assert CollectionAssert.IsEmpty(affectedItems); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_CalculationsWithOutputAndNoHydraulicBoundaryLocation_ClearsOutputAndReturnsAffectedCalculations() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); var calculation1 = new StructuresCalculation <HeightStructuresInput> { Output = new TestStructuresOutput() }; var calculation2 = new StructuresCalculation <HeightStructuresInput> { Output = new TestStructuresOutput() }; var calculation3 = new StructuresCalculation <HeightStructuresInput>(); failureMechanism.CalculationsGroup.Children.Add(calculation1); failureMechanism.CalculationsGroup.Children.Add(calculation2); failureMechanism.CalculationsGroup.Children.Add(calculation3); // Call IEnumerable <IObservable> affectedItems = HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: foreach (ICalculation calculation in failureMechanism.Calculations) { Assert.IsFalse(calculation.HasOutput); } CollectionAssert.AreEqual(new[] { calculation1, calculation2 }, affectedItems); }
protected override IEnumerable <IObservable> ClearData() { return(HeightStructuresDataSynchronizationService.RemoveAllStructures(FailureMechanism)); }
protected override IEnumerable <IObservable> RemoveObjectAndDependentData(HeightStructure removedObject) { return(HeightStructuresDataSynchronizationService.RemoveStructure(removedObject, FailureMechanism)); }
public void RemoveStructure_FullyConfiguredFailureMechanism_RemovesStructureAndClearsDependentData() { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); var structureToRemove = new TestHeightStructure(new Point2D(0, 0), "id1"); var structureToKeep = new TestHeightStructure(new Point2D(2, 2), "id2"); failureMechanism.HeightStructures.AddRange(new[] { structureToRemove, structureToKeep }, "path/to/structures"); var calculationWithOutput = new TestHeightStructuresCalculationScenario { Output = new TestStructuresOutput() }; var calculationWithStructureToRemove = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structureToRemove } }; var calculationWithStructureToKeepAndOutput = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structureToKeep }, Output = new TestStructuresOutput() }; var calculationWithStructureToRemoveAndOutput = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = structureToRemove }, Output = new TestStructuresOutput() }; failureMechanism.CalculationsGroup.Children.AddRange(new[] { calculationWithOutput, calculationWithStructureToRemove, calculationWithStructureToKeepAndOutput, calculationWithStructureToRemoveAndOutput }); // Call IEnumerable <IObservable> affectedObjects = HeightStructuresDataSynchronizationService.RemoveStructure( structureToRemove, failureMechanism); // Assert // Note: To make sure the clear is performed regardless of what is done with // the return result, no ToArray() should be called before these assertions: CollectionAssert.DoesNotContain(failureMechanism.HeightStructures, structureToRemove); Assert.IsNull(calculationWithStructureToRemove.InputParameters.Structure); Assert.IsNull(calculationWithStructureToRemoveAndOutput.InputParameters.Structure); Assert.IsNull(calculationWithStructureToRemoveAndOutput.Output); Assert.IsNotNull(calculationWithOutput.Output); Assert.IsNotNull(calculationWithStructureToKeepAndOutput.Output); Assert.IsNotNull(calculationWithStructureToKeepAndOutput.InputParameters.Structure); IObservable[] expectedAffectedObjects = { calculationWithStructureToRemove.InputParameters, calculationWithStructureToRemoveAndOutput, calculationWithStructureToRemoveAndOutput.InputParameters, failureMechanism.HeightStructures }; CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }