Example #1
0
        private static MacroStabilityInwardsCalculationScenario CreateValidCalculation(HydraulicBoundaryLocation hydraulicBoundaryLocation)
        {
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation);

            calculation.InputParameters.LeakageLengthInwardsPhreaticLine3 = new Random(39).NextRoundedDouble();
            return(calculation);
        }
        public void Create_WithValidData_ReturnsPersistableWaternetCreatorSettingsCollection()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(
                new TestHydraulicBoundaryLocation());
            MacroStabilityInwardsInput input = calculation.InputParameters;

            RoundedDouble normativeAssessmentLevel = RoundedDouble.NaN;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(input.SoilProfileUnderSurfaceLine, idFactory, registry);

            // Call
            IEnumerable <PersistableWaternetCreatorSettings> waternetCreatorSettingsCollection = PersistableWaternetCreatorSettingsFactory.Create(input, normativeAssessmentLevel,
                                                                                                                                                  idFactory, registry);

            // Assert
            var stages = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            PersistableDataModelTestHelper.AssertWaternetCreatorSettings(input, waternetCreatorSettingsCollection, normativeAssessmentLevel, stages);
            AssertRegistry(registry, stages, waternetCreatorSettingsCollection);
        }
        public void GetInitialFailureMechanismResultProbability_ScenarioWithNaNResults_ReturnsNaN()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double contribution1 = 0.2;
            const double contribution2 = 0.8;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)contribution1;

            macroStabilityInwardsCalculationScenario2.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)contribution2;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 0.1);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }
        public void CalculateProfileProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            var strategy = new MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy(
                sectionResult, calculations, new MacroStabilityInwardsFailureMechanism());

            // Call
            double profileProbability = strategy.CalculateProfileProbability();

            // Assert
            Assert.AreEqual(0.99012835, profileProbability, 1e-8);
        }
