// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets 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.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Controls.DataGrid; 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 Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service.TestUtil; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.SoilProfile; using Ringtoets.Piping.Data.TestUtil; using Ringtoets.Piping.Forms; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.KernelWrapper.TestUtil; using Ringtoets.Piping.Primitives; using Ringtoets.Piping.Primitives.TestUtil; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; namespace Ringtoets.Piping.Plugin.Test.TreeNodeInfos { [TestFixture] public class PipingCalculationGroupContextTreeNodeInfoTest : NUnitFormTest { private const int contextMenuImportCalculationGroupIndexRootGroup = 2; private const int contextMenuExportCalculationGroupIndexRootGroup = 3; private const int contextMenuAddCalculationGroupIndexRootGroup = 7; private const int contextMenuAddCalculationIndexRootGroup = 8; private const int contextMenuUpdateEntryAndExitPointsAllIndexRootGroup = 10; private const int contextMenuValidateAllIndexRootGroup = 12; private const int contextMenuCalculateAllIndexRootGroup = 13; private const int contextMenuClearOutputIndexRootGroup = 15; private const int contextMenuCollapseAllIndexRootGroup = 18; private const int contextMenuExpandAllIndexRootGroup = 19; private const int contextMenuPropertiesIndexRootGroup = 21; private const int contextMenuImportCalculationGroupIndexNestedGroup = 0; private const int contextMenuExportCalculationGroupIndexNestedGroup = 1; private const int contextMenuDuplicateIndexNestedGroup = 3; private const int contextMenuAddCalculationGroupIndexNestedGroup = 5; private const int contextMenuAddCalculationIndexNestedGroup = 6; private const int contextMenuRenameCalculationGroupIndexNestedGroup = 8; private const int contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup = 9; private const int contextMenuValidateAllIndexNestedGroup = 11; private const int contextMenuCalculateAllIndexNestedGroup = 12; private const int contextMenuClearOutputIndexNestedGroup = 14; private const int contextMenuDeleteCalculationGroupIndexNestedGroup = 15; private const int contextMenuCollapseAllIndexNestedGroup = 17; private const int contextMenuExpandAllIndexNestedGroup = 18; private const int contextMenuPropertiesIndexNestedGroup = 20; private const int customOnlyContextMenuAddGenerateCalculationsIndex = 5; private MockRepository mocks; private PipingPlugin 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.IsChecked); Assert.IsNull(info.OnNodeChecked); Assert.IsNotNull(info.CanDrag); Assert.IsNotNull(info.CanDrop); Assert.IsNotNull(info.CanInsert); Assert.IsNotNull(info.OnDrop); } [Test] public void ChildNodeObjects_EmptyGroup_ReturnEmpty() { // Setup var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var groupContext = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(groupContext); // Assert CollectionAssert.IsEmpty(children); } [Test] public void ChildNodeObjects_GroupWithMixedContents_ReturnChildren() { // Setup var calculationItem = mocks.StrictMock(); var childCalculation = new PipingCalculationScenario(new GeneralPipingInput()); var childGroup = new CalculationGroup(); var group = new CalculationGroup(); group.Children.Add(calculationItem); group.Children.Add(childCalculation); group.Children.Add(childGroup); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(nodeData).ToArray(); // Assert Assert.AreEqual(group.Children.Count, children.Length); Assert.AreSame(calculationItem, children[0]); var returnedCalculationContext = (PipingCalculationScenarioContext) children[1]; Assert.AreSame(childCalculation, returnedCalculationContext.WrappedData); Assert.AreSame(group, returnedCalculationContext.Parent); Assert.AreSame(pipingFailureMechanism, returnedCalculationContext.FailureMechanism); var returnedCalculationGroupContext = (PipingCalculationGroupContext) children[2]; Assert.AreSame(childGroup, returnedCalculationGroupContext.WrappedData); Assert.AreSame(group, returnedCalculationGroupContext.Parent); Assert.AreSame(pipingFailureMechanism, returnedCalculationGroupContext.FailureMechanism); Assert.AreSame(assessmentSection, returnedCalculationGroupContext.AssessmentSection); } [Test] public void ContextMenuStrip_NestedCalculationGroupWithCalculationOutput_ReturnContextMenuWithItems() { // Setup var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) { Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var applicationFeatureCommandHandler = mocks.Stub(); var importHandler = mocks.StrictMock(); importHandler.Expect(ihm => ihm.CanImportOn(nodeData)).Return(true); var exportHandler = mocks.StrictMock(); exportHandler.Expect(ehm => ehm.CanExportFrom(nodeData)).Return(true); var updateHandler = mocks.Stub(); var viewCommandsHandler = mocks.Stub(); var treeViewControl = mocks.StrictMock(); var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, importHandler, exportHandler, updateHandler, viewCommandsHandler, nodeData, treeViewControl); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); treeViewControl.Expect(tvc => tvc.CanRemoveNodeForData(nodeData)).Return(true); treeViewControl.Expect(tvc => tvc.CanRenameNodeForData(nodeData)).Return(true); treeViewControl.Expect(tvc => tvc.CanExpandOrCollapseForData(nodeData)).Repeat.Twice().Return(false); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // Assert Assert.AreEqual(21, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuImportCalculationGroupIndexNestedGroup, "&Importeren...", "Importeer de gegevens vanuit een bestand.", CoreCommonGuiResources.ImportIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuExportCalculationGroupIndexNestedGroup, "&Exporteren...", "Exporteer de gegevens naar een bestand.", CoreCommonGuiResources.ExportIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuDuplicateIndexNestedGroup, "D&upliceren", "Dupliceer dit element.", RingtoetsCommonFormsResources.CopyHS); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexNestedGroup, "&Map toevoegen", "Voeg een nieuwe map toe aan deze map met berekeningen.", RingtoetsCommonFormsResources.AddFolderIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexNestedGroup, "Berekening &toevoegen", "Voeg een nieuwe berekening toe aan deze map met berekeningen.", RingtoetsCommonFormsResources.CalculationIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRenameCalculationGroupIndexNestedGroup, "&Hernoemen", "Wijzig de naam van dit element.", CoreCommonGuiResources.RenameIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup, "&Bijwerken intrede- en uittredepunten...", "Er zijn geen berekeningen om bij te werken.", RingtoetsCommonFormsResources.UpdateItemIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexNestedGroup, "Alles &valideren", "Valideer alle berekeningen binnen deze map met berekeningen.", RingtoetsCommonFormsResources.ValidateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexNestedGroup, "Alles be&rekenen", "Voer alle berekeningen binnen deze map met berekeningen uit.", RingtoetsCommonFormsResources.CalculateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearOutputIndexNestedGroup, "&Wis alle uitvoer...", "Wis de uitvoer van alle berekeningen binnen deze map met berekeningen.", RingtoetsCommonFormsResources.ClearIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuDeleteCalculationGroupIndexNestedGroup, "Verwij&deren...", "Verwijder dit element uit de boom.", CoreCommonGuiResources.DeleteIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCollapseAllIndexNestedGroup, "Alles i&nklappen", "Klap dit element en alle onderliggende elementen in.", CoreCommonGuiResources.CollapseAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuExpandAllIndexNestedGroup, "Alles ui&tklappen", "Klap dit element en alle onderliggende elementen uit.", CoreCommonGuiResources.ExpandAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuPropertiesIndexNestedGroup, "Ei&genschappen", "Toon de eigenschappen in het Eigenschappenpaneel.", CoreCommonGuiResources.PropertiesHS, false); CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[2], menu.Items[4], menu.Items[7], menu.Items[10], menu.Items[13], menu.Items[16], menu.Items[19] }, typeof(ToolStripSeparator)); } } [Test] public void ContextMenuStrip_WithoutParentNodeDefaultBehavior_ReturnContextMenuWithoutRenameRemove() { // Setup var group = new CalculationGroup(); group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) { Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var applicationFeatureCommandHandler = mocks.Stub(); var importHandler = mocks.StrictMock(); importHandler.Expect(ihm => ihm.CanImportOn(nodeData)).Return(true); var exportHandler = mocks.StrictMock(); exportHandler.Expect(ehm => ehm.CanExportFrom(nodeData)).Return(true); var updateHandler = mocks.Stub(); var viewCommandsHandler = mocks.StrictMock(); viewCommandsHandler.Expect(vc => vc.CanOpenViewFor(nodeData)).Return(true); using (var treeViewControl = new TreeViewControl()) { var menuBuilder = new ContextMenuBuilder(applicationFeatureCommandHandler, importHandler, exportHandler, updateHandler, viewCommandsHandler, nodeData, treeViewControl); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; // Call ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl); // Assert Assert.AreEqual(22, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuImportCalculationGroupIndexRootGroup, "&Importeren...", "Importeer de gegevens vanuit een bestand.", CoreCommonGuiResources.ImportIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuExportCalculationGroupIndexRootGroup, "&Exporteren...", "Exporteer de gegevens naar een bestand.", CoreCommonGuiResources.ExportIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexRootGroup, "&Map toevoegen", "Voeg een nieuwe map toe aan deze map met berekeningen.", RingtoetsCommonFormsResources.AddFolderIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexRootGroup, "Berekening &toevoegen", "Voeg een nieuwe berekening toe aan deze map met berekeningen.", RingtoetsCommonFormsResources.CalculationIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken intrede- en uittredepunten...", "Er zijn geen berekeningen om bij te werken.", RingtoetsCommonFormsResources.UpdateItemIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, "Alles &valideren", "Valideer alle berekeningen binnen deze map met berekeningen.", RingtoetsCommonFormsResources.ValidateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, "Alles be&rekenen", "Voer alle berekeningen binnen deze map met berekeningen uit.", RingtoetsCommonFormsResources.CalculateAllIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearOutputIndexRootGroup, "&Wis alle uitvoer...", "Wis de uitvoer van alle berekeningen binnen deze map met berekeningen.", RingtoetsCommonFormsResources.ClearIcon); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuExpandAllIndexRootGroup, "Alles ui&tklappen", "Klap dit element en alle onderliggende elementen uit.", CoreCommonGuiResources.ExpandAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCollapseAllIndexRootGroup, "Alles i&nklappen", "Klap dit element en alle onderliggende elementen in.", CoreCommonGuiResources.CollapseAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuPropertiesIndexRootGroup, "Ei&genschappen", "Toon de eigenschappen in het Eigenschappenpaneel.", CoreCommonGuiResources.PropertiesHS, false); CollectionAssert.AllItemsAreInstancesOfType(new[] { menu.Items[1], menu.Items[6], menu.Items[9], menu.Items[11], menu.Items[14], menu.Items[17], menu.Items[20] }, typeof(ToolStripSeparator)); } } [Test] public void ContextMenuStrip_WithoutParentNodeDefaultBehaviorAndWithoutAvailableSurfaceLines_ContextMenuItemGenerateCalculationsDisabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), new[] { PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel() }, pipingFailureMechanism, assessmentSection); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(menu, customOnlyContextMenuAddGenerateCalculationsIndex, "Genereer &scenario\'s...", "Er zijn geen profielschematisaties of stochastische ondergrondmodellen beschikbaar om berekeningen voor te genereren.", RingtoetsCommonFormsResources.GenerateScenariosIcon, false); } } } [Test] public void ContextMenuStrip_WithoutParentNodeDefaultBehaviorAndWithoutAvailableSoilModels_ContextMenuItemGenerateCalculationsDisabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, null, new[] { new PipingSurfaceLine(string.Empty) }, Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(menu, customOnlyContextMenuAddGenerateCalculationsIndex, "Genereer &scenario\'s...", "Er zijn geen profielschematisaties of stochastische ondergrondmodellen beschikbaar om berekeningen voor te genereren.", RingtoetsCommonFormsResources.GenerateScenariosIcon, false); } } } [Test] public void ContextMenuStrip_WithoutParentNodeDefaultBehaviorAndWithAvailableSurfaceLinesAndSoilModels_ContextMenuItemGenerateCalculationsEnabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, null, new[] { new PipingSurfaceLine(string.Empty) }, new[] { PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel() }, pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(menu, customOnlyContextMenuAddGenerateCalculationsIndex, "Genereer &scenario\'s...", "Genereer scenario\'s op basis van geselecteerde profielschematisaties.", RingtoetsCommonFormsResources.GenerateScenariosIcon); } } } [Test] public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var group = new CalculationGroup { Children = { PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput() } }; var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, pipingFailureMechanism, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup, "Alles be&rekenen", "De bijdrage van dit toetsspoor is nul.", RingtoetsCommonFormsResources.CalculateAllIcon, false); TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup, "Alles &valideren", "De bijdrage van dit toetsspoor is nul.", RingtoetsCommonFormsResources.ValidateAllIcon, false); } } } [Test] public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllAndValidateAllEnabled() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var group = new CalculationGroup { Children = { PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput() } }; var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, pipingFailureMechanism, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup, "Alles be&rekenen", "Voer alle berekeningen binnen deze map met berekeningen uit.", RingtoetsCommonFormsResources.CalculateAllIcon); TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup, "Alles &valideren", "Valideer alle berekeningen binnen deze map met berekeningen.", RingtoetsCommonFormsResources.ValidateAllIcon); } } } [Test] public void ContextMenuStrip_CalculationGroupWithoutCalculations_ContextMenuItemUpdateEntryAndExitPointsDisabledAndToolTipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var group = new CalculationGroup(); var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken intrede- en uittredepunten...", "Er zijn geen berekeningen om bij te werken.", RingtoetsCommonFormsResources.UpdateItemIcon, false); } } } [Test] public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutSurfaceLine_ContextMenuItemUpdateEntryAndExitPointsDisabledAndToolTipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var group = new CalculationGroup { Children = { new PipingCalculationScenario(new GeneralPipingInput()) } }; var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken intrede- en uittredepunten...", "Er zijn geen berekeningen om bij te werken.", RingtoetsCommonFormsResources.UpdateItemIcon, false); } } } [Test] public void ContextMenuStrip_CalculationGroupWithCalculationWithSurfaceLineAndInputInSync_ContextMenuItemUpdateEntryAndExitPointsDisabledAndToolTipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var group = new CalculationGroup { Children = { PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput() } }; var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken intrede- en uittredepunten...", "Er zijn geen berekeningen om bij te werken.", RingtoetsCommonFormsResources.UpdateItemIcon, false); } } } [Test] public void ContextMenuStrip_CalculationGroupWithCalculationWithSurfaceLineAndInputOutOfSync_ContextMenuItemUpdateEntryAndExitPointsEnabledAndToolTipSet() { // Setup using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); PipingCalculationScenario pipingCalculationScenario = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); var group = new CalculationGroup { Children = { pipingCalculationScenario } }; var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); plugin.Gui = gui; ChangeSurfaceLine(pipingCalculationScenario.InputParameters.SurfaceLine); // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateEntryAndExitPointsAllIndexRootGroup, "&Bijwerken intrede- en uittredepunten...", "Alle berekeningen met een profielschematisatie bijwerken.", RingtoetsCommonFormsResources.UpdateItemIcon); } } } [Test] public void ContextMenuStrip_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers() { // Setup using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); plugin.Gui = gui; var calculationItem = new CalculationGroup { Name = "Nieuwe map" }; group.Children.Add(calculationItem); nodeData.Attach(observer); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // Precondition Assert.AreEqual(1, group.Children.Count); // Call contextMenu.Items[contextMenuAddCalculationGroupIndexNestedGroup].PerformClick(); // Assert Assert.AreEqual(2, group.Children.Count); ICalculationBase newlyAddedItem = group.Children.Last(); Assert.IsInstanceOf(newlyAddedItem); Assert.AreEqual("Nieuwe map (1)", newlyAddedItem.Name, "An item with the same name default name already exists, therefore '(1)' needs to be appended."); } } } [Test] public void ContextMenuStrip_ClickOnAddCalculationItem_AddCalculationToCalculationGroupAndNotifyObservers() { // Setup using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); plugin.Gui = gui; var calculationItem = new PipingCalculationScenario(new GeneralPipingInput()) { Name = "Nieuwe berekening" }; group.Children.Add(calculationItem); nodeData.Attach(observer); using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // Precondition Assert.AreEqual(1, group.Children.Count); // Call contextMenu.Items[contextMenuAddCalculationIndexNestedGroup].PerformClick(); // Assert Assert.AreEqual(2, group.Children.Count); ICalculationBase newlyAddedItem = group.Children.Last(); Assert.IsInstanceOf(newlyAddedItem); Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name, "An item with the same name default name already exists, therefore '(1)' needs to be appended."); } } } [Test] public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations() { // Setup using (var treeViewControl = new TreeViewControl()) { PipingCalculationScenario validCalculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); validCalculation.Name = "A"; PipingCalculationScenario invalidCalculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithInvalidInput(); invalidCalculation.Name = "B"; var childGroup = new CalculationGroup(); childGroup.Children.Add(validCalculation); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(invalidCalculation); var pipingFailureMechanism = new TestPipingFailureMechanism(); var assessmentSection = mocks.Stub(); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // Call Action call = () => contextMenu.Items[contextMenuValidateAllIndexNestedGroup].PerformClick(); // Assert TestHelper.AssertLogMessages(call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(9, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[2]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[8]); }); } } } [Test] public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations() { // Setup using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); PipingCalculationScenario validCalculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); validCalculation.Name = "A"; PipingCalculationScenario invalidCalculation = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithInvalidInput(); invalidCalculation.Name = "B"; var childGroup = new CalculationGroup(); childGroup.Children.Add(validCalculation); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(invalidCalculation); var pipingFailureMechanism = new TestPipingFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( pipingFailureMechanism, mocks); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); mocks.ReplayAll(); plugin.Gui = gui; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; // Call contextMenu.Items[contextMenuCalculateAllIndexNestedGroup].PerformClick(); } } // Assert } [Test] [TestCase(false)] [TestCase(true)] public void ContextMenuStrip_ClickOnClearOutputItem_ClearOutputAllChildCalculationsAndNotifyCalculationObservers(bool confirm) { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation1Observer = mocks.StrictMock(); var calculation2Observer = mocks.StrictMock(); if (confirm) { calculation1Observer.Expect(o => o.UpdateObserver()); calculation2Observer.Expect(o => o.UpdateObserver()); } PipingCalculationScenario calculation1 = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); calculation1.Name = "A"; calculation1.Output = new TestPipingOutput(); calculation1.SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput(); calculation1.Attach(calculation1Observer); PipingCalculationScenario calculation2 = PipingCalculationScenarioFactory.CreatePipingCalculationScenarioWithValidInput(); calculation2.Name = "B"; calculation2.Output = new TestPipingOutput(); calculation2.SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput(); calculation2.Attach(calculation2Observer); var childGroup = new CalculationGroup(); childGroup.Children.Add(calculation1); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); var pipingFailureMechanism = new PipingFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( pipingFailureMechanism, mocks); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; string messageBoxTitle = null, messageBoxText = null; DialogBoxHandler = (name, wnd) => { var messageBox = new MessageBoxTester(wnd); messageBoxText = messageBox.Text; messageBoxTitle = messageBox.Title; if (confirm) { messageBox.ClickOk(); } else { messageBox.ClickCancel(); } }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // Call contextMenu.Items[contextMenuClearOutputIndexNestedGroup].PerformClick(); // Assert Assert.AreNotEqual(confirm, calculation1.HasOutput); Assert.AreNotEqual(confirm, calculation2.HasOutput); Assert.AreEqual("Bevestigen", messageBoxTitle); Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); } } } [Test] public void ContextMenuStrip_ClickOnGenerateCalculationsItemWithSurfaceLinesAndSoilModels_ShowSurfaceLineSelectionView() { // Setup using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var surfaceLines = new[] { new PipingSurfaceLine("surfaceLine1"), new PipingSurfaceLine("surfaceLine2") }; var nodeData = new PipingCalculationGroupContext(group, null, surfaceLines, new[] { PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel() }, pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; PipingSurfaceLineSelectionDialog selectionDialog = null; DataGridViewControl grid = null; var rowCount = 0; DialogBoxHandler = (name, wnd) => { selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; rowCount = grid.Rows.Count; new ButtonTester("CustomCancelButton", selectionDialog).Click(); }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Call contextMenu.Items[customOnlyContextMenuAddGenerateCalculationsIndex].PerformClick(); // Assert Assert.NotNull(selectionDialog); Assert.NotNull(grid); Assert.AreEqual(2, rowCount); } } } [Test] public void GivenPipingCalculationsViewGenerateScenariosButtonClicked_WhenSurfaceLineSelectedAndDialogClosed_ThenUpdateSectionResultScenarios() { // Given using (var treeViewControl = new TreeViewControl()) { var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var surfaceLine1 = new PipingSurfaceLine("Surface line 1") { ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) }; surfaceLine1.SetGeometry(new[] { new Point3D(0.0, 5.0, 0.0), new Point3D(0.0, 0.0, 1.0), new Point3D(0.0, -5.0, 0.0) }); var surfaceLine2 = new PipingSurfaceLine("Surface line 2") { ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) }; surfaceLine2.SetGeometry(new[] { new Point3D(5.0, 5.0, 0.0), new Point3D(5.0, 0.0, 1.0), new Point3D(5.0, -5.0, 0.0) }); var surfaceLines = new[] { surfaceLine1, surfaceLine2 }; pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 1", new List { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) })); pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 2", new List { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) })); var nodeData = new PipingCalculationGroupContext( pipingFailureMechanism.CalculationsGroup, null, surfaceLines, new[] { new PipingStochasticSoilModel("name") { Geometry = { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }, StochasticSoilProfiles = { new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile("A")), new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile("B")) } } }, pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; DialogBoxHandler = (name, wnd) => { var selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; grid.Rows[0].Cells[0].Value = true; new ButtonTester("DoForSelectedButton", selectionDialog).Click(); }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When contextMenu.Items[customOnlyContextMenuAddGenerateCalculationsIndex].PerformClick(); // Then PipingFailureMechanismSectionResult failureMechanismSectionResult1 = pipingFailureMechanism.SectionResults.First(); PipingFailureMechanismSectionResult failureMechanismSectionResult2 = pipingFailureMechanism.SectionResults.ElementAt(1); PipingCalculationScenario[] pipingCalculationScenarios = pipingFailureMechanism.Calculations.OfType().ToArray(); Assert.AreEqual(2, failureMechanismSectionResult1.GetCalculationScenarios(pipingCalculationScenarios).Count()); foreach (PipingCalculationScenario calculationScenario in failureMechanismSectionResult1.GetCalculationScenarios(pipingCalculationScenarios)) { Assert.IsInstanceOf(calculationScenario); } CollectionAssert.IsEmpty(failureMechanismSectionResult2.GetCalculationScenarios(pipingCalculationScenarios)); } } } [Test] public void GivenPipingCalculationsViewGenerateScenariosButtonClicked_WhenCancelButtonClickedAndDialogClosed_ThenSectionResultScenariosNotUpdated() { // Given using (var treeViewControl = new TreeViewControl()) { var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); var surfaceLine1 = new PipingSurfaceLine("Surface line 1") { ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) }; surfaceLine1.SetGeometry(new[] { new Point3D(0.0, 5.0, 0.0), new Point3D(0.0, 0.0, 1.0), new Point3D(0.0, -5.0, 0.0) }); var surfaceLine2 = new PipingSurfaceLine("Surface line 2") { ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0) }; surfaceLine2.SetGeometry(new[] { new Point3D(5.0, 5.0, 0.0), new Point3D(5.0, 0.0, 1.0), new Point3D(5.0, -5.0, 0.0) }); var surfaceLines = new[] { surfaceLine1, surfaceLine2 }; pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 1", new List { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) })); pipingFailureMechanism.AddSection(new FailureMechanismSection("Section 2", new List { new Point2D(5.0, 0.0), new Point2D(10.0, 0.0) })); var nodeData = new PipingCalculationGroupContext(group, null, surfaceLines, new[] { new PipingStochasticSoilModel("name") { Geometry = { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) } } }, pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; // Precondition foreach (PipingFailureMechanismSectionResult failureMechanismSectionResult in pipingFailureMechanism.SectionResults) { CollectionAssert.IsEmpty(failureMechanismSectionResult.GetCalculationScenarios(pipingFailureMechanism.Calculations.OfType())); } DialogBoxHandler = (name, wnd) => { var selectionDialog = (PipingSurfaceLineSelectionDialog) new FormTester(name).TheObject; var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; grid.Rows[0].Cells[0].Value = true; new ButtonTester("CustomCancelButton", selectionDialog).Click(); }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When contextMenu.Items[customOnlyContextMenuAddGenerateCalculationsIndex].PerformClick(); // Then foreach (PipingFailureMechanismSectionResult failureMechanismSectionResult in pipingFailureMechanism.SectionResults) { CollectionAssert.IsEmpty(failureMechanismSectionResult.GetCalculationScenarios(pipingFailureMechanism.Calculations.OfType())); } } } } [Test] public void OnNodeRemoved_ParentIsPipingCalculationGroupContainingGroup_RemoveGroupAndNotifyObservers() { // Setup var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); var group = new CalculationGroup(); var pipingFailureMechanism = new PipingFailureMechanism(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var nodeData = new PipingCalculationGroupContext(group, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentGroup = new CalculationGroup(); parentGroup.Children.Add(group); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); parentNodeData.Attach(observer); // Precondition Assert.IsTrue(info.CanRemove(nodeData, parentNodeData)); // Call info.OnNodeRemoved(nodeData, parentNodeData); // Assert CollectionAssert.DoesNotContain(parentGroup.Children, group); } [Test] public void OnNodeRemoved_ParentIsPipingCalculationGroupContainingGroupContainingCalculations_RemoveGroupAndCalculationsAndNotifyObservers() { // Setup var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); var group = new CalculationGroup(); TestPipingFailureMechanism pipingFailureMechanism = TestPipingFailureMechanism.GetFailureMechanismWithSurfaceLinesAndStochasticSoilModels(); PipingSurfaceLine[] surfaceLines = pipingFailureMechanism.SurfaceLines.ToArray(); var calculation = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLines[0] } }; group.Children.Add(calculation); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); CalculationGroup parentGroup = pipingFailureMechanism.CalculationsGroup; parentGroup.Children.Add(group); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); parentNodeData.Attach(observer); // Precondition Assert.IsTrue(info.CanRemove(nodeData, parentNodeData)); PipingFailureMechanismSectionResult[] sectionResults = pipingFailureMechanism.SectionResults.ToArray(); CollectionAssert.Contains(sectionResults[0].GetCalculationScenarios(pipingFailureMechanism.Calculations.OfType()), calculation); // Call info.OnNodeRemoved(nodeData, parentNodeData); // Assert CollectionAssert.DoesNotContain(parentGroup.Children, group); CollectionAssert.DoesNotContain(sectionResults[0].GetCalculationScenarios(pipingFailureMechanism.Calculations.OfType()), calculation); } [Test] public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateEntryAndExitPointsClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation1Observer = mocks.StrictMock(); var calculation1InputObserver = mocks.StrictMock(); var calculation2Observer = mocks.StrictMock(); var calculation2InputObserver = mocks.StrictMock(); calculation1InputObserver.Expect(obs => obs.UpdateObserver()); calculation2InputObserver.Expect(obs => obs.UpdateObserver()); var surfaceLine = new PipingSurfaceLine(string.Empty); surfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 } }; calculation1.Attach(calculation1Observer); calculation1.InputParameters.Attach(calculation1InputObserver); var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 } }; calculation2.Attach(calculation2Observer); calculation2.InputParameters.Attach(calculation2InputObserver); var childGroup = new CalculationGroup(); childGroup.Children.Add(calculation1); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); var pipingFailureMechanism = new PipingFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( pipingFailureMechanism, mocks); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When ChangeSurfaceLine(surfaceLine); contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); // Then Assert.IsTrue(calculation1.InputParameters.IsEntryAndExitPointInputSynchronized); Assert.IsTrue(calculation2.InputParameters.IsEntryAndExitPointInputSynchronized); } } } [Test] public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointsClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation1Observer = mocks.StrictMock(); var calculation1InputObserver = mocks.StrictMock(); var calculation2Observer = mocks.StrictMock(); var calculation2InputObserver = mocks.StrictMock(); var surfaceLine = new PipingSurfaceLine(string.Empty); surfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation1.Attach(calculation1Observer); calculation1.InputParameters.Attach(calculation1InputObserver); var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation2.Attach(calculation2Observer); calculation2.InputParameters.Attach(calculation2InputObserver); var childGroup = new CalculationGroup(); childGroup.Children.Add(calculation1); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); var pipingFailureMechanism = new PipingFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( pipingFailureMechanism, mocks); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; helper.ClickCancel(); }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When ChangeSurfaceLine(surfaceLine); contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); // Then Assert.IsTrue(calculation1.HasOutput); Assert.IsFalse(calculation1.InputParameters.IsEntryAndExitPointInputSynchronized); Assert.IsTrue(calculation2.HasOutput); Assert.IsFalse(calculation2.InputParameters.IsEntryAndExitPointInputSynchronized); string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedMessage, textBoxMessage); } } } [Test] public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateEntryAndExitPointsClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() { // Setup using (var treeViewControl = new TreeViewControl()) { var calculation1Observer = mocks.StrictMock(); var calculation1InputObserver = mocks.StrictMock(); var calculation2Observer = mocks.StrictMock(); var calculation2InputObserver = mocks.StrictMock(); calculation1Observer.Expect(obs => obs.UpdateObserver()); calculation1InputObserver.Expect(obs => obs.UpdateObserver()); calculation2Observer.Expect(obs => obs.UpdateObserver()); calculation2InputObserver.Expect(obs => obs.UpdateObserver()); var surfaceLine = new PipingSurfaceLine(string.Empty); surfaceLine.SetGeometry(new[] { new Point3D(1, 2, 3), new Point3D(4, 5, 6) }); var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation1.Attach(calculation1Observer); calculation1.InputParameters.Attach(calculation1InputObserver); var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { SurfaceLine = surfaceLine, EntryPointL = (RoundedDouble) 0, ExitPointL = (RoundedDouble) 1 }, Output = new TestPipingOutput(), SemiProbabilisticOutput = new TestPipingSemiProbabilisticOutput() }; calculation2.Attach(calculation2Observer); calculation2.InputParameters.Attach(calculation2InputObserver); var childGroup = new CalculationGroup(); childGroup.Children.Add(calculation1); var emptyChildGroup = new CalculationGroup(); var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); group.Children.Add(childGroup); group.Children.Add(emptyChildGroup); group.Children.Add(calculation2); var pipingFailureMechanism = new PipingFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStubWithoutBoundaryDatabase( pipingFailureMechanism, mocks); var nodeData = new PipingCalculationGroupContext(group, parentGroup, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var parentNodeData = new PipingCalculationGroupContext(parentGroup, null, Enumerable.Empty(), Enumerable.Empty(), pipingFailureMechanism, assessmentSection); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); var gui = mocks.Stub(); gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; helper.ClickOk(); }; using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) { // When ChangeSurfaceLine(surfaceLine); contextMenu.Items[contextMenuUpdateEntryAndExitPointsAllIndexNestedGroup].PerformClick(); // Then Assert.IsFalse(calculation1.HasOutput); Assert.IsTrue(calculation1.InputParameters.IsEntryAndExitPointInputSynchronized); Assert.IsFalse(calculation2.HasOutput); Assert.IsTrue(calculation2.InputParameters.IsEntryAndExitPointInputSynchronized); string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedMessage, textBoxMessage); } } } public override void Setup() { mocks = new MockRepository(); plugin = new PipingPlugin(); info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingCalculationGroupContext)); } public override void TearDown() { plugin.Dispose(); mocks.VerifyAll(); base.TearDown(); } private static void ChangeSurfaceLine(PipingSurfaceLine surfaceLine) { surfaceLine.SetGeometry(new[] { new Point3D(0, 0, 0), new Point3D(1, 0, 2), new Point3D(2, 0, 3), new Point3D(3, 0, 0), new Point3D(4, 0, 2), new Point3D(5, 0, 3) }); surfaceLine.SetDikeToeAtRiverAt(new Point3D(2, 0, 3)); surfaceLine.SetDikeToeAtPolderAt(new Point3D(3, 0, 0)); } } }