private static void AssertHeightStructuresCalculationActivity(Activity activity, ICalculation <HeightStructuresInput> calculation, HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { var mocks = new MockRepository(); var testCalculator = new TestStructuresCalculator <StructuresOvertoppingCalculationInput>(); var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresOvertoppingCalculationInput>( Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(testCalculator); mocks.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { activity.Run(); StructuresOvertoppingCalculationInput actualInput = testCalculator.ReceivedInputs.Single(); Assert.AreEqual(calculation.InputParameters.FailureProbabilityStructureWithErosion, actualInput.Variables.Single(v => v.VariableId == 105).Value); } mocks.VerifyAll(); }
public void Calculate_PreprocessorDirectorySet_InputPropertiesCorrectlySentToCalculator(bool usePreprocessor) { // Setup string preprocessorDirectory = usePreprocessor ? validPreprocessorDirectory : string.Empty; var calculationSettings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath, validHlcdFilePath, false, preprocessorDirectory); var failureMechanism = new HeightStructuresFailureMechanism(); var mockRepository = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); var calculator = new TestStructuresCalculator <StructuresOvertoppingCalculationInput>(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresOvertoppingCalculationInput>( Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( calculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(calculator); mockRepository.ReplayAll(); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001) } }; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new HeightStructuresCalculationService().Calculate(calculation, failureMechanism.GeneralInput, calculationSettings); // Assert StructuresOvertoppingCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); StructuresOvertoppingCalculationInput actualInput = calculationInputs[0]; Assert.AreEqual(usePreprocessor, actualInput.PreprocessorSetting.RunPreprocessor); } mockRepository.VerifyAll(); }
public void Constructor_Always_ExpectedValues() { // Setup const int hydraulicBoundaryLocationId = 1000; IEnumerable <HydraRingForelandPoint> forelandPoints = Enumerable.Empty <HydraRingForelandPoint>(); var breakWater = new HydraRingBreakWater(1, 1.1); const double sectionNormal = 26.6; const double gravitationalAcceleration = 1.1; const double modelFactorOvertoppingFlowMean = 2.2; const double modelFactorOvertoppingFlowStandardDeviation = 3.3; const double levelCrestStructureMean = 4.4; const double levelCrestStructureStandardDeviation = 5.5; const double structureNormalOrientation = 6.6; const double modelFactorSuperCriticalFlowMean = 7.7; const double modelFactorSuperCriticalFlowStandardDeviation = 8.8; const double allowedLevelIncreaseStorageMean = 9.9; const double allowedLevelIncreaseStorageStandardDeviation = 10.0; const double modelFactorStorageVolumeMean = 11.1; const double modelFactorStorageVolumeStandardDeviation = 12.2; const double storageStructureAreaMean = 13.3; const double storageStructureAreaVariation = 14.4; const double modelFactorInflowVolume = 15.5; const double flowWidthAtBottomProtectionMean = 16.6; const double flowWidthAtBottomProtectionStandardDeviation = 17.7; const double criticalOvertoppingDischargeMean = 18.8; const double criticalOvertoppingDischargeVariation = 19.9; const double failureProbabilityStructureWithErosion = 20.0; const double widthFlowAperturesMean = 21.1; const double widthFlowAperturesStandardDeviation = 22.2; const double deviationWaveDirection = 23.3; const double stormDurationMean = 24.4; const double stormDurationVariation = 25.5; // Call var input = new StructuresOvertoppingCalculationInput(hydraulicBoundaryLocationId, sectionNormal, forelandPoints, breakWater, gravitationalAcceleration, modelFactorOvertoppingFlowMean, modelFactorOvertoppingFlowStandardDeviation, levelCrestStructureMean, levelCrestStructureStandardDeviation, structureNormalOrientation, modelFactorSuperCriticalFlowMean, modelFactorSuperCriticalFlowStandardDeviation, allowedLevelIncreaseStorageMean, allowedLevelIncreaseStorageStandardDeviation, modelFactorStorageVolumeMean, modelFactorStorageVolumeStandardDeviation, storageStructureAreaMean, storageStructureAreaVariation, modelFactorInflowVolume, flowWidthAtBottomProtectionMean, flowWidthAtBottomProtectionStandardDeviation, criticalOvertoppingDischargeMean, criticalOvertoppingDischargeVariation, failureProbabilityStructureWithErosion, widthFlowAperturesMean, widthFlowAperturesStandardDeviation, deviationWaveDirection, stormDurationMean, stormDurationVariation); // Assert Assert.IsInstanceOf <ExceedanceProbabilityCalculationInput>(input); Assert.AreEqual(1, input.CalculationTypeId); Assert.AreEqual(HydraRingFailureMechanismType.StructuresOvertopping, input.FailureMechanismType); Assert.AreEqual(60, input.VariableId); Assert.AreEqual(4404, input.FaultTreeModelId); Assert.AreEqual(6, input.IterationMethodId); Assert.AreEqual(hydraulicBoundaryLocationId, input.HydraulicBoundaryLocationId); HydraRingSection section = input.Section; Assert.AreEqual(1, section.SectionId); Assert.IsNaN(section.SectionLength); Assert.AreEqual(sectionNormal, section.CrossSectionNormal); Assert.AreSame(forelandPoints, input.ForelandPoints); Assert.AreSame(breakWater, input.BreakWater); HydraRingDataEqualityHelper.AreEqual(GetDefaultOvertoppingVariables().ToArray(), input.Variables.ToArray()); }
public void Calculate_VariousCalculationsWithBreakWater_InputPropertiesCorrectlySentToCalculator(BreakWaterType breakWaterType) { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); var mockRepository = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository); var calculator = new TestStructuresCalculator <StructuresOvertoppingCalculationInput>(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresOvertoppingCalculationInput>(null)) .IgnoreArguments() .Return(calculator); mockRepository.ReplayAll(); var calculation = new TestHeightStructuresCalculationScenario { InputParameters = { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), ForeshoreProfile = new TestForeshoreProfile(true) { BreakWater = { Type = breakWaterType } } } }; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new HeightStructuresCalculationService().Calculate(calculation, failureMechanism.GeneralInput, CreateCalculationSettings()); // Assert StructuresOvertoppingCalculationInput[] overtoppingCalculationInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, overtoppingCalculationInputs.Length); GeneralHeightStructuresInput generalInput = failureMechanism.GeneralInput; HeightStructuresInput input = calculation.InputParameters; var expectedInput = new StructuresOvertoppingCalculationInput( 1300001, input.StructureNormalOrientation, input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), generalInput.GravitationalAcceleration, generalInput.ModelFactorOvertoppingFlow.Mean, generalInput.ModelFactorOvertoppingFlow.StandardDeviation, input.LevelCrestStructure.Mean, input.LevelCrestStructure.StandardDeviation, input.StructureNormalOrientation, input.ModelFactorSuperCriticalFlow.Mean, input.ModelFactorSuperCriticalFlow.StandardDeviation, input.AllowedLevelIncreaseStorage.Mean, input.AllowedLevelIncreaseStorage.StandardDeviation, generalInput.ModelFactorStorageVolume.Mean, generalInput.ModelFactorStorageVolume.StandardDeviation, input.StorageStructureArea.Mean, input.StorageStructureArea.CoefficientOfVariation, generalInput.ModelFactorInflowVolume, input.FlowWidthAtBottomProtection.Mean, input.FlowWidthAtBottomProtection.StandardDeviation, input.CriticalOvertoppingDischarge.Mean, input.CriticalOvertoppingDischarge.CoefficientOfVariation, input.FailureProbabilityStructureWithErosion, input.WidthFlowApertures.Mean, input.WidthFlowApertures.StandardDeviation, input.DeviationWaveDirection, input.StormDuration.Mean, input.StormDuration.CoefficientOfVariation); StructuresOvertoppingCalculationInput actualInput = overtoppingCalculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); Assert.IsFalse(calculator.IsCanceled); } mockRepository.VerifyAll(); }