Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        private IEnumerable <IObservable> UpdateStochasticSoilModel(MacroStabilityInwardsStochasticSoilModel modelToUpdate, MacroStabilityInwardsStochasticSoilModel modelToUpdateFrom)
        {
            Dictionary <MacroStabilityInwardsStochasticSoilProfile, IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> > oldProfiles =
                modelToUpdate
                .StochasticSoilProfiles
                .ToDictionary(ssp => ssp, ssp => ssp.SoilProfile, new ReferenceEqualityComparer <MacroStabilityInwardsStochasticSoilProfile>());

            MacroStabilityInwardsStochasticSoilModelProfileDifference difference = modelToUpdate.Update(modelToUpdateFrom);

            var affectedObjects = new List <IObservable>();

            foreach (MacroStabilityInwardsStochasticSoilProfile removedProfile in difference.RemovedProfiles)
            {
                affectedObjects.AddRange(MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilProfileFromInput(FailureMechanism, removedProfile));
            }

            foreach (MacroStabilityInwardsStochasticSoilProfile updatedProfile in difference.UpdatedProfiles)
            {
                if (!oldProfiles[updatedProfile].Equals(updatedProfile.SoilProfile))
                {
                    affectedObjects.AddRange(MacroStabilityInwardsDataSynchronizationService.ClearStochasticSoilProfileDependentData(FailureMechanism, updatedProfile));
                }

                affectedObjects.Add(updatedProfile);
            }

            return(affectedObjects);
        }
Ejemplo n.º 5
0
        public void ClearReferenceLineDependentData_FailureMechanismNull_ThrowArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.ClearReferenceLineDependentData(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 6
0
        public void RemoveAllStochasticSoilModel_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.RemoveAllStochasticSoilModels(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 7
0
        public void ClearAllCalculationOutputWithoutManualAssessmentLevel_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputWithoutManualAssessmentLevel(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 8
0
        public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 9
0
        public void ClearStochasticSoilProfileDependentData_WithoutSoilProfile_ThrowsArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.ClearStochasticSoilProfileDependentData(
                new MacroStabilityInwardsFailureMechanism(), null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("soilProfile", exception.ParamName);
        }
Ejemplo n.º 10
0
        public void ClearStochasticSoilProfileDependentData_WithoutFailureMechanism_ThrowsArgumentNullException()
        {
            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.ClearStochasticSoilProfileDependentData(
                null, new MacroStabilityInwardsStochasticSoilProfile(0.5, MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D()));

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 11
0
        public void RemoveSurfaceLine_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Setup
            var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty);

            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.RemoveSurfaceLine(null, surfaceLine);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 12
0
        public void RemoveStochasticSoilModel_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Setup
            MacroStabilityInwardsStochasticSoilModel soilModel = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel();

            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilModel(null, soilModel);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("failureMechanism", exception.ParamName);
        }
Ejemplo n.º 13
0
        public void RemoveStochasticSoilModel_StochasticSoilModelNull_ThrowsArgumentNullException()
        {
            // Setup
            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            // Call
            void Call() => MacroStabilityInwardsDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("soilModel", exception.ParamName);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public void ClearAllCalculationOutputWithoutManualAssessmentLevel_WithVariousCalculations_ClearsCalculationsOutputAndReturnsAffectedCalculations()
        {
            // Setup
            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.AddRange(new[]
            {
                new MacroStabilityInwardsCalculationScenario(),
                new MacroStabilityInwardsCalculationScenario
                {
                    InputParameters =
                    {
                        UseAssessmentLevelManualInput = true
                    },
                    Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
                },
                new MacroStabilityInwardsCalculationScenario
                {
                    Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
                }
            });

            MacroStabilityInwardsCalculationScenario[] expectedAffectedCalculations = failureMechanism.Calculations
                                                                                      .OfType <MacroStabilityInwardsCalculationScenario>()
                                                                                      .Where(c => !c.InputParameters.UseAssessmentLevelManualInput && c.HasOutput)
                                                                                      .ToArray();

            // Call
            IEnumerable <IObservable> affectedItems = MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputWithoutManualAssessmentLevel(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
                          .OfType <MacroStabilityInwardsCalculationScenario>()
                          .Where(c => !c.InputParameters.UseAssessmentLevelManualInput)
                          .All(c => !c.HasOutput));

            CollectionAssert.AreEquivalent(expectedAffectedCalculations, affectedItems);
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        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);
        }
 protected override IEnumerable <IObservable> ClearData()
 {
     return(MacroStabilityInwardsDataSynchronizationService.RemoveAllStochasticSoilModels(FailureMechanism));
 }
Ejemplo n.º 19
0
 protected override IEnumerable <IObservable> RemoveObjectAndDependentData(MacroStabilityInwardsSurfaceLine removedObject)
 {
     return(MacroStabilityInwardsDataSynchronizationService.RemoveSurfaceLine(FailureMechanism, removedObject));
 }