public void UpdateObserver_DataUpdated_MapLayersSameOrder() { // Setup var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); var assessmentSection = new AssessmentSectionStub { ReferenceLine = referenceLine }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) }); AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); MapDataCollection mapData = extendedView.Map.Data; MapData dataToMove = mapData.Collection.ElementAt(0); mapData.Remove(dataToMove); mapData.Add(dataToMove); // Precondition var referenceLineMapData = (MapLineData)mapData.Collection.ElementAt(referenceLineIndex + 1); Assert.AreEqual("Referentielijn", referenceLineMapData.Name); var hrLocationsMapData = (MapPointData)mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); Assert.AreEqual("Hydraulische belastingen", hrLocationsMapData.Name); // Call assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) }); assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); // Assert var actualReferenceLineMapData = (MapLineData)mapData.Collection.ElementAt(referenceLineIndex + 1); Assert.AreEqual("Referentielijn", actualReferenceLineMapData.Name); var actualHrLocationsMapData = (MapPointData)mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); Assert.AreEqual("Hydraulische belastingen", actualHrLocationsMapData.Name); }
public void CreateCalculationActivity_WithValidCalculation_ReturnsGrassCoverErosionOutwardsWaveConditionsCalculationActivityWithParametersSet() { // Setup GrassCoverErosionOutwardsFailureMechanism failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; hydraulicBoundaryDatabase.FilePath = validFilePath; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName 1"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation); // Call CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <GrassCoverErosionOutwardsWaveConditionsCalculationActivity>(activity); AssertGrassCoverErosionOutwardsWaveConditionsCalculationActivity( activity, calculation, assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result, hydraulicBoundaryDatabase); }
public void CreateHydraulicBoundaryLocationFeatures_WithLocations_ReturnsLocationFeaturesCollection(bool setOutput) { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "location1", 1, 1), new HydraulicBoundaryLocation(2, "location2", 2, 2) }, setOutput); Dictionary <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, string> waterLevels = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.ToDictionary( tp => (IObservableEnumerable <HydraulicBoundaryLocationCalculation>)tp.HydraulicBoundaryLocationCalculations, tp => $"h - {ProbabilityFormattingHelper.Format(tp.TargetProbability)}"); waterLevels.Add(assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, "h - 1/30.000"); waterLevels.Add(assessmentSection.WaterLevelCalculationsForSignalFloodingProbability, "h - 1/30.000 (1)"); IEnumerable <AggregatedHydraulicBoundaryLocation> locations = AggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations( assessmentSection.HydraulicBoundaryDatabase.Locations, waterLevels, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.ToDictionary( tp => (IObservableEnumerable <HydraulicBoundaryLocationCalculation>)tp.HydraulicBoundaryLocationCalculations, tp => $"Hs - {ProbabilityFormattingHelper.Format(tp.TargetProbability)}")); // Call IEnumerable <MapFeature> features = RiskeerMapDataFeaturesFactory.CreateHydraulicBoundaryLocationFeatures(locations); // Assert MapFeaturesTestHelper.AssertHydraulicBoundaryFeaturesData(assessmentSection, features); }
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 CreateCalculationActivity_WithValidCalculation_ReturnsMacroStabilityInwardsCalculationActivityWithParametersSet() { // Setup var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var assessmentSection = new AssessmentSectionStub { FailureMechanismContribution = { NormativeProbabilityType = NormativeProbabilityType.MaximumAllowableFloodingProbability } }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var random = new Random(39); HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.Single(); hydraulicBoundaryLocationCalculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble()); MacroStabilityInwardsCalculationScenario calculation = CreateValidCalculation(hydraulicBoundaryLocation); // Call CalculatableActivity activity = MacroStabilityInwardsCalculationActivityFactory.CreateCalculationActivity(calculation, new GeneralMacroStabilityInwardsInput(), assessmentSection); // Assert Assert.IsInstanceOf <MacroStabilityInwardsCalculationActivity>(activity); AssertMacroStabilityInwardsCalculationActivity(activity, calculation, hydraulicBoundaryLocationCalculation); }
private IAssessmentSection CreateAssessmentSectionWithHydraulicBoundaryOutput() { var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = validFilePath, Locations = { hydraulicBoundaryLocation } } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(9.3); return(assessmentSection); }
private static IEnumerable <TestCaseData> GetAssessmentSectionConfigurations() { var assessmentSectionWithTargetProbabilities = new AssessmentSectionStub(); assessmentSectionWithTargetProbabilities.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); yield return(new TestCaseData(assessmentSectionWithTargetProbabilities, new[] { "Waterstanden bij vaste doelkans/Waterstanden_30000.shp", "Waterstanden bij vaste doelkans/Waterstanden_30000 (1).shp", "Waterstanden bij vrije doelkans/Waterstanden_10000.shp", "Waterstanden bij vrije doelkans/Waterstanden_100000.shp", "Golfhoogten bij vrije doelkans/Golfhoogten_4000.shp", "Golfhoogten bij vrije doelkans/Golfhoogten_40000.shp" }).SetName("With UserDefinedTargetProbabilities")); var assessmentSectionWithoutTargetProbabilities = new AssessmentSectionStub(); assessmentSectionWithoutTargetProbabilities.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); assessmentSectionWithoutTargetProbabilities.WaterLevelCalculationsForUserDefinedTargetProbabilities.Clear(); assessmentSectionWithoutTargetProbabilities.WaveHeightCalculationsForUserDefinedTargetProbabilities.Clear(); yield return(new TestCaseData(assessmentSectionWithoutTargetProbabilities, new[] { "Waterstanden bij vaste doelkans/Waterstanden_30000.shp", "Waterstanden bij vaste doelkans/Waterstanden_30000 (1).shp" }).SetName("Without UserDefinedTargetProbabilities")); }
public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenSelectedWaveHeightTargetProbabilityIndexUpdatedAndCollectionNotified_ThenMapDataAndSelectedMetaDataAttributeUpdated( Action <ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > shiftItemAction, string selectedTargetProbabilityFormat, string expectedSelectedTargetProbabilityFormat) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); const double targetProbability = 0.001; var assessmentSection = new AssessmentSectionStub(); assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.Clear(); assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.AddRange(new[] { new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability), new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability), new HydraulicBoundaryLocationCalculationsForTargetProbability(targetProbability) }); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection)) { string targetProbabilityString = ProbabilityFormattingHelper.Format(targetProbability); string selectedProbabilityString = string.Format(selectedTargetProbabilityFormat, targetProbabilityString); mapLayer.MapData.SelectedMetaDataAttribute = string.Format(waveHeightDisplayNameFormat, selectedProbabilityString); mapLayer.MapData.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); // When ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> waveHeightCalculationsForUserDefinedTargetProbabilities = assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities; shiftItemAction(waveHeightCalculationsForUserDefinedTargetProbabilities); waveHeightCalculationsForUserDefinedTargetProbabilities.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); string expectedSelectedProbabilityString = string.Format(expectedSelectedTargetProbabilityFormat, targetProbabilityString); Assert.AreEqual(string.Format(waveHeightDisplayNameFormat, expectedSelectedProbabilityString), mapLayer.MapData.SelectedMetaDataAttribute); } mocks.VerifyAll(); }
private static void SetHydraulicBoundaryLocationToAssessmentSection(AssessmentSectionStub assessmentSection, TestHydraulicBoundaryLocation hydraulicBoundaryLocation) { assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output = new TestHydraulicBoundaryLocationCalculationOutput(2.0); }
/// <summary> /// Gets a collection of <see cref="TestCaseData"/> containing an assessment level configuration for all types /// of <see cref="WaveConditionsInputWaterLevelType"/>. /// </summary> /// <returns>A collection of <see cref="TestCaseData"/>, in which each item contains: /// <list type="bullet"> /// <item>the configured assessment section;</item> /// <item>a method for configuring the wave conditions input at stake;</item> /// <item>the expected assessment level given the combination of the before-mentioned assessment section, the configured /// hydraulic boundary location and the configured water level type.</item> /// </list> /// </returns> public static IEnumerable <TestCaseData> GetAssessmentLevelConfigurationPerWaterLevelType() { var calculationsForTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.01); var assessmentSection = new AssessmentSectionStub { WaterLevelCalculationsForUserDefinedTargetProbabilities = { calculationsForTargetProbability } }; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); yield return(new TestCaseData( assessmentSection, new Action <WaveConditionsInput>(input => { input.HydraulicBoundaryLocation = hydraulicBoundaryLocation; input.WaterLevelType = WaveConditionsInputWaterLevelType.None; }), RoundedDouble.NaN)); yield return(new TestCaseData( assessmentSection, new Action <WaveConditionsInput>(input => { input.HydraulicBoundaryLocation = hydraulicBoundaryLocation; input.WaterLevelType = WaveConditionsInputWaterLevelType.MaximumAllowableFloodingProbability; }), assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.First().Output.Result)); yield return(new TestCaseData( assessmentSection, new Action <WaveConditionsInput>(input => { input.HydraulicBoundaryLocation = hydraulicBoundaryLocation; input.WaterLevelType = WaveConditionsInputWaterLevelType.SignalFloodingProbability; }), assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.First().Output.Result)); yield return(new TestCaseData( assessmentSection, new Action <WaveConditionsInput>(input => { input.HydraulicBoundaryLocation = hydraulicBoundaryLocation; input.WaterLevelType = WaveConditionsInputWaterLevelType.UserDefinedTargetProbability; input.CalculationsTargetProbability = calculationsForTargetProbability; }), calculationsForTargetProbability.HydraulicBoundaryLocationCalculations.First().Output.Result)); }
public void Run_CalculationWithInvalidHydraulicBoundaryDatabaseFilePath_DoesNotPerformCalculationAndLogsError() { // Setup string invalidFilePath = Path.Combine(testDataPath, "NonExisting.sqlite"); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = invalidFilePath } }; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new StabilityStoneCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call void Call() => activity.Run(); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); Assert.AreEqual("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " + $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet.", msgs[2]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]); }); Assert.AreEqual(ActivityState.Failed, activity.State); } mockRepository.VerifyAll(); }
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]); }); } } }
public void CreateCalculationActivitiesForCalculationGroup_WithValidCalculations_ReturnsMacroStabilityInwardsCalculationActivitiesWithParametersSet() { // Setup var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); var assessmentSection = new AssessmentSectionStub { FailureMechanismContribution = { NormativeProbabilityType = NormativeProbabilityType.MaximumAllowableFloodingProbability } }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation1, hydraulicBoundaryLocation2 }); var random = new Random(39); HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation1 = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.First(); hydraulicBoundaryLocationCalculation1.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble()); HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation2 = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.ElementAt(1); hydraulicBoundaryLocationCalculation2.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble()); MacroStabilityInwardsCalculationScenario calculation1 = CreateValidCalculation(hydraulicBoundaryLocation1); MacroStabilityInwardsCalculationScenario calculation2 = CreateValidCalculation(hydraulicBoundaryLocation2); var calculations = new CalculationGroup { Children = { calculation1, calculation2 } }; // Call IEnumerable <CalculatableActivity> activities = MacroStabilityInwardsCalculationActivityFactory.CreateCalculationActivities( calculations, new GeneralMacroStabilityInwardsInput(), assessmentSection); // Assert CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(MacroStabilityInwardsCalculationActivity)); Assert.AreEqual(2, activities.Count()); AssertMacroStabilityInwardsCalculationActivity(activities.First(), calculation1, hydraulicBoundaryLocationCalculation1); AssertMacroStabilityInwardsCalculationActivity(activities.ElementAt(1), calculation2, hydraulicBoundaryLocationCalculation2); }
public void CreateWaterLevelCalculationActivitiesForNormTargetProbabilities_WithValidDataAndUsePreprocessorStates_ExpectedInputSetToActivities(bool usePreprocessor) { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(usePreprocessor); var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation("locationName 1"); var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation("locationName 2"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation1, hydraulicBoundaryLocation2 }); // Call IEnumerable <CalculatableActivity> activities = AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.CreateWaterLevelCalculationActivitiesForNormTargetProbabilities(assessmentSection); // Assert Assert.AreEqual(4, activities.Count()); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; double maximumAllowableFloodingProbability = assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability; const string expectedMaximumAllowableFloodingProbabilityText = "1/30.000"; double signalFloodingProbability = assessmentSection.FailureMechanismContribution.SignalFloodingProbability; const string expectedSignalFloodingProbabilityText = "1/30.000 (1)"; AssertDesignWaterLevelCalculationActivity(activities.ElementAt(0), hydraulicBoundaryLocation1, maximumAllowableFloodingProbability, expectedMaximumAllowableFloodingProbabilityText, hydraulicBoundaryDatabase); AssertDesignWaterLevelCalculationActivity(activities.ElementAt(1), hydraulicBoundaryLocation2, maximumAllowableFloodingProbability, expectedMaximumAllowableFloodingProbabilityText, hydraulicBoundaryDatabase); AssertDesignWaterLevelCalculationActivity(activities.ElementAt(2), hydraulicBoundaryLocation1, signalFloodingProbability, expectedSignalFloodingProbabilityText, hydraulicBoundaryDatabase); AssertDesignWaterLevelCalculationActivity(activities.ElementAt(3), hydraulicBoundaryLocation2, signalFloodingProbability, expectedSignalFloodingProbabilityText, hydraulicBoundaryDatabase); }
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); } } }
private static IAssessmentSection GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations() { var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocations = new[] { new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation() }; assessmentSection.SetHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, true); return(assessmentSection); }
public void GivenMapLayerWithHydraulicBoundaryLocations_WhenChangingHydraulicBoundaryLocationsDataAndObserversNotified_ThenMapDataUpdated() { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) }); using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection)) { mapLayer.MapData.Attach(observer); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); // When assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) }); assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); } mocks.VerifyAll(); }
public void CreateInstance_WithContextAndNormativeProbabilityTypeSignalFloodingProbability_ExpectedProperties() { // Setup var assessmentSection = new AssessmentSectionStub { FailureMechanismContribution = { NormativeProbabilityType = NormativeProbabilityType.SignalFloodingProbability } }; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var scenario = new MacroStabilityInwardsCalculationScenario { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var context = new MacroStabilityInwardsInputContext( scenario.InputParameters, scenario, Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(), Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); // Call IObjectProperties objectProperties = info.CreateInstance(context); // Assert Assert.IsInstanceOf <MacroStabilityInwardsInputContextProperties>(objectProperties); Assert.AreSame(context, objectProperties.Data); double expectedAssessmentLevel = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.ElementAt(0).Output.Result; Assert.AreEqual(expectedAssessmentLevel, ((MacroStabilityInwardsInputContextProperties)objectProperties).AssessmentLevel); }
public void GetNormativeAssessmentLevel_NoCorrespondingAssessmentLevelOutput_ReturnsNaN() { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.FailureMechanismContribution.NormativeProbabilityType = new Random(32).NextEnumValue <NormativeProbabilityType>(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert Assert.IsNaN(normativeAssessmentLevel); }
private static AssessmentSectionStub CreateAssessmentSection() { var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = validFilePath } }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new TestHydraulicBoundaryLocation() }); HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); return(assessmentSection); }
public void Constructor_ExpectedValues() { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) }); // Call using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection)) { // Assert Assert.IsInstanceOf <IDisposable>(mapLayer); MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); } }
public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenCalculationsForUserDefinedTargetProbabilitiesUpdatedAndNotified_ThenMapDataUpdated( Func <IAssessmentSection, ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > getTargetProbabilitiesFunc) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection)) { ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> targetProbabilities = getTargetProbabilitiesFunc(assessmentSection); var newTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1); newTargetProbability.HydraulicBoundaryLocationCalculations.AddRange(assessmentSection.HydraulicBoundaryDatabase.Locations .Select(l => new HydraulicBoundaryLocationCalculation(l)) .ToArray()); targetProbabilities.Add(newTargetProbability); targetProbabilities.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); // When HydraulicBoundaryLocationCalculation calculation = newTargetProbability.HydraulicBoundaryLocationCalculations.First(); calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble()); calculation.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); } mocks.VerifyAll(); }
public void GivenMapLayerWithHydraulicBoundaryLocationsData_WhenNotSelectedTargetProbabilityRemovedAndNotified_ThenMapDataUpdated( Func <IAssessmentSection, ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> > getTargetProbabilitiesFunc, string displayName) { // Given var mocks = new MockRepository(); var observer = mocks.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); using (var mapLayer = new HydraulicBoundaryLocationsMapLayer(assessmentSection)) { ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability> targetProbabilities = getTargetProbabilitiesFunc(assessmentSection); HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbabilityToRemove = targetProbabilities.First(); HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability = targetProbabilities.Last(); mapLayer.MapData.SelectedMetaDataAttribute = string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability)); mapLayer.MapData.NotifyObservers(); mapLayer.MapData.Attach(observer); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); // When targetProbabilities.Remove(calculationsForTargetProbabilityToRemove); targetProbabilities.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapLayer.MapData); Assert.AreEqual(string.Format(displayName, ProbabilityFormattingHelper.Format(calculationsForTargetProbability.TargetProbability)), mapLayer.MapData.SelectedMetaDataAttribute); } mocks.VerifyAll(); }
public void CreateWaveConditionsCalculationActivitiesForCalculationGroup_WithValidCalculations_ReturnsGrassCoverErosionOutwardsWaveConditionsCalculationActivitiesWithParametersSet() { // Setup GrassCoverErosionOutwardsFailureMechanism failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; hydraulicBoundaryDatabase.FilePath = validFilePath; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName 1"); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); GrassCoverErosionOutwardsWaveConditionsCalculation calculation1 = CreateValidCalculation(hydraulicBoundaryLocation); GrassCoverErosionOutwardsWaveConditionsCalculation calculation2 = CreateValidCalculation(hydraulicBoundaryLocation); var calculations = new CalculationGroup { Children = { calculation1, calculation2 } }; // Call IEnumerable <CalculatableActivity> activities = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivities( calculations, failureMechanism, assessmentSection); // Assert CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(GrassCoverErosionOutwardsWaveConditionsCalculationActivity)); Assert.AreEqual(2, activities.Count()); RoundedDouble assessmentLevel = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result; AssertGrassCoverErosionOutwardsWaveConditionsCalculationActivity(activities.First(), calculation1, assessmentLevel, hydraulicBoundaryDatabase); AssertGrassCoverErosionOutwardsWaveConditionsCalculationActivity(activities.ElementAt(1), calculation2, assessmentLevel, hydraulicBoundaryDatabase); }
public void Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse() { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CreatingZipFileThrowsCriticalFileWriteException_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "test.zip"); var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, filePath); try { using (var helper = new FileDisposeHelper(filePath)) { helper.LockFiles(); // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " + "Er zijn geen hydraulische belastingenlocaties geëxporteerd."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage); Assert.IsFalse(isExported); } } finally { DirectoryHelper.TryDelete(directoryPath); } }
public void Constructor_WithReferenceLineAndHydraulicBoundaryDatabase_DataUpdatedToCollectionOfFilledMapData() { // Setup var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); var assessmentSection = new AssessmentSectionStub { ReferenceLine = referenceLine }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) }); // Call AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); // Assert Assert.IsInstanceOf <MapDataCollection>(extendedView.Map.Data); MapDataCollection mapData = extendedView.Map.Data; Assert.IsNotNull(mapData); MapData hydraulicBoundaryLocationsMapData = mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex); MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData); Assert.IsTrue(referenceLineMapData.IsVisible); }
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); }
private static IEnumerable <TestCaseData> GetNormativeHydraulicBoundaryLocationCalculationPerNormativeProbabilityType() { var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); yield return(new TestCaseData( assessmentSection, hydraulicBoundaryLocation, NormativeProbabilityType.SignalFloodingProbability, assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.ElementAt(0))); yield return(new TestCaseData( assessmentSection, hydraulicBoundaryLocation, NormativeProbabilityType.MaximumAllowableFloodingProbability, assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.ElementAt(0))); }
public void Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse() { // Setup var assessmentSection = new AssessmentSectionStub(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) }); string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_HydraulicBoundaryLocationCalculationsExporterReturnsFalse_LogErrorAndReturnFalse)); Directory.CreateDirectory(directoryPath); string filePath = Path.Combine(directoryPath, "test.zip"); var exporter = new HydraulicBoundaryLocationCalculationsExporter(assessmentSection, filePath); try { using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) { // Call var isExported = true; void Call() => isExported = exporter.Export(); // Assert string expectedFilePath = Path.Combine(directoryPath, "~temp", "Waterstanden bij vaste doelkans", "Waterstanden_30000.shp"); string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{expectedFilePath}'. " + "Er zijn geen hydraulische belastingenlocaties geëxporteerd."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage); Assert.IsFalse(isExported); } } finally { DirectoryHelper.TryDelete(directoryPath); } }
public void CreateSemiProbabilisticPipingCalculationActivity_WithValidCalculation_ReturnsActivityWithParametersSet() { // Setup var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var assessmentSection = new AssessmentSectionStub { FailureMechanismContribution = { NormativeProbabilityType = NormativeProbabilityType.MaximumAllowableFloodingProbability } }; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var random = new Random(39); HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability.Single(); hydraulicBoundaryLocationCalculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble()); var calculation = SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestSemiProbabilisticPipingCalculation>( hydraulicBoundaryLocation); var generalPipingInput = new GeneralPipingInput(); // Call CalculatableActivity activity = PipingCalculationActivityFactory.CreateSemiProbabilisticPipingCalculationActivity(calculation, generalPipingInput, assessmentSection); // Assert Assert.IsInstanceOf <SemiProbabilisticPipingCalculationActivity>(activity); AssertSemiProbabilisticPipingCalculationActivity(activity, calculation, hydraulicBoundaryLocationCalculation); }