public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedObjects() { // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); StructuresCalculation <StabilityPointStructuresInput>[] calculations = failureMechanism.Calculations.Cast <StructuresCalculation <StabilityPointStructuresInput> >().ToArray(); IObservable[] expectedAffectedCalculations = calculations.Where(c => c.HasOutput) .Cast <IObservable>() .ToArray(); IObservable[] expectedAffectedCalculationInputs = calculations.Select(c => c.InputParameters) .Where(i => i.HydraulicBoundaryLocation != null) .Cast <IObservable>() .ToArray(); // Call IEnumerable <IObservable> affectedItems = StabilityPointStructuresDataSynchronizationService.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: Assert.IsTrue(failureMechanism.Calculations.Cast <StructuresCalculation <StabilityPointStructuresInput> >() .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedCalculations.Concat(expectedAffectedCalculationInputs), affectedItems); }
public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveFailureMechanismDependentData() { // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); object[] expectedRemovedObjects = failureMechanism.Sections.OfType <object>() .Concat(failureMechanism.SectionResults) .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) .Concat(failureMechanism.ForeshoreProfiles) .Concat(failureMechanism.StabilityPointStructures) .ToArray(); // Call ClearResults results = StabilityPointStructuresDataSynchronizationService.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.StabilityPointStructures); 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.StabilityPointStructures); CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects); }
public void RemoveAllStructures_FailureMechanismNull_ThrowsArgumentNullException() { // Call void Call() => StabilityPointStructuresDataSynchronizationService.RemoveAllStructures(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName; Assert.AreEqual("failureMechanism", paramName); }
public void RemoveStructure_FailureMechanismNull_ThrowsArgumentNullException() { // Call void Call() => StabilityPointStructuresDataSynchronizationService.RemoveStructure(new TestStabilityPointStructure(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void ClearReferenceLineDependentData_FailureMechanismNull_ThrowArgumentNullException() { // Call void Call() => StabilityPointStructuresDataSynchronizationService.ClearReferenceLineDependentData(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName; Assert.AreEqual("failureMechanism", paramName); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() { // Call void Call() => StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("failureMechanism", exception.ParamName); }
public void RemoveStructure_FullyConfiguredFailureMechanism_RemovesStructureAndClearsDependentData() { // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); StabilityPointStructure structure = failureMechanism.StabilityPointStructures[0]; StructuresCalculation <StabilityPointStructuresInput>[] calculationsWithStructure = failureMechanism.Calculations .Cast <StructuresCalculation <StabilityPointStructuresInput> >() .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); StructuresCalculation <StabilityPointStructuresInput>[] calculationsWithOutput = calculationsWithStructure.Where(c => c.HasOutput) .ToArray(); // Precondition CollectionAssert.IsNotEmpty(calculationsWithOutput); CollectionAssert.IsNotEmpty(calculationsWithStructure); // Call IEnumerable <IObservable> affectedObjects = StabilityPointStructuresDataSynchronizationService.RemoveStructure(structure, 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.StabilityPointStructures, structure); foreach (StructuresCalculation <StabilityPointStructuresInput> calculation in calculationsWithStructure) { Assert.IsNull(calculation.InputParameters.Structure); } foreach (StructuresCalculation <StabilityPointStructuresInput> calculation in calculationsWithOutput) { Assert.IsFalse(calculation.HasOutput); } IObservable[] array = affectedObjects.ToArray(); Assert.AreEqual(1 + calculationsWithOutput.Length + calculationsWithStructure.Length, array.Length); CollectionAssert.Contains(array, failureMechanism.StabilityPointStructures); foreach (StructuresCalculation <StabilityPointStructuresInput> calculation in calculationsWithStructure) { CollectionAssert.Contains(array, calculation.InputParameters); } foreach (StructuresCalculation <StabilityPointStructuresInput> calculation in calculationsWithOutput) { CollectionAssert.Contains(array, calculation); } }
public void ClearAllCalculationOutput_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedCalculations() { // Setup StabilityPointStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); ICalculation[] expectedAffectedCalculations = failureMechanism.Calculations .Where(c => c.HasOutput) .ToArray(); // Call IEnumerable <IObservable> affectedItems = StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutput(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: Assert.IsTrue(failureMechanism.Calculations.All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems); }
public void RemoveAllStructures_FullyConfiguredFailureMechanism_RemoveAllStructuresAndClearDependentData() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); var structureA = new TestStabilityPointStructure(new Point2D(0, 0), "A"); var structureB = new TestStabilityPointStructure(new Point2D(2, 2), "B"); failureMechanism.StabilityPointStructures.AddRange(new[] { structureA, structureB }, "path/to/structures"); var calculationWithOutput = new StructuresCalculation <StabilityPointStructuresInput> { Output = new TestStructuresOutput() }; var calculationWithStructureA = new StructuresCalculation <StabilityPointStructuresInput> { InputParameters = { Structure = structureA } }; var calculationWithStructureBAndOutput = new StructuresCalculation <StabilityPointStructuresInput> { InputParameters = { Structure = structureB }, Output = new TestStructuresOutput() }; var calculationWithStructureAAndOutput = new StructuresCalculation <StabilityPointStructuresInput> { InputParameters = { Structure = structureA }, Output = new TestStructuresOutput() }; failureMechanism.CalculationsGroup.Children.AddRange(new[] { calculationWithOutput, calculationWithStructureA, calculationWithStructureBAndOutput, calculationWithStructureAAndOutput }); // Call IEnumerable <IObservable> affectedObjects = StabilityPointStructuresDataSynchronizationService.RemoveAllStructures(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.StabilityPointStructures, structureA); Assert.IsNull(calculationWithStructureA.InputParameters.Structure); Assert.IsNull(calculationWithStructureAAndOutput.InputParameters.Structure); Assert.IsNull(calculationWithStructureBAndOutput.InputParameters.Structure); Assert.IsNull(calculationWithStructureAAndOutput.Output); Assert.IsNull(calculationWithStructureBAndOutput.Output); Assert.IsNotNull(calculationWithOutput.Output); IObservable[] expectedAffectedObjects = { calculationWithStructureA.InputParameters, calculationWithStructureAAndOutput, calculationWithStructureAAndOutput.InputParameters, calculationWithStructureBAndOutput, calculationWithStructureBAndOutput.InputParameters, failureMechanism.StabilityPointStructures }; CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); }
protected override IEnumerable <IObservable> RemoveObjectAndDependentData(StabilityPointStructure removedObject) { return(StabilityPointStructuresDataSynchronizationService.RemoveStructure(removedObject, FailureMechanism)); }
protected override IEnumerable <IObservable> ClearData() { return(StabilityPointStructuresDataSynchronizationService.RemoveAllStructures(FailureMechanism)); }