Example #5
0
        public void Create_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(
                new TestHydraulicBoundaryLocation());

            calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)),
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2))
            });

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            Assert.AreEqual(1, states.Count());

            PersistableState state = states.First();

            Assert.IsNotNull(state.Id);
            CollectionAssert.IsEmpty(state.StateLines);
            CollectionAssert.IsEmpty(state.StatePoints);
        }
        public void GetInitialFailureMechanismResultProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 1.1);

            // Assert
            Assert.AreEqual(0.99052414832077185, initialFailureMechanismResultProbability);
        }
        public void CreateCalculationFeatures_GivenCalculations_ReturnsCalculationFeaturesCollection()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new HydraulicBoundaryLocation(1, string.Empty, 5.0, 4.0));
            MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new HydraulicBoundaryLocation(1, string.Empty, 2.2, 3.8));

            calculationA.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint = new Point2D(1.0, 3.0);
            calculationB.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint = new Point2D(1.0, 4.0);

            // Call
            IEnumerable <MapFeature> features = MacroStabilityInwardsMapDataFeaturesFactory.CreateCalculationFeatures(new[]
            {
                calculationA,
                calculationB
            });

            // Assert
            Assert.AreEqual(2, features.Count());
            Assert.AreEqual(1, features.ElementAt(0).MapGeometries.Count());
            Assert.AreEqual(1, features.ElementAt(1).MapGeometries.Count());
            AssertEqualPointCollections(new[]
            {
                new Point2D(1.0, 3.0),
                new Point2D(5.0, 4.0)
            }, features.ElementAt(0).MapGeometries.ElementAt(0));
            AssertEqualPointCollections(new[]
            {
                new Point2D(1.0, 4.0),
                new Point2D(2.2, 3.8)
            }, features.ElementAt(1).MapGeometries.ElementAt(0));
        }
        public void Export_SoilProfileWithMultipleAquiferLayers_LogsWarningAndReturnsTrue()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix");

            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.InputParameters.StochasticSoilProfile.SoilProfile.Layers.ForEachElementDo(layer => layer.Data.IsAquifer = true);
            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    var exportResult            = false;
                    void Call() => exportResult = exporter.Export();

                    // Assert
                    var expectedMessage = $"'{calculation.Name}': De schematisatie van de berekening bevat meerdere aquifer lagen. De volgorde van de aquifer lagen kan niet bepaald worden tijdens exporteren. Er worden daarom geen lagen als aquifer geëxporteerd.";
                    TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn));
                    Assert.IsTrue(exportResult);
                }
            }
            finally
            {
                File.Delete(filePath);
            }
        }
        public void Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_LogsWarningAndReturnsTrue)}.ValidFile.stix");

            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)),
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2))
            });
            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    var exportResult            = false;
                    void Call() => exportResult = exporter.Export();

                    // Assert
                    var expectedMessage = $"'{calculation.Name}': De schematisatie van de berekening bevat meerdere stresspunten binnen één laag of stresspunten die niet aan een laag gekoppeld kunnen worden. Er worden daarom geen POP en grensspanningen geëxporteerd.";
                    TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn));
                    Assert.IsTrue(exportResult);
                }
            }
            finally
            {
                File.Delete(filePath);
            }
        }
        public void Export_RunsSuccessful_WritesFileAndRemovesTempFile()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_RunsSuccessful_WritesFileAndRemovesTempFile)}.ValidFile.stix");
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    bool exportResult = exporter.Export();

                    // Assert
                    Assert.IsTrue(exportResult);
                    Assert.IsTrue(File.Exists(filePath));
                    Assert.IsFalse(File.Exists($"{filePath}.temp"));
                }
            }
            finally
            {
                File.Delete(filePath);
            }
        }
        public void Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue(double maximumSliceWidth)
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_MaximumSliceWidthNotOne_LogsWarningAndReturnsTrue)}.ValidFile.stix");

            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.InputParameters.MaximumSliceWidth = (RoundedDouble)maximumSliceWidth;
            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), new PersistenceFactory(), filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    var exportResult            = false;
                    void Call() => exportResult = exporter.Export();

                    // Assert
                    var expectedMessage = $"'{calculation.Name}': De berekening bevat een lamelbreedte van {calculation.InputParameters.MaximumSliceWidth.ToString(null, CultureInfo.CurrentCulture)} meter. D-GEO Suite Stability ondersteunt enkel een maximale lamelbreedte van 1 meter. Er wordt daarom een lamelbreedte van 1 meter geëxporteerd.";
                    TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Warn));
                    Assert.IsTrue(exportResult);
                }
            }
            finally
            {
                File.Delete(filePath);
            }
        }
        public void Export_PersistenceFactoryThrowsException_NoFileWritten()
        {
            // Setup
            string filePath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationExporterTest)}.{nameof(Export_PersistenceFactoryThrowsException_NoFileWritten)}.ValidFile.stix");
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory
                {
                    ThrowException = true,
                    WriteFile      = true
                };

                var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

                // Call
                exporter.Export();

                // Assert
                Assert.IsFalse(File.Exists(filePath));
                Assert.IsFalse(File.Exists($"{filePath}.temp"));
            }
        }
        public void Export_PersistenceFactoryThrowsException_LogsErrorAndReturnsFalse()
        {
            // Setup
            const string filePath = "ValidFilePath";
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                var persistenceFactory = new MacroStabilityInwardsTestPersistenceFactory
                {
                    ThrowException = true
                };

                var exporter = new MacroStabilityInwardsCalculationExporter(calculation, new GeneralMacroStabilityInwardsInput(), persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel);

                // Call
                var exportResult            = true;
                void Call() => exportResult = exporter.Export();

                // Assert
                string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. Er is geen D-GEO Suite Stability Project geëxporteerd.";
                TestHelper.AssertLogMessageWithLevelIsGenerated(Call, new Tuple <string, LogLevelConstant>(expectedMessage, LogLevelConstant.Error));
                Assert.IsFalse(exportResult);
            }
        }
        private static MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy CreateStrategyForMultipleScenarios(FailureMechanismSection section)
        {
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            return(new MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy(
                       sectionResult, calculations, new MacroStabilityInwardsFailureMechanism()));
        }
