public void GetAssessmentLevel_ValidInputWithHydraulicBoundaryLocation_ReturnsExpectedValue( WaveConditionsInputWaterLevelType waterLevelType, Func <WaveConditionsInput, IAssessmentSection, double> getExpectedAssessmentLevel) { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); var input = new WaveConditionsInput { HydraulicBoundaryLocation = hydraulicBoundaryLocation, WaterLevelType = waterLevelType, CalculationsTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.First() }; // Call double assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(input, assessmentSection); // Assert Assert.AreEqual(getExpectedAssessmentLevel(input, assessmentSection), assessmentLevel); }
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); }
private static SelectableTargetProbability CreateSelectableTargetProbability(IAssessmentSection assessmentSection, IEnumerable <HydraulicBoundaryLocationCalculation> calculations, WaveConditionsInputWaterLevelType waterLevelType, double targetProbability) { return(new SelectableTargetProbability(assessmentSection, calculations, waterLevelType, targetProbability)); }
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(); }
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 GetAssessmentLevel_InputWithInvalidWaterLevelType_ThrowsInvalidEnumArgumentException() { // Setup const WaveConditionsInputWaterLevelType waterLevelType = (WaveConditionsInputWaterLevelType)99; var waveConditionsInput = new WaveConditionsInput { WaterLevelType = waterLevelType }; // Call void Call() => WaveConditionsInputHelper.GetAssessmentLevel(waveConditionsInput, new AssessmentSectionStub()); // Assert var expectedMessage = $"The value of argument 'WaterLevelType' ({waterLevelType}) is invalid for Enum type '{nameof(WaveConditionsInputWaterLevelType)}'."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage); Assert.AreEqual("WaterLevelType", exception.ParamName); }
public void GetTargetProbability_ValidInput_ReturnsExpectedValue( WaveConditionsInputWaterLevelType waterLevelType, Func <WaveConditionsInput, IAssessmentSection, double> getExpectedTargetProbability) { // Setup var assessmentSection = new AssessmentSectionStub(); var input = new WaveConditionsInput { WaterLevelType = waterLevelType, CalculationsTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.01) }; // Call double targetProbability = WaveConditionsInputHelper.GetTargetProbability(input, assessmentSection); // Assert Assert.AreEqual(getExpectedTargetProbability(input, assessmentSection), targetProbability); }
/// <summary> /// Creates a new instance of <see cref="SelectableTargetProbability"/>. /// </summary> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/>.</param> /// <param name="hydraulicBoundaryLocationCalculations">The collection of <see cref="HydraulicBoundaryLocationCalculation"/>.</param> /// <param name="waterLevelType">The <see cref="WaveConditionsInputWaterLevelType"/> belonging to the <paramref name="hydraulicBoundaryLocationCalculations"/>.</param> /// <param name="targetProbability">The target probability belonging to the <paramref name="hydraulicBoundaryLocationCalculations"/>.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="assessmentSection"/> or <paramref name="hydraulicBoundaryLocationCalculations"/> is <c>null</c>.</exception> public SelectableTargetProbability(IAssessmentSection assessmentSection, IEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations, WaveConditionsInputWaterLevelType waterLevelType, double targetProbability) { if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (hydraulicBoundaryLocationCalculations == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryLocationCalculations)); } this.assessmentSection = assessmentSection; HydraulicBoundaryLocationCalculations = hydraulicBoundaryLocationCalculations; WaterLevelType = waterLevelType; TargetProbability = targetProbability; }
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> /// 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); }
public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup IAssessmentSection assessmentSection = new AssessmentSectionStub(); const WaveConditionsInputWaterLevelType waterLevelType = WaveConditionsInputWaterLevelType.MaximumAllowableFloodingProbability; const double targetProbability = 0.1; var selectableTargetProbability = new SelectableTargetProbability(assessmentSection, assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, waterLevelType, targetProbability); var properties = new ObjectPropertiesWithSelectableTargetProbability( selectableTargetProbability, new[] { new SelectableTargetProbability(assessmentSection, assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, waterLevelType, targetProbability) }); var propertyBag = new DynamicPropertyBag(properties); var editor = new WaveConditionsInputContextTargetProbabilitySelectionEditor(); var someValue = new object(); var mocks = new MockRepository(); var serviceProvider = mocks.Stub <IServiceProvider>(); var service = mocks.Stub <IWindowsFormsEditorService>(); var descriptorContext = mocks.Stub <ITypeDescriptorContext>(); serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service); descriptorContext.Stub(c => c.Instance).Return(propertyBag); mocks.ReplayAll(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreEqual(selectableTargetProbability, result); mocks.VerifyAll(); }
public void GetAssessmentLevel_ValidInputWithoutHydraulicBoundaryLocation_ReturnsNaN(WaveConditionsInputWaterLevelType waterLevelType) { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new TestHydraulicBoundaryLocation() }, true); var input = new WaveConditionsInput { WaterLevelType = waterLevelType, CalculationsTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.First() }; // Call double assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(input, assessmentSection); // Assert Assert.IsNaN(assessmentLevel); }
public void Import_ValidConfigurationWithValidData_DataAddedToModel(FailureMechanismContribution failureMechanismContribution, HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability, WaveConditionsInputWaterLevelType expectedWaterLevelType) { // Setup string filePath = Path.Combine(path, "validConfigurationFullCalculation.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 importer = new TestWaveConditionsCalculationConfigurationImporter( filePath, calculationGroup, new[] { hydraulicBoundaryLocation }, new[] { foreshoreProfile }, failureMechanismContribution, new[] { calculationsForTargetProbability }); // 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, CalculationsTargetProbability = expectedWaterLevelType == WaveConditionsInputWaterLevelType.UserDefinedTargetProbability ? calculationsForTargetProbability : null, 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]); }
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(); }