public void ClearStochasticSoilProfileDependentData_NoCalculationsWithOutputWithProfile_ReturnInput() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); IEnumerable <MacroStabilityInwardsCalculationScenario> calculations = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculationScenario>(); MacroStabilityInwardsStochasticSoilProfile profileToDelete = null; var expectedInputs = new List <MacroStabilityInwardsInput>(); foreach (MacroStabilityInwardsCalculationScenario calculationScenario in calculations) { MacroStabilityInwardsInput input = calculationScenario.InputParameters; MacroStabilityInwardsStochasticSoilProfile currentProfile = input.StochasticSoilProfile; if (profileToDelete == null) { profileToDelete = currentProfile; } if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) { calculationScenario.ClearOutput(); expectedInputs.Add(input); } } // Call IEnumerable <IObservable> affected = MacroStabilityInwardsDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, profileToDelete); // Assert CollectionAssert.AreEquivalent(expectedInputs, affected); CollectionAssert.IsEmpty(affected.Cast <MacroStabilityInwardsInput>().Where(a => a.StochasticSoilProfile == null)); }
public void RemoveStochasticSoilProfileFromInput_NoCalculationsWithProfile_ReturnNoAffectedObjects() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); IEnumerable <MacroStabilityInwardsCalculationScenario> calculations = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculationScenario>(); MacroStabilityInwardsStochasticSoilProfile profileToDelete = null; foreach (MacroStabilityInwardsCalculationScenario calculationScenario in calculations) { MacroStabilityInwardsInput input = calculationScenario.InputParameters; MacroStabilityInwardsStochasticSoilProfile currentProfile = input.StochasticSoilProfile; if (profileToDelete == null) { profileToDelete = currentProfile; } if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) { input.StochasticSoilProfile = null; } } // Call IEnumerable <IObservable> affected = MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete); // Assert CollectionAssert.IsEmpty(affected); }
public void ClearReferenceLineDependentData_FullyConfiguredFailureMechanism_RemoveReferenceLineDependentDataAndReturnAffectedObjects() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); object[] expectedRemovedObjects = failureMechanism.Sections.OfType <object>() .Concat(failureMechanism.SectionResults) .Concat(failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) .Concat(failureMechanism.StochasticSoilModels) .Concat(failureMechanism.SurfaceLines) .ToArray(); // Call ClearResults results = MacroStabilityInwardsDataSynchronizationService.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.StochasticSoilModels); CollectionAssert.IsEmpty(failureMechanism.SurfaceLines); 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.StochasticSoilModels); CollectionAssert.Contains(array, failureMechanism.SurfaceLines); CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects); }
public void RemoveStochasticSoilModel_FullyConfiguredFailureMechanism_RemoveProfileAndClearDependentData() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); MacroStabilityInwardsStochasticSoilModel soilModel = failureMechanism.StochasticSoilModels[1]; MacroStabilityInwardsCalculation[] calculationsWithSoilModel = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculation>() .Where(c => ReferenceEquals(c.InputParameters.StochasticSoilModel, soilModel)) .ToArray(); MacroStabilityInwardsCalculation[] calculationsWithOutput = calculationsWithSoilModel.Where(c => c.HasOutput) .ToArray(); // Precondition CollectionAssert.IsNotEmpty(calculationsWithSoilModel); // Call IEnumerable <IObservable> observables = MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, soilModel); // 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.StochasticSoilModels, soilModel); foreach (MacroStabilityInwardsCalculation calculation in calculationsWithSoilModel) { Assert.IsNull(calculation.InputParameters.StochasticSoilModel); } IObservable[] affectedObjectsArray = observables.ToArray(); int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithSoilModel.Length; Assert.AreEqual(expectedAffectedObjectCount, affectedObjectsArray.Length); foreach (MacroStabilityInwardsCalculation calculation in calculationsWithOutput) { Assert.IsFalse(calculation.HasOutput); } IEnumerable <IObservable> expectedAffectedObjects = calculationsWithSoilModel.Select(calc => calc.InputParameters) .Cast <IObservable>() .Concat(calculationsWithOutput) .Concat(new IObservable[] { failureMechanism.StochasticSoilModels }); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjectsArray); }
public void RemoveStochasticSoilProfileFromInput_CalculationWithOutputWithProfile_ReturnInputWithoutProfileAndCalculation() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); IEnumerable <MacroStabilityInwardsCalculationScenario> calculations = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculationScenario>(); var expectedAffectedObjects = new List <IObservable>(); MacroStabilityInwardsStochasticSoilProfile profileToDelete = null; foreach (MacroStabilityInwardsCalculationScenario calculationScenario in calculations) { MacroStabilityInwardsInput input = calculationScenario.InputParameters; MacroStabilityInwardsStochasticSoilProfile currentProfile = input.StochasticSoilProfile; if (profileToDelete == null) { profileToDelete = currentProfile; } if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile)) { if (calculationScenario.HasOutput) { expectedAffectedObjects.Add(calculationScenario); } expectedAffectedObjects.Add(input); } } // Call IEnumerable <IObservable> affected = MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete); // Assert CollectionAssert.AreEquivalent(expectedAffectedObjects, affected); CollectionAssert.IsEmpty(affected.OfType <MacroStabilityInwardsInput>().Where(a => a.StochasticSoilProfile != null)); CollectionAssert.IsEmpty(affected.OfType <MacroStabilityInwardsCalculation>().Where(a => a.HasOutput)); }
public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_WithVariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() { // Setup MacroStabilityInwardsFailureMechanism failureMechanism = MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsFailureMechanismWithAllCalculationConfigurations(); failureMechanism.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario { InputParameters = { UseAssessmentLevelManualInput = true }, Output = MacroStabilityInwardsOutputTestFactory.CreateOutput() }); MacroStabilityInwardsCalculation[] calculations = failureMechanism.Calculations .Cast <MacroStabilityInwardsCalculation>() .ToArray(); var expectedAffectedItems = new List <IObservable>(); expectedAffectedItems.AddRange(calculations.Where(c => !c.InputParameters.UseAssessmentLevelManualInput && c.HasOutput)); expectedAffectedItems.AddRange(calculations.Select(c => c.InputParameters) .Where(i => i.HydraulicBoundaryLocation != null)); // Call IEnumerable <IObservable> affectedItems = MacroStabilityInwardsDataSynchronizationService.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(calculations.Where(c => !c.InputParameters.UseAssessmentLevelManualInput) .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); }