Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/Ringtoets.ClosingStructures.Plugin.Test.csproj
===================================================================
diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -rb9267deb13c311cb0faa0e48013147346754a5bf
--- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/Ringtoets.ClosingStructures.Plugin.Test.csproj (.../Ringtoets.ClosingStructures.Plugin.Test.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0)
+++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/Ringtoets.ClosingStructures.Plugin.Test.csproj (.../Ringtoets.ClosingStructures.Plugin.Test.csproj) (revision b9267deb13c311cb0faa0e48013147346754a5bf)
@@ -68,7 +68,7 @@
-
+
Fisheye: Tag b9267deb13c311cb0faa0e48013147346754a5bf refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresFailureMechanismContextTreeNodeInfoTest.cs
===================================================================
diff -u
--- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresFailureMechanismContextTreeNodeInfoTest.cs (revision 0)
+++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresFailureMechanismContextTreeNodeInfoTest.cs (revision b9267deb13c311cb0faa0e48013147346754a5bf)
@@ -0,0 +1,762 @@
+// Copyright (C) Stichting Deltares 2016. 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.IO;
+using System.Linq;
+using System.Windows.Forms;
+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 Ringtoets.ClosingStructures.Data;
+using Ringtoets.ClosingStructures.Data.TestUtil;
+using Ringtoets.ClosingStructures.Forms.PresentationObjects;
+using Ringtoets.Common.Data;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Contribution;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.Structures;
+using Ringtoets.Common.Forms.PresentationObjects;
+using Ringtoets.HydraRing.Calculation.TestUtil.Calculator;
+using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
+
+namespace Ringtoets.ClosingStructures.Plugin.Test.TreeNodeInfos
+{
+ [TestFixture]
+ public class ClosingStructuresFailureMechanismContextTreeNodeInfoTest : NUnitFormTest
+ {
+ private const int contextMenuRelevancyIndexWhenRelevant = 2;
+ private const int contextMenuRelevancyIndexWhenNotRelevant = 0;
+
+ private const int contextMenuValidateAllIndex = 4;
+ private const int contextMenuCalculateAllIndex = 5;
+ private const int contextMenuClearAllIndex = 7;
+
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter");
+
+ private MockRepository mocksRepository;
+ private ClosingStructuresPlugin plugin;
+ private TreeNodeInfo info;
+
+ [SetUp]
+ public void SetUp()
+ {
+ mocksRepository = new MockRepository();
+ plugin = new ClosingStructuresPlugin();
+ info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ClosingStructuresFailureMechanismContext));
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ plugin.Dispose();
+
+ mocksRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Initialized_Always_ExpectedPropertiesSet()
+ {
+ // Setup
+ mocksRepository.ReplayAll();
+
+ // Assert
+ Assert.AreEqual(typeof(ClosingStructuresFailureMechanismContext), info.TagType);
+ Assert.IsNotNull(info.Text);
+ Assert.IsNotNull(info.ForeColor);
+ Assert.IsNotNull(info.Image);
+ Assert.IsNotNull(info.ChildNodeObjects);
+ Assert.IsNotNull(info.ContextMenuStrip);
+ Assert.IsNull(info.EnsureVisibleOnCreate);
+ Assert.IsNull(info.CanRename);
+ Assert.IsNull(info.OnNodeRenamed);
+ Assert.IsNull(info.CanRemove);
+ Assert.IsNull(info.OnNodeRemoved);
+ Assert.IsNull(info.CanCheck);
+ Assert.IsNull(info.IsChecked);
+ Assert.IsNull(info.OnNodeChecked);
+ Assert.IsNull(info.CanDrag);
+ Assert.IsNull(info.CanDrop);
+ Assert.IsNull(info.CanInsert);
+ Assert.IsNull(info.OnDrop);
+ }
+
+ [Test]
+ public void ChildNodeObjects_FailureMechanismIsRelevant_ReturnChildDataNodes()
+ {
+ // Setup
+ var assessmentSectionStub = mocksRepository.Stub();
+ mocksRepository.ReplayAll();
+
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub);
+
+ // Call
+ var children = info.ChildNodeObjects(failureMechanismContext).ToArray();
+
+ // Assert
+ Assert.AreEqual(3, children.Length);
+
+ var inputsFolder = (CategoryTreeFolder) children[0];
+ Assert.AreEqual("Invoer", inputsFolder.Name);
+ Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category);
+
+ Assert.AreEqual(4, inputsFolder.Contents.Count);
+ var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputsFolder.Contents[0];
+ Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData);
+ Assert.AreSame(assessmentSectionStub, failureMechanismSectionsContext.ParentAssessmentSection);
+
+ var profilesContext = (ForeshoreProfilesContext) inputsFolder.Contents[1];
+ Assert.AreSame(failureMechanism.ForeshoreProfiles, profilesContext.WrappedData);
+ Assert.AreSame(failureMechanism, profilesContext.ParentFailureMechanism);
+ Assert.AreSame(assessmentSectionStub, profilesContext.ParentAssessmentSection);
+
+ var closingStructuresContext = (ClosingStructuresContext) inputsFolder.Contents[2];
+ Assert.AreSame(failureMechanism.ClosingStructures, closingStructuresContext.WrappedData);
+ Assert.AreSame(failureMechanism, closingStructuresContext.FailureMechanism);
+ Assert.AreSame(assessmentSectionStub, closingStructuresContext.AssessmentSection);
+
+ var inputComment = (Comment) inputsFolder.Contents[3];
+ Assert.AreSame(failureMechanism.InputComments, inputComment);
+
+ var calculationsFolder = (ClosingStructuresCalculationGroupContext) children[1];
+ Assert.AreEqual("Berekeningen", calculationsFolder.WrappedData.Name);
+ Assert.AreEqual(failureMechanism.CalculationsGroup, calculationsFolder.WrappedData);
+ Assert.AreEqual(failureMechanism, calculationsFolder.FailureMechanism);
+
+ var outputsFolder = (CategoryTreeFolder) children[2];
+ Assert.AreEqual("Oordeel", outputsFolder.Name);
+ Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category);
+
+ Assert.AreEqual(3, outputsFolder.Contents.Count);
+ var scenariosContext = (ClosingStructuresScenariosContext) outputsFolder.Contents[0];
+ Assert.AreSame(failureMechanism.CalculationsGroup, scenariosContext.WrappedData);
+ Assert.AreSame(failureMechanism, scenariosContext.ParentFailureMechanism);
+
+ var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputsFolder.Contents[1];
+ Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism);
+ Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData);
+
+ var outputComment = (Comment) outputsFolder.Contents[2];
+ Assert.AreSame(failureMechanism.OutputComments, outputComment);
+ }
+
+ [Test]
+ public void ChildNodeObjects_FailureMechanismIsNotRelevant_ReturnOnlyFailureMechanismNotRelevantComments()
+ {
+ // Setup
+ var assessmentSectionStub = mocksRepository.Stub();
+ mocksRepository.ReplayAll();
+
+ var failureMechanism = new ClosingStructuresFailureMechanism
+ {
+ IsRelevant = false
+ };
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub);
+
+ // Call
+ var children = info.ChildNodeObjects(failureMechanismContext).ToArray();
+
+ // Assert
+ Assert.AreEqual(1, children.Length);
+ var comment = (Comment) children[0];
+ Assert.AreSame(failureMechanism.NotRelevantComments, comment);
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsRelevant_CallsContextMenuBuilderMethods()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ var assessmentSectionMock = mocksRepository.Stub();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var guiMock = mocksRepository.StrictMock();
+ var menuBuilderMock = mocksRepository.StrictMock();
+
+ using (mocksRepository.Ordered())
+ {
+ menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
+ }
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilderMock);
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ info.ContextMenuStrip(failureMechanismContext, null, treeViewControl);
+ }
+
+ // Assert
+ // Assert is done in TearDown
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsNotRelevant_CallsContextMenuBuilderMethods()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism
+ {
+ IsRelevant = false
+ };
+ var assessmentSectionMock = mocksRepository.Stub();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var guiMock = mocksRepository.StrictMock();
+ var menuBuilderMock = mocksRepository.StrictMock();
+
+ using (mocksRepository.Ordered())
+ {
+ menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock);
+ menuBuilderMock.Expect(mb => mb.Build()).Return(null);
+ }
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilderMock);
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ info.ContextMenuStrip(failureMechanismContext, null, treeViewControl);
+ }
+
+ // Assert
+ // Assert is done in TearDown
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsRelevant_AddCustomItems()
+ {
+ // Setup
+ using (var treeView = new TreeViewControl())
+ {
+ var assessmentSectionMock = mocksRepository.Stub();
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var guiMock = mocksRepository.StrictMock();
+
+ guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeView)).Return(menuBuilder);
+ guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+
+ mocksRepository.ReplayAll();
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView))
+ {
+ // Assert
+ Assert.AreEqual(13, menu.Items.Count);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant,
+ "I&s relevant",
+ "Geeft aan of dit toetsspoor relevant is of niet.",
+ RingtoetsCommonFormsResources.Checkbox_ticked);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex,
+ "Alles &valideren",
+ "Er zijn geen berekeningen om te valideren.",
+ RingtoetsCommonFormsResources.ValidateAllIcon,
+ false);
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex,
+ "Alles be&rekenen",
+ "Er zijn geen berekeningen om uit te voeren.",
+ RingtoetsCommonFormsResources.CalculateAllIcon,
+ false);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearAllIndex,
+ "&Wis alle uitvoer...",
+ "Er zijn geen berekeningen met uitvoer om te wissen.",
+ RingtoetsCommonFormsResources.ClearIcon,
+ false);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsNotRelevant_AddCustomItems()
+ {
+ // Setup
+ using (var treeView = new TreeViewControl())
+ {
+ var assessmentSectionMock = mocksRepository.Stub();
+ var failureMechanism = new ClosingStructuresFailureMechanism
+ {
+ IsRelevant = false
+ };
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var guiMock = mocksRepository.StrictMock();
+
+ guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeView)).Return(menuBuilder);
+ guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+
+ mocksRepository.ReplayAll();
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView))
+ {
+ // Assert
+ Assert.AreEqual(4, menu.Items.Count);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenNotRelevant,
+ "I&s relevant",
+ "Geeft aan of dit toetsspoor relevant is of niet.",
+ RingtoetsCommonFormsResources.Checkbox_empty);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsRelevantAndClickOnIsRelevantItem_MakeFailureMechanismNotRelevantAndRemovesAllViewsForItem()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ var assessmentSectionStub = mocksRepository.Stub();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub);
+ var viewCommandsMock = mocksRepository.StrictMock();
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var guiMock = mocksRepository.StrictMock();
+
+ viewCommandsMock.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext));
+ guiMock.Stub(g => g.ViewCommands).Return(viewCommandsMock);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+ plugin.Gui = guiMock;
+
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl))
+ {
+ // Call
+ contextMenu.Items[contextMenuRelevancyIndexWhenRelevant].PerformClick();
+
+ // Assert
+ Assert.IsFalse(failureMechanism.IsRelevant);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismIsNotRelevantAndClickOnIsRelevantItem_MakeFailureMechanismRelevantAndRemovesAllViewsForItem()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism
+ {
+ IsRelevant = false
+ };
+ var assessmentSectionStub = mocksRepository.Stub();
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub);
+ var viewCommandsMock = mocksRepository.StrictMock();
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var guiMock = mocksRepository.StrictMock();
+
+ viewCommandsMock.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext));
+ guiMock.Stub(g => g.ViewCommands).Return(viewCommandsMock);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+ plugin.Gui = guiMock;
+
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl))
+ {
+ // Call
+ contextMenu.Items[contextMenuRelevancyIndexWhenNotRelevant].PerformClick();
+
+ // Assert
+ Assert.IsTrue(failureMechanism.IsRelevant);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet()
+ {
+ // Setup
+ var guiMock = mocksRepository.StrictMock();
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+ var assessmentSectionMock = mocksRepository.StrictMock();
+
+ var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex,
+ "Alles be&rekenen",
+ "Er is geen vakindeling geïmporteerd.",
+ RingtoetsCommonFormsResources.CalculateAllIcon,
+ false);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex,
+ "Alles &valideren",
+ "Er is geen vakindeling geïmporteerd.",
+ RingtoetsCommonFormsResources.ValidateAllIcon,
+ false);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet()
+ {
+ // Setup
+ var guiMock = mocksRepository.StrictMock();
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ failureMechanism.AddSection(new FailureMechanismSection("test", new[]
+ {
+ new Point2D(0, 0)
+ }));
+ failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+
+ var assessmentSectionMock = mocksRepository.Stub();
+
+ var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex,
+ "Alles be&rekenen",
+ "Er is geen hydraulische randvoorwaardendatabase geïmporteerd.",
+ RingtoetsCommonFormsResources.CalculateAllIcon,
+ false);
+
+ TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndex,
+ "Alles &valideren",
+ "Er is geen hydraulische randvoorwaardendatabase geïmporteerd.",
+ RingtoetsCommonFormsResources.ValidateAllIcon,
+ false);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllAndValidateAllDisabledAndTooltipSet()
+ {
+ // Setup
+ var guiMock = mocksRepository.StrictMock();
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ failureMechanism.AddSection(new FailureMechanismSection("test", new[]
+ {
+ new Point2D(0, 0)
+ }));
+ failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+
+ var assessmentSectionMock = mocksRepository.Stub();
+ assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+
+ var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ ToolStripItem calculateAllContextMenuItem = contextMenu.Items[contextMenuCalculateAllIndex];
+
+ Assert.AreEqual("Alles be&rekenen", calculateAllContextMenuItem.Text);
+ StringAssert.Contains(string.Format("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. {0}", ""), calculateAllContextMenuItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateAllIcon, calculateAllContextMenuItem.Image);
+ Assert.IsFalse(calculateAllContextMenuItem.Enabled);
+
+ ToolStripItem validateAllContextMenuItem = contextMenu.Items[contextMenuValidateAllIndex];
+
+ Assert.AreEqual("Alles &valideren", validateAllContextMenuItem.Text);
+ StringAssert.Contains(string.Format("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. {0}", ""), validateAllContextMenuItem.ToolTipText);
+ TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateAllIcon, validateAllContextMenuItem.Image);
+ Assert.IsFalse(validateAllContextMenuItem.Enabled);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicDatabaseSet_ContextMenuItemCalculateAllAndValidateAllEnabled()
+ {
+ // Setup
+ var guiMock = mocksRepository.StrictMock();
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ failureMechanism.AddSection(new FailureMechanismSection("test", new[]
+ {
+ new Point2D(0, 0)
+ }));
+ failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
+
+ string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
+
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
+ {
+ FilePath = validFilePath,
+ Version = "1.0"
+ };
+
+ var assessmentSectionMock = mocksRepository.Stub();
+ assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase;
+
+ var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ // Call
+ using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
+ {
+ // Assert
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex,
+ "Alles be&rekenen",
+ "Voer alle berekeningen binnen dit toetsspoor uit.",
+ RingtoetsCommonFormsResources.CalculateAllIcon);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex,
+ "Alles &valideren",
+ "Valideer alle berekeningen binnen dit toetsspoor.",
+ RingtoetsCommonFormsResources.ValidateAllIcon);
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations()
+ {
+ // Setup
+ var guiMock = mocksRepository.StrictMock();
+ var mainWindowStub = mocksRepository.Stub();
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var section = new FailureMechanismSection("A", new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(2, 2)
+ });
+ failureMechanism.AddSection(section);
+
+ failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation
+ {
+ Name = "A",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2)
+ }
+ });
+ failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation
+ {
+ Name = "B",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2)
+ }
+ });
+
+ string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
+
+ var hydraulicBoundaryDatabaseStub = mocksRepository.Stub();
+ hydraulicBoundaryDatabaseStub.FilePath = validFilePath;
+
+ var assessmentSectionStub = mocksRepository.Stub();
+ assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabaseStub;
+ assessmentSectionStub.Stub(a => a.Id).Return(string.Empty);
+ assessmentSectionStub.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution(Enumerable.Empty(), 1, 1));
+
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionStub);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder);
+ guiMock.Expect(g => g.MainWindow).Return(mainWindowStub);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ DialogBoxHandler = (name, wnd) =>
+ {
+ // Expect an activity dialog which is automatically closed
+ };
+
+ using (var contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl))
+ using (new HydraRingCalculatorFactoryConfig())
+ {
+ // Call
+ TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndex].PerformClick(), messages =>
+ {
+ var messageList = messages.ToList();
+
+ // Assert
+ Assert.AreEqual(12, messageList.Count);
+ StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]);
+ StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]);
+ StringAssert.StartsWith("Berekening van 'A' gestart om: ", messageList[2]);
+ StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[3]);
+ StringAssert.StartsWith("Berekening van 'A' beëindigd om: ", messageList[4]);
+ StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[5]);
+ StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[6]);
+ StringAssert.StartsWith("Berekening van 'B' gestart om: ", messageList[7]);
+ StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[8]);
+ StringAssert.StartsWith("Berekening van 'B' beëindigd om: ", messageList[9]);
+ Assert.AreEqual("Uitvoeren van 'A' is gelukt.", messageList[10]);
+ Assert.AreEqual("Uitvoeren van 'B' is gelukt.", messageList[11]);
+ });
+ }
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+ var section = new FailureMechanismSection("A", new[]
+ {
+ new Point2D(0, 0)
+ });
+ failureMechanism.AddSection(section);
+ failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation
+ {
+ Name = "A",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2)
+ }
+ });
+ failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation
+ {
+ Name = "B",
+ InputParameters =
+ {
+ HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2)
+ }
+ });
+
+ string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
+
+ var hydraulicBoundaryDatabaseStub = mocksRepository.Stub();
+ hydraulicBoundaryDatabaseStub.FilePath = validFilePath;
+
+ var assessmentSectionMock = mocksRepository.Stub();
+ assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabaseStub;
+
+ var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock);
+
+ using (var treeViewControl = new TreeViewControl())
+ {
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+ var guiMock = mocksRepository.Stub();
+ guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder);
+
+ mocksRepository.ReplayAll();
+
+ plugin.Gui = guiMock;
+
+ using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl))
+ {
+ // Call
+ Action call = () => contextMenu.Items[contextMenuValidateAllIndex].PerformClick();
+
+ // Assert
+ TestHelper.AssertLogMessages(call, messages =>
+ {
+ var messageList = messages.ToArray();
+
+ Assert.AreEqual(4, messageList.Length);
+ StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]);
+ StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]);
+ StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[2]);
+ StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[3]);
+ });
+ }
+ }
+ }
+ }
+}
\ No newline at end of file