public void ParseBreakWater_Use_ReturnHydraRingBreakWater(BreakWaterType breakWaterType) { // Setup var random = new Random(22); double breakWaterHeight = random.NextDouble(); var mockRepository = new MockRepository(); var breakWater = mockRepository.Stub <IUseBreakWater>(); breakWater.UseBreakWater = true; var expectedBreakWater = new BreakWater(breakWaterType, breakWaterHeight); breakWater.Stub(call => call.BreakWater).Return(expectedBreakWater); mockRepository.ReplayAll(); // Call HydraRingBreakWater parsedBreakWater = HydraRingInputParser.ParseBreakWater(breakWater); // Assert Assert.AreEqual(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), parsedBreakWater.Type); Assert.AreEqual(expectedBreakWater.Height, parsedBreakWater.Height, expectedBreakWater.Height.GetAccuracy()); mockRepository.VerifyAll(); }
public void Run_Always_InputPropertiesCorrectlySentToService(BreakWaterType breakWaterType) { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(); ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection); GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation, failureMechanism, assessmentSection); var waveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator(); RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray(); int nrOfCalculators = GetNrOfCalculators(calculation, assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(waveConditionsCosineCalculator) .Repeat .Times(nrOfCalculators); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = waveConditionsCosineCalculator.ReceivedInputs.ToArray(); Assert.AreEqual(nrOfCalculators, waveConditionsInputs.Length); WaveConditionsInput input = calculation.InputParameters; double targetProbability = assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability; var waterLevelIndex = 0; GeneralGrassCoverErosionOutwardsInput generalInput = failureMechanism.GeneralInput; for (var i = 0; i < waveConditionsInputs.Length / 2; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralWaveRunUpWaveConditionsInput.A, generalInput.GeneralWaveRunUpWaveConditionsInput.B, generalInput.GeneralWaveRunUpWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } waterLevelIndex = 0; for (int i = waveConditionsInputs.Length / 2; i < waveConditionsInputs.Length; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralWaveImpactWaveConditionsInput.A, generalInput.GeneralWaveImpactWaveConditionsInput.B, generalInput.GeneralWaveImpactWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } } mockRepository.VerifyAll(); }
public void Calculate_Always_InputPropertiesCorrectlySentToCalculator(BreakWaterType breakWaterType) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var calculator = new TestWaveConditionsCosineCalculator(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(3); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate( calculation, assessmentSection, waveImpactAsphaltCoverFailureMechanism.GeneralInput); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(3, waveConditionsInputs.Length); var waterLevelIndex = 0; foreach (WaveConditionsCosineCalculationInput actualInput in waveConditionsInputs) { GeneralWaveConditionsInput generalInput = waveImpactAsphaltCoverFailureMechanism.GeneralInput; WaveConditionsInput input = calculation.InputParameters; var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), GetWaterLevels(calculation, assessmentSection).ElementAt(waterLevelIndex++), generalInput.A, generalInput.B, generalInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); } } mockRepository.VerifyAll(); }
private static WaveConditionsCosineCalculationInput CreateInput(double waterLevel, double a, double b, double c, double targetProbability, WaveConditionsInput input, bool useForeshore, bool useBreakWater) { return(new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, useForeshore ? input.ForeshoreGeometry.Select(coordinate => new HydraRingForelandPoint(coordinate.X, coordinate.Y)) : new HydraRingForelandPoint[0], useBreakWater ? new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(input.BreakWater.Type), input.BreakWater.Height) : null, waterLevel, a, b, c)); }
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(); }