/// <summary> /// Sets the <see cref="WaveConditionsInputWaterLevelType"/> of the <paramref name="waveConditionsInput"/> /// based on the <see cref="NormativeProbabilityType"/>. /// </summary> /// <param name="waveConditionsInput">The <see cref="WaveConditionsInput"/> to set the water level type for.</param> /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to set the <paramref name="waveConditionsInput"/> for.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="waveConditionsInput"/> is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is an invalid value.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is a valid value, /// but unsupported.</exception> public static void SetWaterLevelType(WaveConditionsInput waveConditionsInput, NormativeProbabilityType normativeProbabilityType) { if (waveConditionsInput == null) { throw new ArgumentNullException(nameof(waveConditionsInput)); } if (!Enum.IsDefined(typeof(NormativeProbabilityType), normativeProbabilityType)) { throw new InvalidEnumArgumentException(nameof(normativeProbabilityType), (int)normativeProbabilityType, typeof(NormativeProbabilityType)); } switch (normativeProbabilityType) { case NormativeProbabilityType.MaximumAllowableFloodingProbability: waveConditionsInput.WaterLevelType = WaveConditionsInputWaterLevelType.MaximumAllowableFloodingProbability; break; case NormativeProbabilityType.SignalFloodingProbability: waveConditionsInput.WaterLevelType = WaveConditionsInputWaterLevelType.SignalFloodingProbability; break; default: throw new NotSupportedException(); } }
public void AddCalculationsFromLocations_MultipleLocationsEmptyCalculationBase_ReturnsUniquelyNamedCalculationsWithCorrectInputSet( NormativeProbabilityType normativeProbabilityType, WaveConditionsInputWaterLevelType expectedWaveConditionsInputWaterLevelType) { // Setup const string name = "name"; var locations = new[] { new HydraulicBoundaryLocation(1, name, 1, 1), new HydraulicBoundaryLocation(2, name, 2, 2) }; var calculationBases = new List <ICalculationBase>(); // Call GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(locations, calculationBases, normativeProbabilityType); // Assert Assert.AreEqual(2, calculationBases.Count); var firstCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation)calculationBases.First(); Assert.AreEqual(name, firstCalculation.Name); GrassCoverErosionOutwardsWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters; Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, firstCalculationInput.WaterLevelType); var secondCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation)calculationBases.ElementAt(1); Assert.AreEqual($"{name} (1)", secondCalculation.Name); GrassCoverErosionOutwardsWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters; Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, secondCalculationInput.WaterLevelType); }
/// <summary> /// Gets the relevant collection of <see cref="HydraulicBoundaryLocationCalculation"/> based on the <see cref="NormativeProbabilityType"/> of the /// assessment section. /// </summary> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> to get the collections of /// <see cref="HydraulicBoundaryLocationCalculation"/> from.</param> /// <returns>A collection of <see cref="HydraulicBoundaryLocationCalculation"/> from the <see cref="IAssessmentSection"/> /// based on the <see cref="NormativeProbabilityType"/>.</returns> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="assessmentSection"/> /// contains an invalid value of <see cref="NormativeProbabilityType"/>.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="assessmentSection"/> /// contains a valid value of <see cref="NormativeProbabilityType"/>, but unsupported.</exception> private static IEnumerable <HydraulicBoundaryLocationCalculation> GetHydraulicBoundaryLocationCalculations(IAssessmentSection assessmentSection) { NormativeProbabilityType normativeProbabilityType = assessmentSection.FailureMechanismContribution.NormativeProbabilityType; if (!Enum.IsDefined(typeof(NormativeProbabilityType), normativeProbabilityType)) { throw new InvalidEnumArgumentException(nameof(normativeProbabilityType), (int)normativeProbabilityType, typeof(NormativeProbabilityType)); } IEnumerable <HydraulicBoundaryLocationCalculation> calculations; switch (normativeProbabilityType) { case NormativeProbabilityType.SignalFloodingProbability: calculations = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability; break; case NormativeProbabilityType.MaximumAllowableFloodingProbability: calculations = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability; break; default: throw new NotSupportedException(); } return(calculations); }
public void NormativeProbabilityType_Always_HandlerCalledAndPropertySet() { // Setup FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(); var mocks = new MockRepository(); var failureMechanismContributionNormChangeHandler = mocks.StrictMock <IFailureMechanismContributionNormChangeHandler>(); failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNormativeProbabilityType(null)) .IgnoreArguments() .WhenCalled(invocation => { var actionToPerform = (Action)invocation.Arguments[0]; actionToPerform(); }); mocks.ReplayAll(); var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler); const NormativeProbabilityType newValue = NormativeProbabilityType.SignalFloodingProbability; // Call properties.NormativeProbabilityType = newValue; // Assert Assert.AreEqual(newValue, failureMechanismContribution.NormativeProbabilityType); mocks.VerifyAll(); }
public void GivenCalculationsWithoutOutput_WhenChangingProbability_ThenActionPerformedAndContributionNotified( NormativeProbabilityType normativeProbabilityType, Func <AssessmentSection, IEnumerable <HydraulicBoundaryLocationCalculation> > getLocationCalculationsFunc, WaveConditionsInputWaterLevelType waterLevelType) { // Given DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); tester.ClickOk(); }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType; IEnumerable <HydraulicBoundaryLocationCalculation> calculationsBelongingToNorm = getLocationCalculationsFunc(assessmentSection); var waveConditionsCalculations = new List <ICalculation <WaveConditionsInput> >(); waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations .Cast <GrassCoverErosionOutwardsWaveConditionsCalculation>()); waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations .Cast <StabilityStoneCoverWaveConditionsCalculation>()); waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations .Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>()); var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()).Repeat.Once(); mocks.ReplayAll(); calculationsBelongingToNorm.ForEachElementDo(c => { c.Output = null; c.Attach(observer); }); waveConditionsCalculations.ForEachElementDo(c => { c.InputParameters.WaterLevelType = waterLevelType; c.ClearOutput(); c.Attach(observer); }); assessmentSection.FailureMechanismContribution.Attach(observer); var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection); // When var actionPerformed = false; void Call() => handler.ChangeProbability(() => actionPerformed = true); // Then TestHelper.AssertLogMessagesCount(Call, 0); Assert.IsTrue(actionPerformed); mocks.VerifyAll(); }
private static void GenerateWaveImpactAsphaltCoverWaveConditionsCalculations(IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations, List <ICalculationBase> calculationCollection, NormativeProbabilityType normativeProbabilityType) { WaveImpactAsphaltCoverWaveConditionsCalculationConfigurationHelper.AddCalculationsFromLocations( hydraulicBoundaryLocations, calculationCollection, normativeProbabilityType); }
private static void GenerateStabilityStoneCoverCalculations(IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations, List <ICalculationBase> calculationCollection, NormativeProbabilityType normativeProbabilityType) { StabilityStoneCoverCalculationConfigurationHelper.AddCalculationsFromLocations( hydraulicBoundaryLocations, calculationCollection, normativeProbabilityType); }
public void SetWaterLevelType_WithWaveConditionsInputAndVariousNormativeProbabilityTypes_SetsWaterLevelType( NormativeProbabilityType normativeProbabilityType, WaveConditionsInputWaterLevelType expectedWaveConditionsInputWaterLevelType) { // Setup var waveConditionsInput = new WaveConditionsInput(); // Call WaveConditionsInputHelper.SetWaterLevelType(waveConditionsInput, normativeProbabilityType); // Assert Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, waveConditionsInput.WaterLevelType); }
public void SetWaterLevelType_InvalidNormativeProbabilityType_ThrowsInvalidEnumArgumentException() { // Setup const NormativeProbabilityType normativeProbabilityType = (NormativeProbabilityType)99; // Call void Call() => WaveConditionsInputHelper.SetWaterLevelType(new WaveConditionsInput(), normativeProbabilityType); // Assert var expectedMessage = $"The value of argument 'normativeProbabilityType' ({normativeProbabilityType}) is invalid for Enum type '{nameof(NormativeProbabilityType)}'."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage); Assert.AreEqual("normativeProbabilityType", exception.ParamName); }
public void ClearAllWaveConditionsCalculationOutputWithNormativeProbabilityType_InvalidNormativeProbabilityType_ThrowsInvalidEnumArgumentException() { // Setup const NormativeProbabilityType normativeProbabilityType = (NormativeProbabilityType)99; // Call void Call() => WaveConditionsDataSynchronizationService.ClearAllWaveConditionsCalculationOutput <ICalculatableFailureMechanism, ICalculation <WaveConditionsInput> >( new TestCalculatableFailureMechanism(), normativeProbabilityType); // Assert var expectedMessage = $"The value of argument 'normativeProbabilityType' ({normativeProbabilityType}) is invalid for Enum type '{nameof(NormativeProbabilityType)}'."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage); Assert.AreEqual("normativeProbabilityType", exception.ParamName); }
public void GetNormativeHydraulicBoundaryLocationCalculation_HydraulicBoundaryLocation_ReturnsCorrespondingCalculation( IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation, NormativeProbabilityType normativeProbabilityType, HydraulicBoundaryLocationCalculation calculation) { // Setup assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType; // Call HydraulicBoundaryLocationCalculation normativeHydraulicBoundaryLocationCalculation = assessmentSection.GetNormativeHydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation); // Assert Assert.AreSame(calculation, normativeHydraulicBoundaryLocationCalculation); }
public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutput_ReturnsCorrespondingAssessmentLevel( IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation, NormativeProbabilityType normativeProbabilityType, HydraulicBoundaryLocationCalculation calculation) { // Setup assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType; // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert RoundedDouble expectedNormativeAssessmentLevel = calculation.Output.Result; Assert.AreEqual(expectedNormativeAssessmentLevel, normativeAssessmentLevel); }
private IEnumerable <IObservable> ClearNormDependingHydraulicBoundaryLocationCalculationOutput(bool normativeProbability) { NormativeProbabilityType normativeProbabilityToClearFor = GetNormativeProbabilityToClearFor(normativeProbability, assessmentSection.FailureMechanismContribution.NormativeProbabilityType); IEnumerable <HydraulicBoundaryLocationCalculation> calculationsToClear = GetHydraulicBoundaryLocationCalculationsToClear(normativeProbabilityToClearFor); var affectedObjects = new List <IObservable>(); affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(calculationsToClear)); affectedObjects.AddRange(RiskeerDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(assessmentSection, normativeProbabilityToClearFor)); if (affectedObjects.Any()) { log.Info(Resources.FailureMechanismContributionNormChangeHandler_ClearNormDependingHydraulicBoundaryLocationCalculationOutput_Calculation_results_cleared); } return(affectedObjects); }
/// <summary> /// Creates a calculation and sets the <paramref name="hydraulicBoundaryLocation"/> /// and the water level type on its input. /// </summary> /// <param name="hydraulicBoundaryLocation">The <see cref="HydraulicBoundaryLocation"/> to set.</param> /// <param name="calculations">The list of calculations to base the calculation name from.</param> /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to base the water level type input on.</param> /// <returns>An <see cref="ICalculationBase"/> representing a stability stone cover calculation.</returns> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is an invalid value.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is a valid value, /// but unsupported.</exception> private static ICalculationBase CreateStabilityStoneCoverWaveConditionsCalculation( HydraulicBoundaryLocation hydraulicBoundaryLocation, IEnumerable <ICalculationBase> calculations, NormativeProbabilityType normativeProbabilityType) { string nameBase = hydraulicBoundaryLocation.Name; var calculation = new StabilityStoneCoverWaveConditionsCalculation { Name = NamingHelper.GetUniqueName(calculations, nameBase, c => c.Name), InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; WaveConditionsInputHelper.SetWaterLevelType(calculation.InputParameters, normativeProbabilityType); return(calculation); }
private void SetSelectionProperties() { ReferenceLineMetaSelectionRow referenceLineMetaSelectionRow = GetSelectedReferenceLineMetaSelectionRow(); if (referenceLineMetaSelectionRow != null) { SelectedReferenceLineMeta = referenceLineMetaSelectionRow.ReferenceLineMeta; SelectedNormativeProbabilityType = SignalFloodingProbabilityRadioButton.Checked ? NormativeProbabilityType.SignalFloodingProbability : NormativeProbabilityType.MaximumAllowableFloodingProbability; double maximumAllowableFloodingProbability = GetFloodingProbability(referenceLineMetaSelectionRow.MaximumAllowableFloodingProbabilityReturnPeriod); SelectedMaximumAllowableFloodingProbability = maximumAllowableFloodingProbability; SelectedSignalFloodingProbability = referenceLineMetaSelectionRow.SignalFloodingProbabilityReturnPeriod.HasValue ? GetFloodingProbability(referenceLineMetaSelectionRow.SignalFloodingProbabilityReturnPeriod.Value) : maximumAllowableFloodingProbability; } }
/// <summary> /// Adds <see cref="StabilityStoneCoverWaveConditionsCalculation"/> in the <paramref name="calculations"/> /// based on the <paramref name="locations"/> and the <paramref name="normativeProbabilityType"/>. /// </summary> /// <param name="locations">Locations to base the calculation upon.</param> /// <param name="calculations">The list to update.</param> /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to set the water level type input for.</param> /// <exception cref="ArgumentNullException">Throw when any <paramref name="locations"/> /// or <paramref name="calculations"/> is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is an invalid value.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is a valid value, /// but unsupported.</exception> public static void AddCalculationsFromLocations(IEnumerable <HydraulicBoundaryLocation> locations, List <ICalculationBase> calculations, NormativeProbabilityType normativeProbabilityType) { if (locations == null) { throw new ArgumentNullException(nameof(locations)); } if (calculations == null) { throw new ArgumentNullException(nameof(calculations)); } foreach (HydraulicBoundaryLocation hydraulicBoundaryLocation in locations) { calculations.Add(CreateStabilityStoneCoverWaveConditionsCalculation(hydraulicBoundaryLocation, calculations, normativeProbabilityType)); } }
public void AddCalculationsFromLocations_MultipleCalculationsAndDuplicateNameInCalculationBase_ReturnsUniquelyNamedCalculationsWithCorrectInputSet( NormativeProbabilityType normativeProbabilityType, WaveConditionsInputWaterLevelType expectedWaveConditionsInputWaterLevelType) { // Setup const string name = "name"; var locations = new[] { new HydraulicBoundaryLocation(1, name, 1, 1), new HydraulicBoundaryLocation(2, name, 2, 2) }; var calculationBases = new List <ICalculationBase> { new WaveImpactAsphaltCoverWaveConditionsCalculation { Name = name } }; // Call WaveImpactAsphaltCoverWaveConditionsCalculationConfigurationHelper.AddCalculationsFromLocations(locations, calculationBases, normativeProbabilityType); // Assert Assert.AreEqual(3, calculationBases.Count); var firstCalculation = (WaveImpactAsphaltCoverWaveConditionsCalculation)calculationBases.ElementAt(1); Assert.AreEqual($"{name} (1)", firstCalculation.Name); WaveConditionsInput firstCalculationInput = firstCalculation.InputParameters; Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, firstCalculationInput.WaterLevelType); var secondCalculation = (WaveImpactAsphaltCoverWaveConditionsCalculation)calculationBases.ElementAt(2); Assert.AreEqual($"{name} (2)", secondCalculation.Name); WaveConditionsInput secondCalculationInput = secondCalculation.InputParameters; Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation); Assert.AreEqual(expectedWaveConditionsInputWaterLevelType, secondCalculationInput.WaterLevelType); }
/// <summary> /// Creates a new instance of <see cref="AssessmentSection"/>. /// </summary> /// <param name="selectedItem">The selected <see cref="ReferenceLineMeta"/>.</param> /// <param name="maximumAllowableFloodingProbability">The maximum allowable flooding probability of the assessment section.</param> /// <param name="signalFloodingProbability">The signal flooding probability of the assessment section.</param> /// <param name="normativeProbabilityType">The normative probability type of the assessment section.</param> /// <returns>The newly created <see cref="AssessmentSection"/>.</returns> /// <exception cref="ArgumentOutOfRangeException">Thrown when: /// <list type="bullet"> /// <item><paramref name="maximumAllowableFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item><paramref name="signalFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item>The <paramref name="signalFloodingProbability"/> is larger than <paramref name="maximumAllowableFloodingProbability"/>.</item> /// </list> /// </exception> private AssessmentSection CreateAssessmentSection(ReferenceLineMeta selectedItem, double maximumAllowableFloodingProbability, double signalFloodingProbability, NormativeProbabilityType normativeProbabilityType) { AssessmentSection assessmentSection; AssessmentSectionSettings settingOfSelectedAssessmentSection = settings.FirstOrDefault(s => s.AssessmentSectionId == selectedItem.AssessmentSectionId); if (settingOfSelectedAssessmentSection == null) { log.Warn(Resources.AssessmentSectionFromFileCommandHandler_CreateAssessmentSection_No_settings_found_for_AssessmentSection); assessmentSection = CreateDikeAssessmentSection(maximumAllowableFloodingProbability, signalFloodingProbability); } else { assessmentSection = settingOfSelectedAssessmentSection.IsDune ? CreateDuneAssessmentSection(maximumAllowableFloodingProbability, signalFloodingProbability, settingOfSelectedAssessmentSection.N) : CreateDikeAssessmentSection(maximumAllowableFloodingProbability, signalFloodingProbability, settingOfSelectedAssessmentSection.N); } assessmentSection.Name = string.Format(IntegrationResources.AssessmentSection_Id_0, selectedItem.AssessmentSectionId); assessmentSection.Id = selectedItem.AssessmentSectionId; if (!selectedItem.ReferenceLine.Points.Any()) { log.Warn(Resources.AssessmentSectionFromFileCommandHandler_CreateAssessmentSection_Importing_ReferenceLineFailed); } else { assessmentSection.ReferenceLine.SetGeometry(selectedItem.ReferenceLine.Points); } assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType; return(assessmentSection); }
/// <summary> /// Clears the output for all calculations that corresponds with the <paramref name="normativeProbabilityType"/> /// in the given <paramref name="failureMechanism"/>. /// </summary> /// <param name="failureMechanism">The failure mechanism which contains the calculations.</param> /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to clear for.</param> /// <typeparam name="TFailureMechanism">The type of the calculatable failure mechanism.</typeparam> /// <typeparam name="TCalculation">The type of the calculation.</typeparam> /// <returns>An <see cref="IEnumerable{T}"/> of calculations which are affected by clearing the output.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="failureMechanism"/> is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is invalid.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is not supported.</exception> public static IEnumerable <IObservable> ClearAllWaveConditionsCalculationOutput <TFailureMechanism, TCalculation>( TFailureMechanism failureMechanism, NormativeProbabilityType normativeProbabilityType) where TFailureMechanism : ICalculatableFailureMechanism where TCalculation : ICalculation <WaveConditionsInput> { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } WaveConditionsInputWaterLevelType waterLevelType = GetWaterLevelTypeFromNormativeProbabilityType(normativeProbabilityType); var affectedItems = new List <IObservable>(); foreach (TCalculation calculation in failureMechanism.Calculations .Cast <TCalculation>() .Where(c => c.InputParameters.WaterLevelType == waterLevelType)) { affectedItems.AddRange(RiskeerCommonDataSynchronizationService.ClearCalculationOutput(calculation)); } return(affectedItems); }
/// <summary> /// Tries to create the <see cref="AssessmentSection"/>. /// </summary> /// <param name="selectedItem">The selected <see cref="ReferenceLineMeta"/>.</param> /// <param name="maximumAllowableFloodingProbability">The maximum allowable flooding probability of the assessment section.</param> /// <param name="signalFloodingProbability">The signal flooding probability of the assessment section.</param> /// <param name="normativeProbabilityType">The normative probability type of the assessment section.</param> /// <returns>The created <see cref="AssessmentSection"/>.</returns> /// <exception cref="CriticalFileValidationException">Thrown when: /// <list type="bullet"> /// <item><paramref name="maximumAllowableFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item><paramref name="signalFloodingProbability"/> is not in the interval [0.000001, 0.1] or is <see cref="double.NaN"/>;</item> /// <item>The <paramref name="signalFloodingProbability"/> is larger than <paramref name="maximumAllowableFloodingProbability"/>.</item> /// </list> /// </exception> private AssessmentSection TryCreateAssessmentSection(ReferenceLineMeta selectedItem, double maximumAllowableFloodingProbability, double signalFloodingProbability, NormativeProbabilityType normativeProbabilityType) { try { return(CreateAssessmentSection(selectedItem, maximumAllowableFloodingProbability, signalFloodingProbability, normativeProbabilityType)); } catch (ArgumentOutOfRangeException exception) { var normValidityRange = new Range <double>(1.0 / 1000000, 1.0 / 10); string message = string.Format(Resources.AssessmentSectionFromFileCommandHandler_Unable_to_create_assessmentSection_with_MaximumAllowableFloodingProbability_0_and_SignalFloodingProbability_1_Probabilities_should_be_in_Range_2_, ProbabilityFormattingHelper.Format(maximumAllowableFloodingProbability), ProbabilityFormattingHelper.Format(signalFloodingProbability), normValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)); throw new CriticalFileValidationException(message, exception); } }
private IEnumerable <HydraulicBoundaryLocationCalculation> GetHydraulicBoundaryLocationCalculationsToClear(NormativeProbabilityType normativeProbabilityToClearFor) { return(normativeProbabilityToClearFor == NormativeProbabilityType.MaximumAllowableFloodingProbability ? assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability : assessmentSection.WaterLevelCalculationsForSignalFloodingProbability); }
private static NormativeProbabilityType GetNormativeProbabilityToClearFor(bool normativeProbability, NormativeProbabilityType normativeProbabilityType) { if (normativeProbability) { return(normativeProbabilityType); } return(normativeProbabilityType == NormativeProbabilityType.MaximumAllowableFloodingProbability ? NormativeProbabilityType.SignalFloodingProbability : NormativeProbabilityType.MaximumAllowableFloodingProbability); }
/// <summary> /// Gets the <see cref="WaveConditionsInputWaterLevelType"/> based on the given <paramref name="normativeProbabilityType"/>. /// </summary> /// <param name="normativeProbabilityType">The <see cref="NormativeProbabilityType"/> to get the <see cref="WaveConditionsInputWaterLevelType"/> from.</param> /// <returns>A <see cref="WaveConditionsInputWaterLevelType"/>.</returns> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="normativeProbabilityType"/> is invalid.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="normativeProbabilityType"/> is not supported.</exception> private static WaveConditionsInputWaterLevelType GetWaterLevelTypeFromNormativeProbabilityType(NormativeProbabilityType normativeProbabilityType) { if (!Enum.IsDefined(typeof(NormativeProbabilityType), normativeProbabilityType)) { throw new InvalidEnumArgumentException(nameof(normativeProbabilityType), (int)normativeProbabilityType, typeof(NormativeProbabilityType)); } switch (normativeProbabilityType) { case NormativeProbabilityType.MaximumAllowableFloodingProbability: return(WaveConditionsInputWaterLevelType.MaximumAllowableFloodingProbability); case NormativeProbabilityType.SignalFloodingProbability: return(WaveConditionsInputWaterLevelType.SignalFloodingProbability); default: throw new NotSupportedException(); } }
public void ClearAllWaveConditionsCalculationOutputWithNormativeProbabilityType_WithAllData_ClearsOutputAndReturnsAffectedObjects(NormativeProbabilityType normativeProbabilityType) { // Setup var calculation1 = new TestWaveConditionsCalculation <WaveConditionsInput>(new WaveConditionsInput { WaterLevelType = WaveConditionsInputWaterLevelType.SignalFloodingProbability }, true); var calculation2 = new TestWaveConditionsCalculation <WaveConditionsInput>(new WaveConditionsInput { WaterLevelType = WaveConditionsInputWaterLevelType.MaximumAllowableFloodingProbability }, true); var calculation3 = new TestWaveConditionsCalculation <WaveConditionsInput>(new WaveConditionsInput { WaterLevelType = WaveConditionsInputWaterLevelType.None }, true); var calculation4 = new TestWaveConditionsCalculation <WaveConditionsInput>(new WaveConditionsInput { WaterLevelType = WaveConditionsInputWaterLevelType.UserDefinedTargetProbability }, true); var mocks = new MockRepository(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); failureMechanism.Stub(fm => fm.Calculations).Return(new[] { calculation1, calculation2, calculation3, calculation4 }); mocks.ReplayAll(); TestWaveConditionsCalculation <WaveConditionsInput>[] expectedAffectedCalculations = { normativeProbabilityType == NormativeProbabilityType.MaximumAllowableFloodingProbability ? calculation2 : calculation1 }; // Call IEnumerable <IObservable> affectedCalculations = WaveConditionsDataSynchronizationService.ClearAllWaveConditionsCalculationOutput <ICalculatableFailureMechanism, TestWaveConditionsCalculation <WaveConditionsInput> >( failureMechanism, normativeProbabilityType); // Assert CollectionAssert.AreEqual(expectedAffectedCalculations, affectedCalculations); Assert.IsTrue(expectedAffectedCalculations.All(c => !c.HasOutput)); Assert.IsTrue(failureMechanism.Calculations.Except(expectedAffectedCalculations).All(c => c.HasOutput)); mocks.VerifyAll(); }
public void NormativeProbability_DifferentNormativeProbabilityTypes_ReturnNorm(NormativeProbabilityType normativeProbabilityType, double expectedProbability) { // Setup var failureMechanismContribution = new FailureMechanismContribution(0.1, 0.01) { NormativeProbabilityType = normativeProbabilityType }; // Call double normativeProbability = failureMechanismContribution.NormativeProbability; // Assert Assert.AreEqual(expectedProbability, normativeProbability); }
public void GivenCalculationsWithOutput_WhenChangingProbability_ThenAllDependingOutputClearedAndActionPerformedAndAllAffectedObjectsNotified( NormativeProbabilityType normativeProbabilityType, Func <AssessmentSection, IEnumerable <HydraulicBoundaryLocationCalculation> > getCalculationsFunc, WaveConditionsInputWaterLevelType waterLevelType) { // Given DialogBoxHandler = (name, wnd) => { var tester = new MessageBoxTester(wnd); tester.ClickOk(); }; AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); assessmentSection.FailureMechanismContribution.NormativeProbabilityType = normativeProbabilityType; IEnumerable <HydraulicBoundaryLocationCalculation> expectedCalculationsToClear = getCalculationsFunc(assessmentSection); var waveConditionsCalculations = new List <ICalculation <WaveConditionsInput> >(); waveConditionsCalculations.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations .Cast <GrassCoverErosionOutwardsWaveConditionsCalculation>() .Where(c => c.HasOutput)); waveConditionsCalculations.AddRange(assessmentSection.StabilityStoneCover.Calculations .Cast <StabilityStoneCoverWaveConditionsCalculation>() .Where(c => c.HasOutput)); waveConditionsCalculations.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations .Cast <WaveImpactAsphaltCoverWaveConditionsCalculation>() .Where(c => c.HasOutput)); waveConditionsCalculations.ForEachElementDo(c => c.InputParameters.WaterLevelType = waterLevelType); IEnumerable <IObservable> expectedAffectedObjects = new IObservable[] { assessmentSection.FailureMechanismContribution } .Concat(expectedCalculationsToClear) .Concat(waveConditionsCalculations) .ToArray(); var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()).Repeat.Times(expectedAffectedObjects.Count()); mocks.ReplayAll(); expectedAffectedObjects.ForEachElementDo(obj => obj.Attach(observer)); var handler = new FailureMechanismContributionNormChangeHandler(assessmentSection); // Precondition CollectionAssert.IsNotEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); CollectionAssert.IsNotEmpty(waveConditionsCalculations.Where(c => c.HasOutput)); // When var actionPerformed = false; void Call() => handler.ChangeProbability(() => actionPerformed = true); // Then var expectedMessages = new[] { "Alle berekende hydraulische belastingen behorende bij de gewijzigde norm zijn verwijderd." }; TestHelper.AssertLogMessagesAreGenerated(Call, expectedMessages, 1); Assert.IsTrue(actionPerformed); CollectionAssert.IsEmpty(expectedCalculationsToClear.Where(c => c.HasOutput)); CollectionAssert.IsEmpty(waveConditionsCalculations.Where(c => c.HasOutput)); mocks.VerifyAll(); }
private static void GenerateGrassCoverErosionOutwardsWaveConditionsCalculations(IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations, List <ICalculationBase> calculationCollection, NormativeProbabilityType normativeProbabilityType) { GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations( hydraulicBoundaryLocations, calculationCollection, normativeProbabilityType); }
public void Import_TargetProbabilityNull_DataAddedToModel(NormativeProbabilityType normativeProbabilityType, WaveConditionsInputWaterLevelType expectedWaterLevelType) { // Setup string filePath = Path.Combine(path, "validConfigurationWithoutTargetProbability.xml"); var calculationGroup = new CalculationGroup(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "Locatie", 10, 20); var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new[] { new Point2D(0, 0), new Point2D(1, 1), new Point2D(2, 2) }, new BreakWater(BreakWaterType.Caisson, 0), new ForeshoreProfile.ConstructionProperties { Id = "Voorlandprofiel", Name = "VoorlandProfielName" }); var failureMechanismContribution = new FailureMechanismContribution(0.1, 0.1) { NormativeProbabilityType = normativeProbabilityType }; var importer = new TestWaveConditionsCalculationConfigurationImporter( filePath, calculationGroup, new[] { hydraulicBoundaryLocation }, new[] { foreshoreProfile }, failureMechanismContribution, Enumerable.Empty <HydraulicBoundaryLocationCalculationsForTargetProbability>()); // Call var successful = false; Action call = () => successful = importer.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{filePath}'.", 1); Assert.IsTrue(successful); var expectedCalculation = new TestTargetTestWaveConditionsCalculation { Name = "Berekening 1", InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation, WaterLevelType = expectedWaterLevelType, UpperBoundaryRevetment = (RoundedDouble)10, LowerBoundaryRevetment = (RoundedDouble)2, UpperBoundaryWaterLevels = (RoundedDouble)9, LowerBoundaryWaterLevels = (RoundedDouble)4, StepSize = WaveConditionsInputStepSize.Half, ForeshoreProfile = foreshoreProfile, Orientation = (RoundedDouble)5.5, UseForeshore = false, UseBreakWater = true, BreakWater = { Height = (RoundedDouble)6.6, Type = BreakWaterType.Caisson } } }; Assert.AreEqual(1, calculationGroup.Children.Count); AssertWaveConditionsCalculation(expectedCalculation, (ICalculation <WaveConditionsInput>)calculationGroup.Children[0]); }