Fisheye: Tag 30275a39a1a2a5d53147bb7079f320046f0c19eb refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationScenarioContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationScenarioContextTreeNodeInfoTest.cs (revision 30275a39a1a2a5d53147bb7079f320046f0c19eb) @@ -0,0 +1,1407 @@ +// Copyright (C) Stichting Deltares 2019. 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.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.Commands; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Common.Service.TestUtil; +using Riskeer.GrassCoverErosionInwards.Data; +using Riskeer.GrassCoverErosionInwards.Data.TestUtil; +using Riskeer.GrassCoverErosionInwards.Forms.PresentationObjects; +using Riskeer.HydraRing.Calculation.Calculator.Factory; +using Riskeer.HydraRing.Calculation.Data.Input; +using Riskeer.HydraRing.Calculation.TestUtil.Calculator; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.GrassCoverErosionInwards.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationScenarioContextTreeNodeInfoTest : NUnitFormTest + { + private const int contextMenuDuplicateIndex = 2; + private const int contextMenuUpdateDikeProfileIndex = 5; + private const int contextMenuValidateIndex = 7; + private const int contextMenuCalculateIndex = 8; + private const int contextMenuClearIndex = 10; + private const int contextMenuClearIllustrationPointsIndex = 11; + + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, nameof(HydraulicBoundaryDatabase)); + + private MockRepository mocks; + private GrassCoverErosionInwardsPlugin plugin; + private TreeNodeInfo info; + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + mocks.ReplayAll(); + + // Assert + Assert.IsNotNull(info.Text); + Assert.IsNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNotNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ExpandOnCreate); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNotNull(info.CanRename); + Assert.IsNotNull(info.OnNodeRenamed); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CheckedState); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Image_Always_ReturnsCalculationIcon() + { + // Setup + mocks.ReplayAll(); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ProbabilisticCalculationIcon, image); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ChildNodeObjects_Always_ReturnsCollectionWithOutputObjects(bool hasOutput) + { + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = hasOutput + ? new TestGrassCoverErosionInwardsOutput() + : null + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var calculationContext = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(calculationContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + + var comment = children[0] as Comment; + Assert.AreSame(calculationContext.WrappedData.Comments, comment); + + var grassCoverErosionInwardsInputContext = children[1] as GrassCoverErosionInwardsInputContext; + Assert.IsNotNull(grassCoverErosionInwardsInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, grassCoverErosionInwardsInputContext.WrappedData); + + var grassCoverErosionInwardsOutputContext = children[2] as GrassCoverErosionInwardsOutputContext; + Assert.IsNotNull(grassCoverErosionInwardsOutputContext); + Assert.AreSame(calculationContext.WrappedData, grassCoverErosionInwardsOutputContext.WrappedData); + Assert.AreSame(calculationContext.FailureMechanism, grassCoverErosionInwardsOutputContext.FailureMechanism); + Assert.AreSame(calculationContext.AssessmentSection, grassCoverErosionInwardsOutputContext.AssessmentSection); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + var menuBuilder = mocks.StrictMock(); + using (mocks.Ordered()) + { + menuBuilder.Expect(mb => mb.AddExportItem()).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.AddRenameItem()).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.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.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddDeleteItem()).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.AddSeparator()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); + menuBuilder.Expect(mb => mb.Build()).Return(null); + } + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(nodeData, null, treeViewControl); + } + + // Assert + // Assert expectancies called in TearDown() + } + + [Test] + public void ContextMenuStrip_Always_AddCustomItems() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + Assert.AreEqual(18, menu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuDuplicateIndex, + "D&upliceren", + "Dupliceer dit element.", + RiskeerCommonFormsResources.CopyHS); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel...", + "Er moet een dijkprofiel geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, + "&Valideren", + "Valideer de invoer voor deze berekening.", + RiskeerCommonFormsResources.ValidateIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, + "Be&rekenen", + "Voer deze berekening uit.", + RiskeerCommonFormsResources.CalculateIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, + "&Wis uitvoer...", + "Deze berekening heeft geen uitvoer om te wissen.", + RiskeerCommonFormsResources.ClearIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIllustrationPointsIndex, + "Wis illustratiepunten...", + "Deze berekening heeft geen illustratiepunten om te wissen.", + RiskeerCommonFormsResources.ClearIllustrationPointsIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithoutDikeProfile_ContextMenuItemUpdateDikeProfileDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel...", + "Er moet een dijkprofiel geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithDikeProfileAndInputInSync_ContextMenuItemUpdateDikeProfileDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + DikeProfile = DikeProfileTestFactory.CreateDikeProfile() + } + }; + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel...", + "Er zijn geen wijzigingen om bij te werken.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithDikeProfileAndInputOutOfSync_ContextMenuItemUpdateDikeProfileEnabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeDikeProfile(dikeProfile); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateDikeProfileIndex, + "&Bijwerken dijkprofiel...", + "Berekening bijwerken met het dijkprofiel.", + RiskeerCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateDikeProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + DikeProfile = dikeProfile + } + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeDikeProfile(dikeProfile); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.InputParameters.IsDikeProfileInputSynchronized); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeDikeProfile(dikeProfile); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + Assert.IsFalse(calculation.InputParameters.IsDikeProfileInputSynchronized); + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateDikeProfileClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + DikeProfile = dikeProfile + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + var inputObserver = mocks.StrictMock(); + inputObserver.Expect(obs => obs.UpdateObserver()); + calculation.InputParameters.Attach(inputObserver); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(obs => obs.UpdateObserver()); + calculation.Attach(calculationObserver); + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeDikeProfile(dikeProfile); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateDikeProfileIndex].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsDikeProfileInputSynchronized); + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + "Be&rekenen", + "Er is geen hydraulische belastingendatabase geïmporteerd.", + RiskeerCommonFormsResources.CalculateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateIndex]; + + Assert.AreEqual("Be&rekenen", contextMenuItem.Text); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + "Be&rekenen", + "Voer deze berekening uit.", + RiskeerCommonFormsResources.CalculateIcon); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + "&Valideren", + "Er is geen hydraulische belastingendatabase geïmporteerd.", + RiskeerCommonFormsResources.ValidateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateIndex]; + + Assert.AreEqual("&Valideren", contextMenuItem.Text); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ValidateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + "&Valideren", + "Valideer de invoer voor deze berekening.", + RiskeerCommonFormsResources.ValidateIcon); + } + } + } + + [Test] + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + { + // Given + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random", + Locations = + { + hydraulicBoundaryLocation + } + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.Id).Return(string.Empty); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution()); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = DikeProfileTestFactory.CreateDikeProfile() + } + }; + + var calculationContext = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.DynamicMock()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(Arg.Is.NotNull)) + .WhenCalled(invocation => + { + HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( + HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase), + (HydraRingCalculationSettings) invocation.Arguments[0]); + }) + .Return(new TestOvertoppingCalculator()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + calculation.Attach(observer); + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // When + Action action = () => contextMenuStrip.Items[contextMenuCalculateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(7, msgs.Length); + Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gestart.", msgs[0]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[5]); + Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gelukt.", msgs[6]); + }); + + Assert.IsNotNull(calculation.Output); + } + } + } + + [Test] + public void GivenCalculation_WhenValidatingFromContextMenu_ThenLogMessagesAdded() + { + // Given + var observer = mocks.StrictMock(); + + var failureMechanism = new TestGrassCoverErosionInwardsFailureMechanism(); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random", + Locations = + { + hydraulicBoundaryLocation + } + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + DikeProfile = DikeProfileTestFactory.CreateDikeProfile() + } + }; + + var calculationContext = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + calculation.Attach(observer); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) + { + // When + Action action = () => contextMenuStrip.Items[contextMenuValidateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + string[] msgs = messages.ToArray(); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); + }); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearIndex]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearIndex]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsTrue(calculation.HasOutput); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndContinued_ThenInquiryAndOutputViewsClosedAndCalculationsOutputCleared() + { + // Given + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + calculation.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculation.Output)); + + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsFalse(calculation.HasOutput); + } + } + } + + [Test] + [TestCaseSource(nameof(GetCalculationConfigurationsWithIllustrationPoints))] + public void ContextMenuStrip_CalculationWithIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled( + GrassCoverErosionInwardsCalculationScenario calculation) + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Call + ToolStripItem contextMenuItem = menu.Items[contextMenuClearIllustrationPointsIndex]; + + // Assert + Assert.IsTrue(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithOutputWithoutIllustrationPoints_ContextMenuItemClearIllustrationPointsDisabled() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Call + ToolStripItem contextMenuItem = menu.Items[contextMenuClearIllustrationPointsIndex]; + + // Assert + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationWithIllustrationPoints_WhenClearIllustrationPointsClickedAndAborted_ThenInquiryAndIllustrationPointsNotCleared() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput(new TestGeneralResultFaultTreeIllustrationPoint()) + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de illustratiepunten van deze berekening wilt wissen?", messageBoxText); + + GrassCoverErosionInwardsOutput output = calculation.Output; + Assert.IsTrue(output.OvertoppingOutput.HasGeneralResult); + Assert.IsTrue(output.DikeHeightOutput.HasGeneralResult); + Assert.IsTrue(output.OvertoppingRateOutput.HasGeneralResult); + } + } + } + + [Test] + public void GivenCalculationWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinued_ThenInquiryAndIllustrationPointsCleared() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput(new TestGeneralResultFaultTreeIllustrationPoint()) + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + calculation.Attach(calculationObserver); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de illustratiepunten van deze berekening wilt wissen?", messageBoxText); + + GrassCoverErosionInwardsOutput output = calculation.Output; + Assert.IsFalse(output.OvertoppingOutput.HasGeneralResult); + Assert.IsFalse(output.DikeHeightOutput.HasGeneralResult); + Assert.IsFalse(output.OvertoppingRateOutput.HasGeneralResult); + } + } + } + + [Test] + public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() + { + // Setup + var group = new CalculationGroup(); + var elementToBeRemoved = new GrassCoverErosionInwardsCalculationScenario(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + var calculationContext = new GrassCoverErosionInwardsCalculationScenarioContext(elementToBeRemoved, + group, + failureMechanism, + assessmentSection); + var groupContext = new GrassCoverErosionInwardsCalculationGroupContext(group, + null, + failureMechanism, + assessmentSection); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + group.Children.Add(elementToBeRemoved); + group.Children.Add(new GrassCoverErosionInwardsCalculationScenario()); + group.Attach(observer); + + // Precondition + Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); + Assert.AreEqual(2, group.Children.Count); + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.AreEqual(1, group.Children.Count); + CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); + } + + public override void Setup() + { + mocks = new MockRepository(); + plugin = new GrassCoverErosionInwardsPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationScenarioContext)); + } + + public override void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + + base.TearDown(); + } + + private static void ChangeDikeProfile(DikeProfile dikeProfile) + { + dikeProfile.CopyProperties(new DikeProfile(dikeProfile.WorldReferencePoint, + dikeProfile.DikeGeometry, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = dikeProfile.Id, + DikeHeight = 10, + Orientation = 10 + })); + } + + private static IEnumerable GetCalculationConfigurationsWithIllustrationPoints() + { + var random = new Random(21); + var calculationWithOverToppingOutputWithIllustrationPoints = new GrassCoverErosionInwardsCalculationScenario + { + Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(new TestGeneralResultFaultTreeIllustrationPoint()), + null, + null) + }; + + var calculationWithDikeHeightRateWithIllustrationPoints = new GrassCoverErosionInwardsCalculationScenario + { + Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(random.NextDouble()), + new TestDikeHeightOutput(new TestGeneralResultFaultTreeIllustrationPoint()), + null) + }; + + var calculationWithOvertoppingRateWithIllustrationPoints = new GrassCoverErosionInwardsCalculationScenario + { + Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(random.NextDouble()), + null, + new TestOvertoppingRateOutput(new TestGeneralResultFaultTreeIllustrationPoint())) + }; + + yield return new TestCaseData(calculationWithOverToppingOutputWithIllustrationPoints); + yield return new TestCaseData(calculationWithDikeHeightRateWithIllustrationPoints); + yield return new TestCaseData(calculationWithOvertoppingRateWithIllustrationPoints); + } + } +} \ No newline at end of file