Пример #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));
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var surfaceLine = new MacroStabilityInwardsSurfaceLine("Surface line");

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 0, 0),
                new Point3D(1, 1, 1)
            });

            MacroStabilityInwardsStochasticSoilModel   stochasticSoilModel   = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel();
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = stochasticSoilModel.StochasticSoilProfiles.First();

            // Precondition
            Assert.IsNotNull(stochasticSoilProfile);

            var original = new MacroStabilityInwardsInput(new MacroStabilityInwardsInput.ConstructionProperties());

            MacroStabilityInwardsTestDataGenerator.SetRandomMacroStabilityInwardsInput(original);

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones);
        }
Пример #5
0
        private static MacroStabilityInwardsCalculation CreateRandomCalculationWithoutOutput()
        {
            var calculation = new MacroStabilityInwardsCalculation
            {
                Name     = "A Name",
                Comments =
                {
                    Body = "A comment"
                }
            };

            MacroStabilityInwardsTestDataGenerator.SetRandomMacroStabilityInwardsInput(calculation.InputParameters);
            return(calculation);
        }
Пример #6
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);
        }
        private static MacroStabilityInwardsCalculationScenario CreateRandomCalculationScenarioWithoutOutput()
        {
            var random = new Random(21);

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                Name     = "A Name",
                Comments =
                {
                    Body = "A comment"
                },
                IsRelevant   = random.NextBoolean(),
                Contribution = random.NextRoundedDouble()
            };

            MacroStabilityInwardsTestDataGenerator.SetRandomMacroStabilityInwardsInput(calculation.InputParameters);

            return(calculation);
        }
Пример #8
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));
        }
Пример #9
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 MacroStabilityInwardsCalculationScenario CreateCalculation()
 {
     return(MacroStabilityInwardsTestDataGenerator.GetMacroStabilityInwardsCalculationScenario());
 }