Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -ra8b6ee77e67283b8d9ce37067afc17cac3fad241 -r812870236917a63b3c908298a80135bc52c4c214 --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision a8b6ee77e67283b8d9ce37067afc17cac3fad241) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 812870236917a63b3c908298a80135bc52c4c214) @@ -1019,18 +1019,11 @@ calculateAllItem); var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); - var changeHandler = new ClearIllustrationPointsOfHydraulicBoundaryLocationCalculationCollectionChangeHandler( - GetInquiryHelper(), - RiskeerCommonFormsResources.HydraulicLoads_DisplayName, - () => GrassCoverErosionOutwardsDataSynchronizationService.ClearIllustrationPointResultsForDesignWaterLevelAndWaveHeightCalculations( - failureMechanism, assessmentSection)); return builder.AddExportItem() .AddSeparator() .AddCustomItem(calculateAllItem) .AddSeparator() - .AddClearIllustrationPointsOfCalculationsItem(() => false, changeHandler) - .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() .Build(); Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs =================================================================== diff -u -r6f64cab16e5ef3e1431ed0a4543692cf5891262a -r812870236917a63b3c908298a80135bc52c4c214 --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision 6f64cab16e5ef3e1431ed0a4543692cf5891262a) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision 812870236917a63b3c908298a80135bc52c4c214) @@ -24,9 +24,7 @@ using System.Drawing; using System.IO; using System.Linq; -using System.Threading; using System.Windows.Forms; -using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; @@ -43,8 +41,6 @@ using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Data.TestUtil; -using Riskeer.Common.Data.TestUtil.IllustrationPoints; -using Riskeer.Common.Plugin.TestUtil; using Riskeer.Common.Service.TestUtil; using Riskeer.GrassCoverErosionOutwards.Data; using Riskeer.GrassCoverErosionOutwards.Data.TestUtil; @@ -61,7 +57,6 @@ public class GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContextTreeNodeInfoTest : NUnitFormTest { private const int contextMenuCalculateAllIndex = 2; - private const int contextMenuClearIllustrationPointsIndex = 4; private MockRepository mockRepository; private GrassCoverErosionOutwardsPlugin plugin; @@ -135,8 +130,6 @@ menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); - menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); @@ -241,88 +234,6 @@ } [Test] - [TestCaseSource(nameof(GetHydraulicBoundaryLocationCalculations))] - public void ContextMenuStrip_HydraulicBoundaryLocationCalculationsWithIllustrationPoints_ContextMenuItemClearAllIllustrationPointsEnabledAndTooltipSet( - Func getHydraulicBoundaryLocationCalculationFunc) - { - // Setup - var random = new Random(21); - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.SetHydraulicBoundaryLocations(failureMechanism, assessmentSection, new[] - { - new TestHydraulicBoundaryLocation() - }); - - HydraulicBoundaryLocationCalculation calculation = getHydraulicBoundaryLocationCalculationFunc(assessmentSection, failureMechanism); - calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint()); - - var nodeData = new GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContext(assessmentSection.HydraulicBoundaryDatabase, - failureMechanism, - assessmentSection); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mockRepository.Stub(); - gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub()); - mockRepository.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - ToolStripItem contextMenuItem = contextMenu.Items[contextMenuClearIllustrationPointsIndex]; - - Assert.AreEqual("Wis alle illustratiepunten...", contextMenuItem.Text); - Assert.AreEqual("Wis alle berekende illustratiepunten.", contextMenuItem.ToolTipText); - TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ClearIllustrationPointsIcon, contextMenuItem.Image); - Assert.IsTrue(contextMenuItem.Enabled); - } - } - } - - [Test] - public void ContextMenuStrip_HydraulicBoundaryLocationCalculationsWithoutIllustrationPoints_ContextMenuItemClearAllIllustrationPointsDisabled() - { - // Setup - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.SetHydraulicBoundaryLocations(failureMechanism, assessmentSection, new[] - { - new TestHydraulicBoundaryLocation() - }); - - var nodeData = new GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContext(assessmentSection.HydraulicBoundaryDatabase, - failureMechanism, - assessmentSection); - - using (var treeViewControl = new TreeViewControl()) - { - var gui = mockRepository.Stub(); - gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub()); - mockRepository.ReplayAll(); - - plugin.Gui = gui; - - // Call - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) - { - // Assert - ToolStripItem contextMenuItem = contextMenu.Items[contextMenuClearIllustrationPointsIndex]; - Assert.IsFalse(contextMenuItem.Enabled); - } - } - } - - [Test] public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled() { // Given @@ -372,41 +283,12 @@ gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub()); var calculatorFactory = mockRepository.Stub(); - var designWaterLevelCalculator = new TestDesignWaterLevelCalculator - { - Converged = false, - DesignWaterLevel = 2.0 - }; - var waveHeightCalculator = new TestWaveHeightCalculator - { - Converged = false - }; var waveConditionsCalculator = new TestWaveConditionsCosineCalculator { Converged = false }; HydraulicBoundaryCalculationSettings expectedCalculationSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase); - calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(Arg.Is.NotNull)) - .WhenCalled(invocation => - { - HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( - expectedCalculationSettings, - (HydraRingCalculationSettings) invocation.Arguments[0]); - }) - .Return(designWaterLevelCalculator) - .Repeat - .Times(5); - calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg.Is.NotNull)) - .WhenCalled(invocation => - { - HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( - expectedCalculationSettings, - (HydraRingCalculationSettings) invocation.Arguments[0]); - }) - .Return(waveHeightCalculator) - .Repeat - .Times(5); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg.Is.NotNull)) .WhenCalled(invocation => { @@ -432,41 +314,13 @@ TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); - Assert.AreEqual(108, msgs.Length); + Assert.AreEqual(5, msgs.Length); - const string designWaterLevelCalculationTypeDisplayName = "Waterstand"; - const string designWaterLevelCalculationDisplayName = "Waterstand berekening"; + Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs.ElementAt(0)); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs.ElementAt(1)); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs.ElementAt(2)); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs.ElementAt(3)); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "Iv", msgs, 0); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "IIv", msgs, 8); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "IIIv", msgs, 16); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "IVv", msgs, 24); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, designWaterLevelCalculationTypeDisplayName, designWaterLevelCalculationDisplayName, "Vv", msgs, 32); - - const string waveHeightCalculationTypeDisplayName = "Golfhoogte"; - const string waveHeightCalculationDisplayName = "Golfhoogte berekening"; - - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "Iv", msgs, 40); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "IIv", msgs, 48); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "IIIv", msgs, 56); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "IVv", msgs, 64); - HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( - hydraulicBoundaryLocation.Name, waveHeightCalculationTypeDisplayName, waveHeightCalculationDisplayName, "Vv", msgs, 72); - - Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs.ElementAt(80)); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs.ElementAt(81)); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs.ElementAt(82)); - CalculationServiceTestHelper.AssertCalculationStartMessage(msgs.ElementAt(83)); - IEnumerable waterLevels = calculation.InputParameters.GetWaterLevels( failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm.Single().Output.Result); Assert.AreEqual(3, waterLevels.Count()); @@ -566,138 +420,6 @@ Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); } - [Test] - [TestCaseSource(nameof(GetHydraulicBoundaryLocationCalculations))] - [Apartment(ApartmentState.STA)] - public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndDoNotContinue_ThenInquiryAndIllustrationPointsNotCleared( - Func getHydraulicLocationCalculationFunc) - { - // Given - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.SetHydraulicBoundaryLocations(failureMechanism, assessmentSection, new[] - { - new TestHydraulicBoundaryLocation() - }); - - var random = new Random(21); - HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection, failureMechanism); - calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint()); - - HydraulicBoundaryLocationCalculation[] calculationsWithOutput = GetAllHydraulicLocationCalculationsWithOutput(assessmentSection, failureMechanism).ToArray(); - - var messageBoxText = ""; - DialogBoxHandler = (name, wnd) => - { - var helper = new MessageBoxTester(wnd); - messageBoxText = helper.Text; - - helper.ClickCancel(); - }; - - var context = new GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContext(assessmentSection.HydraulicBoundaryDatabase, - failureMechanism, - assessmentSection); - - using (var treeViewControl = new TreeViewControl()) - { - var affectedCalculationObserver = mockRepository.StrictMock(); - - var gui = mockRepository.Stub(); - gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub()); - gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mockRepository.ReplayAll(); - - calculation.Attach(affectedCalculationObserver); - - plugin.Gui = gui; - - using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) - { - // When - contextMenuAdapter.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); - - // Then - const string expectedMessage = "Weet u zeker dat u alle berekende illustratiepunten bij 'Hydraulische belastingen' wilt wissen?"; - Assert.AreEqual(expectedMessage, messageBoxText); - - Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput)); - Assert.IsTrue(calculation.Output.HasGeneralResult); - } - } - } - - [Test] - [TestCaseSource(nameof(GetHydraulicBoundaryLocationCalculations))] - [Apartment(ApartmentState.STA)] - public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinue_ThenInquiryAndIllustrationPointsCleared( - Func getHydraulicLocationCalculationFunc) - { - // Given - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); - GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.SetHydraulicBoundaryLocations(failureMechanism, assessmentSection, new[] - { - new TestHydraulicBoundaryLocation(), - new TestHydraulicBoundaryLocation() - }, true); - - var random = new Random(21); - HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection, failureMechanism); - calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint()); - - HydraulicBoundaryLocationCalculation unaffectedCalculation = assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm.ElementAt(1); - - HydraulicBoundaryLocationCalculation[] calculationsWithOutput = GetAllHydraulicLocationCalculationsWithOutput(assessmentSection, failureMechanism).ToArray(); - - var messageBoxText = ""; - DialogBoxHandler = (name, wnd) => - { - var helper = new MessageBoxTester(wnd); - messageBoxText = helper.Text; - - helper.ClickOk(); - }; - - var context = new GrassCoverErosionOutwardsHydraulicBoundaryDatabaseContext(assessmentSection.HydraulicBoundaryDatabase, - failureMechanism, - assessmentSection); - - using (var treeViewControl = new TreeViewControl()) - { - var affectedCalculationObserver = mockRepository.StrictMock(); - affectedCalculationObserver.Expect(o => o.UpdateObserver()); - var unAffectedCalculationObserver = mockRepository.StrictMock(); - - var gui = mockRepository.Stub(); - gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); - gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); - gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub()); - gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - mockRepository.ReplayAll(); - - calculation.Attach(affectedCalculationObserver); - unaffectedCalculation.Attach(unAffectedCalculationObserver); - - plugin.Gui = gui; - - using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) - { - // When - contextMenuAdapter.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); - - // Then - const string expectedMessage = "Weet u zeker dat u alle berekende illustratiepunten bij 'Hydraulische belastingen' wilt wissen?"; - Assert.AreEqual(expectedMessage, messageBoxText); - - Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput)); - Assert.IsFalse(calculation.Output.HasGeneralResult); - } - } - } - public override void Setup() { mockRepository = new MockRepository(); @@ -749,45 +471,5 @@ } }; } - - private static IEnumerable GetAllHydraulicLocationCalculationsWithOutput(IAssessmentSection assessmentSection, - GrassCoverErosionOutwardsFailureMechanism failureMechanism) - { - return failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm - .Concat(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm) - .Concat(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm) - .Concat(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm) - .Concat(assessmentSection.WaterLevelCalculationsForLowerLimitNorm) - .Concat(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm) - .Concat(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm) - .Concat(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm) - .Concat(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm) - .Concat(assessmentSection.WaveHeightCalculationsForLowerLimitNorm) - .Where(calc => calc.HasOutput); - } - - private static IEnumerable GetHydraulicBoundaryLocationCalculations() - { - yield return new TestCaseData(new Func( - (s, fm) => fm.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => fm.WaterLevelCalculationsForMechanismSpecificSignalingNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => fm.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => s.WaterLevelCalculationsForLowerLimitNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => s.WaterLevelCalculationsForFactorizedLowerLimitNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => fm.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => fm.WaveHeightCalculationsForMechanismSpecificSignalingNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => fm.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => s.WaveHeightCalculationsForLowerLimitNorm.First())); - yield return new TestCaseData(new Func( - (s, fm) => s.WaveHeightCalculationsForFactorizedLowerLimitNorm.First())); - } } } \ No newline at end of file