Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs =================================================================== diff -u -r1e533850c7711172462df1e8f569b9f3ff950045 -rbb32237c29a9f16a3d7e65c1baf833f5fb0c1988 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision 1e533850c7711172462df1e8f569b9f3ff950045) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision bb32237c29a9f16a3d7e65c1baf833f5fb0c1988) @@ -155,6 +155,8 @@ const string locationName = "punt_flw_"; const string activityName = "GetActivityName"; const string calculationName = "locationName"; + const string ringId = "11-1"; + const double norm = 30; var hydraulicBoundaryLocationMock = mockRepository.Stub(); hydraulicBoundaryLocationMock.Expect(hbl => hbl.Name).Return(locationName).Repeat.AtLeastOnce(); @@ -167,7 +169,7 @@ var activity = new DesignWaterLevelCalculationActivity(calculationMessageProviderMock, hydraulicBoundaryLocationMock, - validFilePath, "", 30); + validFilePath, ringId, norm); using (new DesignWaterLevelCalculationServiceConfig()) { @@ -178,6 +180,10 @@ // Assert Assert.AreSame(calculationMessageProviderMock, testService.MessageProvider); + Assert.AreSame(hydraulicBoundaryLocationMock, testService.HydraulicBoundaryLocation); + Assert.AreEqual(validFilePath, testService.HydraulicBoundaryDatabaseFilePath); + Assert.AreEqual(ringId, testService.RingId); + Assert.AreEqual(norm, testService.Norm); } Assert.AreEqual(ActivityState.Executed, activity.State); mockRepository.VerifyAll(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil.Test/TestDesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r1e533850c7711172462df1e8f569b9f3ff950045 -rbb32237c29a9f16a3d7e65c1baf833f5fb0c1988 --- Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil.Test/TestDesignWaterLevelCalculationServiceTest.cs (.../TestDesignWaterLevelCalculationServiceTest.cs) (revision 1e533850c7711172462df1e8f569b9f3ff950045) +++ Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil.Test/TestDesignWaterLevelCalculationServiceTest.cs (.../TestDesignWaterLevelCalculationServiceTest.cs) (revision bb32237c29a9f16a3d7e65c1baf833f5fb0c1988) @@ -45,17 +45,48 @@ } [Test] - public void Calculate_SetCalculationConvergenceOutputDefault_ReturnsExpectedValue() + public void Calculate_Always_SetsInputParameters() { // Setup + const double norm = 12.34; + const string filePath = "C:/temp"; + const string ringId = "11-1"; + var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); var hydraulicBoundaryLocationMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var service = new TestDesignWaterLevelCalculationService(); + + // Call + service.Calculate(calculationMessageProviderMock, + hydraulicBoundaryLocationMock, + filePath, + ringId, + norm); + + // Assert + Assert.AreSame(calculationMessageProviderMock, service.MessageProvider); + Assert.AreSame(hydraulicBoundaryLocationMock, service.HydraulicBoundaryLocation); + Assert.AreEqual(filePath, service.HydraulicBoundaryDatabaseFilePath); + Assert.AreEqual(ringId, service.RingId); + Assert.AreEqual(norm, service.Norm); + } + + [Test] + public void Calculate_SetCalculationConvergenceOutputDefault_ReturnsExpectedValue() + { + // Setup const double norm = 12.34; + var mockRepository = new MockRepository(); + var calculationMessageProviderMock = mockRepository.StrictMock(); + var hydraulicBoundaryLocationMock = mockRepository.StrictMock(); + + mockRepository.ReplayAll(); + var service = new TestDesignWaterLevelCalculationService(); + // Call ReliabilityIndexCalculationOutput output = service.Calculate(calculationMessageProviderMock, hydraulicBoundaryLocationMock, @@ -72,6 +103,8 @@ public void Calculate_SetCalculationConvergenceOutputCalculatedConverged_ReturnsExpectedValue() { // Setup + const double norm = 12.34; + var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); var hydraulicBoundaryLocationMock = mockRepository.StrictMock(); @@ -81,7 +114,6 @@ { SetCalculationConvergenceOutput = CalculationConvergence.CalculatedConverged }; - const double norm = 12.34; // Call ReliabilityIndexCalculationOutput output = service.Calculate(calculationMessageProviderMock, @@ -100,6 +132,8 @@ public void Calculate_SetCalculationConvergenceOutputNotCalculated_ReturnsNull() { // Setup + const double norm = 12.34; + var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); var hydraulicBoundaryLocationMock = mockRepository.StrictMock(); @@ -109,7 +143,6 @@ { SetCalculationConvergenceOutput = CalculationConvergence.NotCalculated }; - const double norm = 12.34; // Call ReliabilityIndexCalculationOutput output = service.Calculate(calculationMessageProviderMock, @@ -127,6 +160,8 @@ public void Calculate_SetCalculationConvergenceOutputCalculatedNotConverged_ReturnsExpectedValue() { // Setup + const double norm = 12.34; + var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); var hydraulicBoundaryLocationMock = mockRepository.StrictMock(); @@ -136,7 +171,6 @@ { SetCalculationConvergenceOutput = CalculationConvergence.CalculatedNotConverged }; - const double norm = 12.34; // Call ReliabilityIndexCalculationOutput output = service.Calculate(calculationMessageProviderMock, Index: Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/TestDesignWaterLevelCalculationService.cs =================================================================== diff -u -rc78a5b1d66fba1148ab5880357ce3c20a042c9ed -rbb32237c29a9f16a3d7e65c1baf833f5fb0c1988 --- Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/TestDesignWaterLevelCalculationService.cs (.../TestDesignWaterLevelCalculationService.cs) (revision c78a5b1d66fba1148ab5880357ce3c20a042c9ed) +++ Ringtoets/Common/test/Ringtoets.Common.Service.TestUtil/TestDesignWaterLevelCalculationService.cs (.../TestDesignWaterLevelCalculationService.cs) (revision bb32237c29a9f16a3d7e65c1baf833f5fb0c1988) @@ -50,16 +50,43 @@ /// public ICalculationMessageProvider MessageProvider { get; private set; } + /// + /// Gets the used . + /// + public IHydraulicBoundaryLocation HydraulicBoundaryLocation { get; private set; } + + /// + /// Gets the used hydraulic boundary databse file path. + /// + public string HydraulicBoundaryDatabaseFilePath { get; private set; } + + /// + /// Gets the used ring id. + /// + public string RingId { get; private set; } + + /// + /// Gets the used norm. + /// + public double Norm { get; private set; } + public bool Validate(string name, string hydraulicBoundaryDatabaseFilePath) { return true; } - public ReliabilityIndexCalculationOutput Calculate(ICalculationMessageProvider messageProvider, - IHydraulicBoundaryLocation hydraulicBoundaryLocation, string hydraulicBoundaryDatabaseFilePath, - string ringId, double norm) + public ReliabilityIndexCalculationOutput Calculate(ICalculationMessageProvider messageProvider, + IHydraulicBoundaryLocation hydraulicBoundaryLocation, + string hydraulicBoundaryDatabaseFilePath, + string ringId, + double norm) { MessageProvider = messageProvider; + HydraulicBoundaryLocation = hydraulicBoundaryLocation; + HydraulicBoundaryDatabaseFilePath = hydraulicBoundaryDatabaseFilePath; + RingId = ringId; + Norm = norm; + switch (returnValidOutput) { case CalculationConvergence.NotCalculated: Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -r74e4aee44698b08453c18b16432edeaf103fbd0d -rbb32237c29a9f16a3d7e65c1baf833f5fb0c1988 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 74e4aee44698b08453c18b16432edeaf103fbd0d) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision bb32237c29a9f16a3d7e65c1baf833f5fb0c1988) @@ -293,8 +293,8 @@ return; } - var correctedNormFactor = assessmentSection.FailureMechanismContribution.Norm* - (failureMechanism.Contribution/100)/ + var correctedNormFactor = assessmentSection.FailureMechanismContribution.Norm/ + (failureMechanism.Contribution/100)* failureMechanism.GeneralInput.N; hydraulicBoundaryLocationCalculationGuiService.CalculateDesignWaterLevels( Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs =================================================================== diff -u -r1e533850c7711172462df1e8f569b9f3ff950045 -rbb32237c29a9f16a3d7e65c1baf833f5fb0c1988 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision 1e533850c7711172462df1e8f569b9f3ff950045) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/TreeNodeInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsContextTreeNodeInfoTest.cs) (revision bb32237c29a9f16a3d7e65c1baf833f5fb0c1988) @@ -358,6 +358,75 @@ } [Test] + public void CalculateDesignWaterLevelsFromContextMenu_Always_SendsRightInputToCalculationService() + { + // Setup + string filePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite"); + + var guiMock = mockRepository.DynamicMock(); + var location = new HydraulicBoundaryLocation(1, "HydraulicBoundaryLocation", 1.1, 2.2); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 1 + }; + var assessmentSectionMock = mockRepository.Stub(); + assessmentSectionMock.Stub(a => a.Id).Return("Id"); + assessmentSectionMock.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + assessmentSectionMock.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution(Enumerable.Empty(), 1, 300)); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = filePath, + Locations = + { + location + } + }; + + var grassCoverErosionOutwardsHydraulicBoundaryLocation = new GrassCoverErosionOutwardsHydraulicBoundaryLocation(location); + var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext(new ObservableList + { + grassCoverErosionOutwardsHydraulicBoundaryLocation + }, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Expect(g => g.MainWindow).Return(mockRepository.Stub()); + mockRepository.ReplayAll(); + + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + plugin.Gui = guiMock; + plugin.Activate(); + + using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) + using (new DesignWaterLevelCalculationServiceConfig()) + { + var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance; + + // Call + contextMenuAdapter.Items[contextMenuRunDesignWaterLevelCalculationsIndex].PerformClick(); + + // Assert + Assert.AreSame(grassCoverErosionOutwardsHydraulicBoundaryLocation, testService.HydraulicBoundaryLocation); + Assert.AreEqual(filePath, testService.HydraulicBoundaryDatabaseFilePath); + Assert.AreEqual(assessmentSectionMock.Id, testService.RingId); + + var expectedNorm = assessmentSectionMock.FailureMechanismContribution.Norm/ + (failureMechanism.Contribution/100)* + failureMechanism.GeneralInput.N; + Assert.AreEqual(expectedNorm, testService.Norm); + } + } + } + mockRepository.VerifyAll(); + } + + [Test] [RequiresSTA] public void GivenHydraulicBoundaryDatabaseWithNonExistingFilePath_WhenCalculatingDesignWaterLevelFromContextMenu_ThenLogMessagesAddedPreviousOutputNotAffected() { @@ -477,19 +546,17 @@ plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) + using (new DesignWaterLevelCalculationServiceConfig()) { - using (new DesignWaterLevelCalculationServiceConfig()) - { - var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance; - testService.SetCalculationConvergenceOutput = CalculationConvergence.NotCalculated; + var testService = (TestDesignWaterLevelCalculationService) DesignWaterLevelCalculationService.Instance; + testService.SetCalculationConvergenceOutput = CalculationConvergence.NotCalculated; - // When - contextMenuAdapter.Items[contextMenuRunDesignWaterLevelCalculationsIndex].PerformClick(); + // When + contextMenuAdapter.Items[contextMenuRunDesignWaterLevelCalculationsIndex].PerformClick(); - // Then - Assert.IsInstanceOf(testService.MessageProvider); - Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); - } + // Then + Assert.IsInstanceOf(testService.MessageProvider); + Assert.AreEqual(CalculationConvergence.NotCalculated, grassCoverErosionOutwardsHydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); } } }