Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs =================================================================== diff -u -r92210258706d0f57e05552037b676bd941a6fe19 -rf8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision 92210258706d0f57e05552037b676bd941a6fe19) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision f8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e) @@ -366,7 +366,7 @@ } [Test] - public void CalculateDesignWaterLevelsFromContextMenu_Always_SendsRightInputToCalculationService() + public void CalculateDesignWaterLevelsFromContextMenu_HydraulicBoundaryDatabaseWithCanUsePreprocessorFalse_SendsRightInputToCalculationService() { // Setup string filePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite"); @@ -376,17 +376,88 @@ Contribution = 5 }; - IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mockRepository, filePath); - HydraulicBoundaryLocation grassCoverErosionOutwardsHydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(); + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(failureMechanism, mockRepository); + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = filePath, + Locations = + { + hydraulicBoundaryLocation + } + }; + var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext(new ObservableList { - grassCoverErosionOutwardsHydraulicBoundaryLocation + hydraulicBoundaryLocation }, assessmentSection, failureMechanism); - var observer = mockRepository.StrictMock(); - context.Attach(observer); - observer.Expect(o => o.UpdateObserver()); + using (var treeViewControl = new TreeViewControl()) + { + var gui = mockRepository.Stub(); + gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mockRepository.Stub()); + var designWaterLevelCalculator = new TestDesignWaterLevelCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, string.Empty)).Return(designWaterLevelCalculator); + mockRepository.ReplayAll(); + + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + plugin.Gui = gui; + plugin.Activate(); + + using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + contextMenuAdapter.Items[contextMenuRunDesignWaterLevelCalculationsIndex].PerformClick(); + + // Assert + AssessmentLevelCalculationInput designWaterLevelCalculationInput = designWaterLevelCalculator.ReceivedInputs.First(); + + Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); + double expectedProbability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N); + Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(expectedProbability), designWaterLevelCalculationInput.Beta); + } + } + } + mockRepository.VerifyAll(); + } + + [Test] + public void CalculateDesignWaterLevelsFromContextMenu_HydraulicBoundaryDatabaseWithUsePreprocessorTrue_SendsRightInputToCalculationService() + { + // Setup + string filePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite"); + string preprocessorDirectory = TestHelper.GetScratchPadPath(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 5 + }; + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(failureMechanism, mockRepository); + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(true, preprocessorDirectory) + { + FilePath = filePath, + Locations = + { + hydraulicBoundaryLocation + } + }; + + var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext(new ObservableList + { + hydraulicBoundaryLocation + }, assessmentSection, failureMechanism); + using (var treeViewControl = new TreeViewControl()) { var gui = mockRepository.Stub(); @@ -395,7 +466,7 @@ var designWaterLevelCalculator = new TestDesignWaterLevelCalculator(); var calculatorFactory = mockRepository.Stub(); - calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(designWaterLevelCalculator); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, preprocessorDirectory)).Return(designWaterLevelCalculator); mockRepository.ReplayAll(); using (var plugin = new GrassCoverErosionOutwardsPlugin()) @@ -413,7 +484,7 @@ // Assert AssessmentLevelCalculationInput designWaterLevelCalculationInput = designWaterLevelCalculator.ReceivedInputs.First(); - Assert.AreEqual(grassCoverErosionOutwardsHydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); + Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); double expectedProbability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( assessmentSection.FailureMechanismContribution.Norm, failureMechanism.Contribution, @@ -426,6 +497,71 @@ } [Test] + public void CalculateDesignWaterLevelsFromContextMenu_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_SendsRightInputToCalculationService() + { + // Setup + string filePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite"); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 5 + }; + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase(failureMechanism, mockRepository); + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(false, "InvalidPreprocessorDirectory") + { + FilePath = filePath, + Locations = + { + hydraulicBoundaryLocation + } + }; + + var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext(new ObservableList + { + hydraulicBoundaryLocation + }, assessmentSection, failureMechanism); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mockRepository.Stub(); + gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mockRepository.Stub()); + + var designWaterLevelCalculator = new TestDesignWaterLevelCalculator(); + var calculatorFactory = mockRepository.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, string.Empty)).Return(designWaterLevelCalculator); + mockRepository.ReplayAll(); + + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + plugin.Gui = gui; + plugin.Activate(); + + using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + contextMenuAdapter.Items[contextMenuRunDesignWaterLevelCalculationsIndex].PerformClick(); + + // Assert + AssessmentLevelCalculationInput designWaterLevelCalculationInput = designWaterLevelCalculator.ReceivedInputs.First(); + + Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); + double expectedProbability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + failureMechanism.Contribution, + failureMechanism.GeneralInput.N); + Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(expectedProbability), designWaterLevelCalculationInput.Beta); + } + } + } + mockRepository.VerifyAll(); + } + + [Test] [Apartment(ApartmentState.STA)] public void GivenHydraulicBoundaryLocationSucceeds_CalculatingDesignWaterLevelFromContextMenu_ThenLogMessagesAddedOutputSet() { @@ -454,7 +590,7 @@ Converged = false }; var calculatorFactory = mockRepository.Stub(); - calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(designWaterLevelCalculator); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, string.Empty)).Return(designWaterLevelCalculator); mockRepository.ReplayAll(); using (var plugin = new GrassCoverErosionOutwardsPlugin())