Example #15
0
        public void Create_WithValidData_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario   calculation           = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1))
            });

            IMacroStabilityInwardsSoilLayer lastLayer = stochasticSoilProfile.SoilProfile.Layers.Last();

            lastLayer.Data.UsePop = true;
            lastLayer.Data.Pop    = new VariationCoefficientLogNormalDistribution
            {
                Mean = (RoundedDouble)1,
                CoefficientOfVariation = (RoundedDouble)2
            };
            calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile;

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertStates(soilProfile, states);
            PersistableState state = states.First();

            Assert.AreEqual(registry.States[MacroStabilityInwardsExportStageType.Daily], state.Id);
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenMacroStabilityInwardsCalculationScenarioNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();
            MacroStabilityInwardsCalculationScenario calculation =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation);

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                calculation.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
Example #17
0
        private static void AssertPropertyChangeWithOrWithoutCalculationOutput(
            Action <MacroStabilityInwardsCalculationRow> setProperty,
            Action <MacroStabilityInwardsCalculationScenario> assertions,
            bool hasOutput,
            bool expectUpdates)
        {
            // Setup
            var mockRepository = new MockRepository();
            var inputObserver  = mockRepository.StrictMock <IObserver>();

            if (expectUpdates)
            {
                inputObserver.Expect(o => o.UpdateObserver());
            }

            var calculationObserver = mockRepository.StrictMock <IObserver>();

            if (expectUpdates && hasOutput)
            {
                calculationObserver.Expect(o => o.UpdateObserver());
            }

            var handler = mockRepository.Stub <IObservablePropertyChangeHandler>();

            mockRepository.ReplayAll();

            MacroStabilityInwardsOutput assignedOutput = null;

            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            if (hasOutput)
            {
                assignedOutput = MacroStabilityInwardsOutputTestFactory.CreateOutput();
            }

            calculation.Output = assignedOutput;

            var row = new MacroStabilityInwardsCalculationRow(calculation, handler);

            calculation.Attach(calculationObserver);
            calculation.InputParameters.Attach(inputObserver);

            // Call
            setProperty(row);

            // Assert
            assertions(calculation);
            if (expectUpdates)
            {
                Assert.IsNull(calculation.Output);
            }
            else
            {
                Assert.AreSame(assignedOutput, calculation.Output);
            }

            mockRepository.VerifyAll();
        }
        private static void AddMacroStabilityInwardsCalculationScenario(AssessmentSection assessmentSection,
                                                                        HydraulicBoundaryLocation hydraulicBoundaryLocation)
        {
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation);

            macroStabilityInwardsCalculationScenario.InputParameters.UseAssessmentLevelManualInput = true;
            macroStabilityInwardsCalculationScenario.InputParameters.AssessmentLevel = new Random(39).NextRoundedDouble();
            assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(macroStabilityInwardsCalculationScenario);
        }
        public void Create_WithValidData_ReturnsPersistableProjectInfo()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());
            const string filePath = "SomeFilePath";

            // Call
            PersistableProjectInfo persistableProjectInfo = PersistableProjectInfoFactory.Create(calculation, filePath);

            // Assert
            PersistableDataModelTestHelper.AssertProjectInfo(calculation, filePath, persistableProjectInfo);
        }
        public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated()
        {
            // Given
            var surfaceLineA = new MacroStabilityInwardsSurfaceLine(string.Empty);

            surfaceLineA.SetGeometry(new[]
            {
                new Point3D(0.0, 0.0, 1.0),
                new Point3D(3.0, 0.0, 1.7)
            });
            surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3);

            MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculationA.InputParameters.SurfaceLine = surfaceLineA;

            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationA);

            MacroStabilityInwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub());

            IMapControl map = ((RiskeerMapControl)view.Controls[0]).MapControl;

            var surfaceLineB = new MacroStabilityInwardsSurfaceLine(string.Empty);

            surfaceLineB.SetGeometry(new[]
            {
                new Point3D(0.0, 0.0, 1.5),
                new Point3D(3.0, 0.0, 1.8)
            });
            surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5);

            MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculationB.InputParameters.SurfaceLine = surfaceLineB;

            var calculationMapData = (MapLineData)map.Data.Collection.ElementAt(calculationsIndex);

            var mocks = new MockRepository();

            IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection);
            observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver());
            mocks.ReplayAll();

            // When
            failureMechanism.CalculationsGroup.Children.Add(calculationB);
            failureMechanism.CalculationsGroup.NotifyObservers();

            // Then
            AssertCalculationsMapData(failureMechanism.Calculations.Cast <MacroStabilityInwardsCalculationScenario>(), calculationMapData);
            mocks.VerifyAll();
        }
