Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContextTreeNodeInfoTest.cs
===================================================================
diff -u
--- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContextTreeNodeInfoTest.cs (revision 0)
+++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContextTreeNodeInfoTest.cs (revision 1f219ba0936738435cfa9803a7acd2001294dde7)
@@ -0,0 +1,771 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Base.Storage;
+using Core.Common.Controls.TreeView;
+using Core.Common.TestUtil;
+using Core.Gui;
+using Core.Gui.Commands;
+using Core.Gui.ContextMenu;
+using Core.Gui.Forms.Main;
+using Core.Gui.Forms.ViewHost;
+using Core.Gui.TestUtil;
+using Core.Gui.TestUtil.ContextMenu;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Data.Hydraulics;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Common.Data.TestUtil.IllustrationPoints;
+using Riskeer.Common.Forms.PresentationObjects;
+using Riskeer.Common.Plugin.TestUtil;
+using Riskeer.Common.Service.TestUtil;
+using Riskeer.HydraRing.Calculation.Calculator;
+using Riskeer.HydraRing.Calculation.Calculator.Factory;
+using Riskeer.HydraRing.Calculation.Data.Input;
+using Riskeer.HydraRing.Calculation.TestUtil.Calculator;
+using Riskeer.Integration.Data;
+using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources;
+
+namespace Riskeer.Integration.Plugin.Test.TreeNodeInfos
+{
+ [TestFixture]
+ public class WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContextTreeNodeInfoTest : NUnitFormTest
+ {
+ private const int contextMenuAddTargetProbabilityIndex = 0;
+ private const int contextMenuRunWaveHeightCalculationsIndex = 2;
+ private const int contextMenuClearIllustrationPointsIndex = 4;
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.Service, "HydraRingCalculation");
+
+ [Test]
+ public void Initialized_Always_ExpectedPropertiesSet()
+ {
+ // Setup
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Assert
+ Assert.IsNotNull(info.Text);
+ Assert.IsNull(info.ForeColor);
+ Assert.IsNotNull(info.Image);
+ Assert.IsNotNull(info.ContextMenuStrip);
+ Assert.IsNull(info.EnsureVisibleOnCreate);
+ Assert.IsNull(info.ExpandOnCreate);
+ Assert.IsNotNull(info.ChildNodeObjects);
+ Assert.IsNull(info.CanRename);
+ Assert.IsNull(info.OnNodeRenamed);
+ Assert.IsNull(info.CanRemove);
+ Assert.IsNull(info.OnNodeRemoved);
+ Assert.IsNull(info.CanCheck);
+ Assert.IsNull(info.CheckedState);
+ Assert.IsNull(info.OnNodeChecked);
+ Assert.IsNull(info.CanDrag);
+ Assert.IsNull(info.CanDrop);
+ Assert.IsNull(info.CanInsert);
+ Assert.IsNull(info.OnDrop);
+ }
+ }
+
+ [Test]
+ public void Text_Always_ReturnsSetName()
+ {
+ // Setup
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ string text = info.Text(null);
+
+ // Assert
+ Assert.AreEqual("Golfhoogten bij doelkans", text);
+ }
+ }
+
+ [Test]
+ public void Image_Always_ReturnsGeneralFolderIcon()
+ {
+ // Setup
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ Image image = info.Image(null);
+
+ // Assert
+ TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.GeneralFolderIcon, image);
+ }
+ }
+
+ [Test]
+ public void ChildNodeObjects_Always_ReturnsChildrenOfData()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSectionStub();
+
+ var calculations = new ObservableList
+ {
+ new HydraulicBoundaryLocationCalculationsForTargetProbability(),
+ new HydraulicBoundaryLocationCalculationsForTargetProbability()
+ };
+ var calculationsGroupContext = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ object[] childNodeObjects = info.ChildNodeObjects(calculationsGroupContext);
+
+ // Assert
+ Assert.AreEqual(2, childNodeObjects.Length);
+
+ WaveHeightCalculationsForUserDefinedTargetProbabilityContext[] calculationsContexts = childNodeObjects.OfType().ToArray();
+ Assert.AreEqual(2, calculationsContexts.Length);
+
+ Assert.AreSame(calculations[0], calculationsContexts[0].WrappedData);
+ Assert.AreSame(assessmentSection, calculationsContexts[0].AssessmentSection);
+
+ Assert.AreSame(calculations[1], calculationsContexts[1].WrappedData);
+ Assert.AreSame(assessmentSection, calculationsContexts[1].AssessmentSection);
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods()
+ {
+ // Setup
+ IAssessmentSection assessmentSection = new AssessmentSectionStub();
+
+ var mockRepository = new MockRepository();
+ var menuBuilder = mockRepository.StrictMock();
+ using (mockRepository.Ordered())
+ {
+ 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.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);
+ }
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(new ObservableList(),
+ 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(menuBuilder);
+ gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub());
+ gui.Stub(cmp => cmp.MainWindow).Return(mockRepository.Stub());
+ mockRepository.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ plugin.Gui = gui;
+
+ // Call
+ info.ContextMenuStrip(nodeData, null, treeViewControl);
+ }
+ }
+
+ // Assert
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void ContextMenuStrip_ClickOnAddTargetProbabilityItem_CalculationsForTargetProbabilityAddedAndObserversNotified()
+ {
+ // Given
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
+ {
+ HydraulicBoundaryDatabase =
+ {
+ Locations =
+ {
+ new TestHydraulicBoundaryLocation("Location 1"),
+ new TestHydraulicBoundaryLocation("Location 2")
+ }
+ }
+ };
+
+ var calculations = new ObservableList();
+ var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection);
+
+ var mockRepository = new MockRepository();
+ var calculationsObserver = mockRepository.StrictMock();
+ calculationsObserver.Expect(o => o.UpdateObserver());
+ calculations.Attach(calculationsObserver);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mockRepository);
+
+ var gui = mockRepository.Stub();
+ gui.Stub(g => g.MainWindow).Return(mainWindow);
+ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+ gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
+ gui.Stub(g => g.ProjectStore).Return(mockRepository.Stub());
+
+ mockRepository.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ plugin.Gui = gui;
+ plugin.Activate();
+
+ using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl))
+ {
+ // When
+ contextMenuAdapter.Items[contextMenuAddTargetProbabilityIndex].PerformClick();
+
+ // Then
+ Assert.AreEqual(1, calculations.Count);
+ Assert.AreEqual(0.1, calculations[0].TargetProbability);
+ Assert.AreEqual(2, calculations[0].HydraulicBoundaryLocationCalculations.Count);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet()
+ {
+ // Setup
+ IAssessmentSection assessmentSection = new AssessmentSectionStub();
+
+ var calculations = new ObservableList
+ {
+ new HydraulicBoundaryLocationCalculationsForTargetProbability()
+ };
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection);
+
+ var mockRepository = new MockRepository();
+ 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();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ plugin.Gui = gui;
+
+ // Precondition
+ Assert.IsFalse(assessmentSection.HydraulicBoundaryDatabase.IsLinked());
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ ToolStripItem contextMenuItem = contextMenu.Items[contextMenuRunWaveHeightCalculationsIndex];
+
+ Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text);
+ StringAssert.Contains("Er is geen hydraulische belastingendatabase geïmporteerd.", contextMenuItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateAllIcon, contextMenuItem.Image);
+ Assert.IsFalse(contextMenuItem.Enabled);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll(); // Expect no calls on arguments
+ }
+
+ [Test]
+ public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet()
+ {
+ // Setup
+ IAssessmentSection assessmentSection = new AssessmentSectionStub();
+ assessmentSection.HydraulicBoundaryDatabase.FilePath = "invalidFilePath";
+
+ var calculations = new ObservableList
+ {
+ new HydraulicBoundaryLocationCalculationsForTargetProbability()
+ };
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection);
+
+ var mockRepository = new MockRepository();
+ 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();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ plugin.Gui = gui;
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ ToolStripItem contextMenuItem = contextMenu.Items[contextMenuRunWaveHeightCalculationsIndex];
+
+ Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text);
+ StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateAllIcon, contextMenuItem.Image);
+ Assert.IsFalse(contextMenuItem.Enabled);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll(); // Expect no calls on arguments
+ }
+
+ [Test]
+ public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled()
+ {
+ // Setup
+ IAssessmentSection assessmentSection = new AssessmentSectionStub();
+ assessmentSection.HydraulicBoundaryDatabase.FilePath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
+ nameof(HydraulicBoundaryDatabase)),
+ "complete.sqlite");
+ HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);
+
+ var calculations = new ObservableList
+ {
+ new HydraulicBoundaryLocationCalculationsForTargetProbability()
+ };
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(calculations, assessmentSection);
+
+ var mockRepository = new MockRepository();
+ 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();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ plugin.Gui = gui;
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ const string expectedItemText = @"Alles be&rekenen";
+ const string expectedItemTooltip = @"Alle golfhoogten berekenen.";
+
+ TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuRunWaveHeightCalculationsIndex,
+ expectedItemText, expectedItemTooltip, RiskeerCommonFormsResources.CalculateAllIcon);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll(); // Expect no calls on arguments
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetWaveHeightCalculations))]
+ public void ContextMenuStrip_WaveHeightCalculationsWithIllustrationPoints_ContextMenuItemClearAllIllustrationPointsEnabledAndTooltipSet(
+ Func getHydraulicLocationCalculationFunc)
+ {
+ // Setup
+ var random = new Random(21);
+ IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations();
+ HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection);
+ calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint());
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
+ assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
+ assessmentSection);
+
+ var mockRepository = new MockRepository();
+ 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();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ 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);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll(); // Expect no calls on arguments
+ }
+
+ [Test]
+ public void ContextMenuStrip_WaveHeightCalculationsWithoutIllustrationPoints_ContextMenuItemClearAllIllustrationPointsDisabled()
+ {
+ // Setup
+ IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations();
+
+ var nodeData = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
+ assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
+ assessmentSection);
+
+ var mockRepository = new MockRepository();
+ 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();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ plugin.Gui = gui;
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ ToolStripItem contextMenuItem = contextMenu.Items[contextMenuClearIllustrationPointsIndex];
+ Assert.IsFalse(contextMenuItem.Enabled);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll(); // Expect no calls on arguments
+ }
+
+ [Test]
+ [Apartment(ApartmentState.STA)]
+ public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenLogMessagesAddedOutputSet()
+ {
+ // Given
+ var mockRepository = new MockRepository();
+ var assessmentSection = new AssessmentSectionStub
+ {
+ HydraulicBoundaryDatabase =
+ {
+ FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite")
+ }
+ };
+
+ HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);
+
+ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName");
+ assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
+ {
+ hydraulicBoundaryLocation
+ });
+
+ var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
+ assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
+ assessmentSection);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mockRepository);
+
+ var gui = mockRepository.Stub();
+ gui.Stub(g => g.MainWindow).Return(mainWindow);
+ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+ gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
+ gui.Stub(g => g.DocumentViewController).Return(mockRepository.Stub());
+ gui.Stub(g => g.ViewCommands).Return(mockRepository.Stub());
+ gui.Stub(g => g.ProjectStore).Return(mockRepository.Stub());
+
+ var waveHeightCalculator = new TestWaveHeightCalculator
+ {
+ Converged = false
+ };
+ var calculatorFactory = mockRepository.Stub();
+ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg.Is.NotNull))
+ .WhenCalled(invocation =>
+ {
+ HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
+ HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
+ (HydraRingCalculationSettings) invocation.Arguments[0]);
+ })
+ .Return(waveHeightCalculator)
+ .Repeat
+ .Times(2);
+ mockRepository.ReplayAll();
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ // Expect an activity dialog which is automatically closed
+ };
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ plugin.Gui = gui;
+ plugin.Activate();
+
+ using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl))
+ using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
+ {
+ // When
+ void Call() => contextMenuAdapter.Items[contextMenuRunWaveHeightCalculationsIndex].PerformClick();
+
+ // Then
+ TestHelper.AssertLogMessages(Call, messages =>
+ {
+ string[] msgs = messages.ToArray();
+ Assert.AreEqual(16, msgs.Length);
+
+ const string calculationTypeDisplayName = "Golfhoogte";
+ const string calculationDisplayName = "Golfhoogte berekening";
+
+ HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
+ hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/4.000", msgs, 0);
+ HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
+ hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/40.000", msgs, 8);
+ });
+
+ AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[0].HydraulicBoundaryLocationCalculations[0].Output);
+ AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[1].HydraulicBoundaryLocationCalculations[0].Output);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetWaveHeightCalculations))]
+ [Apartment(ApartmentState.STA)]
+ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndDoNotContinue_ThenInquiryAndIllustrationPointsNotCleared(
+ Func getHydraulicLocationCalculationFunc)
+ {
+ // Given
+ var random = new Random(21);
+ IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations();
+ HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection);
+ calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint());
+
+ HydraulicBoundaryLocationCalculation[] calculationsWithOutput = GetAllWaveHeightCalculationsWithOutput(assessmentSection).ToArray();
+
+ var messageBoxText = "";
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var helper = new MessageBoxTester(wnd);
+ messageBoxText = helper.Text;
+
+ helper.ClickCancel();
+ };
+
+ var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
+ assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
+ assessmentSection);
+
+ var mockRepository = new MockRepository();
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var calculationObserver = 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(calculationObserver);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ 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 'Golfhoogten' wilt wissen?";
+ Assert.AreEqual(expectedMessage, messageBoxText);
+
+ Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput));
+ Assert.IsTrue(calculation.Output.HasGeneralResult);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetWaveHeightCalculations))]
+ [Apartment(ApartmentState.STA)]
+ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinue_ThenInquiryAndIllustrationPointsCleared(
+ Func getHydraulicLocationCalculationFunc)
+ {
+ // Given
+ var random = new Random(21);
+ IAssessmentSection assessmentSection = GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations();
+ HydraulicBoundaryLocationCalculation calculation = getHydraulicLocationCalculationFunc(assessmentSection);
+ calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble(), new TestGeneralResultSubMechanismIllustrationPoint());
+
+ HydraulicBoundaryLocationCalculation[] calculationsWithOutput = GetAllWaveHeightCalculationsWithOutput(assessmentSection).ToArray();
+
+ var messageBoxText = "";
+ DialogBoxHandler = (name, wnd) =>
+ {
+ var helper = new MessageBoxTester(wnd);
+ messageBoxText = helper.Text;
+
+ helper.ClickOk();
+ };
+
+ var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
+ assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
+ assessmentSection);
+
+ var mockRepository = new MockRepository();
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var calculationObserver = mockRepository.StrictMock();
+ calculationObserver.Expect(o => o.UpdateObserver());
+
+ 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(calculationObserver);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ 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 'Golfhoogten' wilt wissen?";
+ Assert.AreEqual(expectedMessage, messageBoxText);
+
+ Assert.IsTrue(calculationsWithOutput.All(calc => calc.HasOutput));
+ Assert.IsFalse(calculation.Output.HasGeneralResult);
+ }
+ }
+ }
+
+ mockRepository.VerifyAll();
+ }
+
+ private static void AssertHydraulicBoundaryLocationCalculationOutput(IWaveHeightCalculator waveHeightCalculator,
+ HydraulicBoundaryLocationCalculationOutput actualOutput)
+ {
+ Assert.AreEqual(waveHeightCalculator.WaveHeight, actualOutput.Result, actualOutput.Result.GetAccuracy());
+ Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, actualOutput.CalculationConvergence);
+ }
+
+ private static IAssessmentSection GetConfiguredAssessmentSectionWithHydraulicBoundaryLocationCalculations()
+ {
+ var assessmentSection = new AssessmentSectionStub();
+
+ var hydraulicBoundaryLocations = new[]
+ {
+ new TestHydraulicBoundaryLocation(),
+ new TestHydraulicBoundaryLocation(),
+ new TestHydraulicBoundaryLocation()
+ };
+
+ assessmentSection.SetHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations, true);
+
+ return assessmentSection;
+ }
+
+ private static IEnumerable GetAllWaveHeightCalculationsWithOutput(IAssessmentSection assessmentSection)
+ {
+ return assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities
+ .SelectMany(wlc => wlc.HydraulicBoundaryLocationCalculations)
+ .Where(calc => calc.HasOutput);
+ }
+
+ private static IEnumerable GetWaveHeightCalculations()
+ {
+ yield return new TestCaseData(new Func(
+ section => section.WaveHeightCalculationsForUserDefinedTargetProbabilities[0].HydraulicBoundaryLocationCalculations[0]));
+ yield return new TestCaseData(new Func(
+ section => section.WaveHeightCalculationsForUserDefinedTargetProbabilities[1].HydraulicBoundaryLocationCalculations[1]));
+ }
+
+ private static TreeNodeInfo GetInfo(RiskeerPlugin plugin)
+ {
+ return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext));
+ }
+ }
+}
\ No newline at end of file