Example #21
0
        public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations()
        {
            // Setup
            using (var treeViewControl = new TreeViewControl())
            {
                var assessmentSection         = new AssessmentSectionStub();
                var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();

                assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
                {
                    hydraulicBoundaryLocation
                }, true);

                var failureMechanism = new MacroStabilityInwardsFailureMechanism();
                MacroStabilityInwardsCalculationScenario validCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation);
                validCalculation.Name = "A";
                MacroStabilityInwardsCalculationScenario invalidCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();
                invalidCalculation.Name = "B";

                failureMechanism.CalculationsGroup.Children.Add(validCalculation);
                failureMechanism.CalculationsGroup.Children.Add(invalidCalculation);

                var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection);

                var menuBuilder = new CustomItemsOnlyContextMenuBuilder();

                var gui = mocks.Stub <IGui>();
                gui.Stub(g => g.Get(context, treeViewControl)).Return(menuBuilder);
                mocks.ReplayAll();

                plugin.Gui = gui;

                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl))
                    using (new MacroStabilityInwardsCalculatorFactoryConfig())
                    {
                        // Call
                        void Call() => contextMenu.Items[contextMenuValidateAllIndex].PerformClick();

                        // Assert
                        TestHelper.AssertLogMessages(Call, messages =>
                        {
                            string[] msgs = messages.ToArray();
                            Assert.AreEqual(9, msgs.Length);
                            CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                            Assert.AreEqual("Validatie van waterspanningen in extreme omstandigheden is gestart.", msgs[1]);
                            Assert.AreEqual("Validatie van waterspanningen in dagelijkse omstandigheden is gestart.", msgs[2]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(msgs[4]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(msgs[8]);
                        });
                    }
            }
        }
        private static MacroStabilityInwardsCalculationScenario CreateCalculation(string calculationName, bool setOutput = true)
        {
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Name = calculationName;
            if (setOutput)
            {
                calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();
            }

            return(calculation);
        }
Example #23
0
        public void Create_CalculationWithoutOutput_ThrowsInvalidOperationException()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            // Call
            void Call() => PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, string.Empty);

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

            Assert.AreEqual("Calculation must have output.", exception.Message);
        }
Example #24
0
        public void CreateCalculationActivity_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            // Call
            void Call() => MacroStabilityInwardsCalculationActivityFactory.CreateCalculationActivity(calculation, new GeneralMacroStabilityInwardsInput(), null);

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

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
        public void GetWaternetExtreme_GeneralInputNull_ThrowsArgumentNullException()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            // Call
            void Call() => DerivedMacroStabilityInwardsInput.GetWaternetExtreme(calculation.InputParameters, null, RoundedDouble.NaN);

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

            Assert.AreEqual("generalInput", exception.ParamName);
        }
Example #26
0
        public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled()
        {
            // Setup
            using (var treeViewControl = new TreeViewControl())
            {
                var assessmentSection         = new AssessmentSectionStub();
                var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();

                assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
                {
                    hydraulicBoundaryLocation
                }, true);

                var failureMechanism = new MacroStabilityInwardsFailureMechanism
                {
                    CalculationsGroup =
                    {
                        Children =
                        {
                            MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation)
                        }
                    }
                };

                var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection);

                var menuBuilder = new CustomItemsOnlyContextMenuBuilder();

                var gui = mocks.Stub <IGui>();
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder);
                mocks.ReplayAll();

                plugin.Gui = gui;

                // Call
                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl))
                {
                    // Assert
                    TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex,
                                                                  "Alles be&rekenen",
                                                                  "Voer alle berekeningen binnen dit faalmechanisme uit.",
                                                                  RiskeerCommonFormsResources.CalculateAllIcon);

                    TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndex,
                                                                  "Alles &valideren",
                                                                  "Valideer alle berekeningen binnen dit faalmechanisme.",
                                                                  RiskeerCommonFormsResources.ValidateAllIcon);
                }
            }
        }
        public void GetWaternetDaily_ValidInput_ReturnsMacroStabilityInwardsWaternet()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                // Call
                MacroStabilityInwardsWaternet waternet = DerivedMacroStabilityInwardsInput.GetWaternetDaily(calculation.InputParameters, new GeneralMacroStabilityInwardsInput());

                // Assert
                var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;

                CalculatorOutputAssert.AssertWaternet(calculatorFactory.LastCreatedWaternetDailyCalculator.Output, waternet);
            }
        }
        public void GivenMacroStabilityInwardsFailureMechanismResultView_WhenNestedCalculationInputNotifiesObservers_ThenDataGridViewUpdatedAndAssemblyPerformed()
        {
            // Given
            var failureMechanism            = new MacroStabilityInwardsFailureMechanism();
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1");

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            MacroStabilityInwardsCalculationScenario calculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculationScenario);
            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism))
                {
                    var testFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    FailureMechanismSectionAssemblyCalculatorStub failureMechanismSectionAssemblyCalculator = testFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                    failureMechanismSectionAssemblyCalculator.FailureMechanismSectionAssemblyResultOutput = new FailureMechanismSectionAssemblyResultWrapper(
                        new FailureMechanismSectionAssemblyResult(1, 1, 1, FailureMechanismSectionAssemblyGroup.III),
                        AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1);

                    FailureMechanismAssemblyCalculatorStub failureMechanismAssemblyCalculator  = testFactory.LastCreatedFailureMechanismAssemblyCalculator;
                    IEnumerable <FailureMechanismSectionAssemblyResult> initialCalculatorInput = failureMechanismAssemblyCalculator.SectionAssemblyResultsInput
                                                                                                 .ToArray();

                    var          rowsChanged  = false;
                    DataGridView dataGridView = GetDataGridView();
                    dataGridView.Rows.CollectionChanged += (sender, args) => rowsChanged = true;

                    // Precondition
                    Assert.IsFalse(rowsChanged);

                    // When
                    calculationScenario.InputParameters.NotifyObservers();

                    // Then
                    Assert.IsTrue(rowsChanged);
                    IEnumerable <FailureMechanismSectionAssemblyResult> updatedCalculatorInput = failureMechanismAssemblyCalculator.SectionAssemblyResultsInput
                                                                                                 .ToArray();
                    CollectionAssert.AreNotEqual(initialCalculatorInput, updatedCalculatorInput);
                }
        }
Example #29
0
        public void Create_WithValidData_ReturnsPersistableDataModel()
        {
            // Setup
            const string filePath = "ValidFilePath";
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                // Call
                PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath);

                // Assert
                PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel);
            }
        }
        public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1");

            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            failureMechanism.CalculationsGroup.Children.Add(
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(1.1, section));

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism))
                {
                    DataGridView dataGridView = GetDataGridView();

                    // Assert
                    DataGridViewRowCollection rows = dataGridView.Rows;
                    Assert.AreEqual(1, rows.Count);

                    double probability = failureMechanism.SectionResults.First().GetInitialFailureMechanismResultProbability(
                        failureMechanism.Calculations.OfType <MacroStabilityInwardsCalculationScenario>(), failureMechanism.GeneralInput.ModelFactor);

                    DataGridViewCellCollection cells = rows[0].Cells;
                    Assert.AreEqual(columnCount, cells.Count);
                    Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue);
                    Assert.AreEqual(true, cells[isRelevantIndex].Value);
                    Assert.AreEqual(AdoptableInitialFailureMechanismResultType.Adopt, cells[initialFailureMechanismResultTypeIndex].Value);
                    Assert.AreEqual(probability, cells[initialFailureMechanismResultProfileProbabilityIndex].Value);
                    Assert.AreEqual(probability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(section.Length),
                                    cells[initialFailureMechanismResultSectionProbabilityIndex].Value);
                    Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value);
                    Assert.AreEqual(ProbabilityRefinementType.Section, cells[probabilityRefinementTypeIndex].Value);
                    Assert.AreEqual("<afgeleid>", cells[refinedProfileProbabilityIndex].FormattedValue);
                    Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("1/100", cells[profileProbabilityIndex].FormattedValue);
                    Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("10,00", cells[sectionNIndex].FormattedValue);
                    Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue);
                }
        }