Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs
===================================================================
diff -u -r0559c17efc9173756acbac70af3d2cfde37e2f98 -re7b2da23c1741fe8241c31fa592231a9724ea60a
--- Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision 0559c17efc9173756acbac70af3d2cfde37e2f98)
+++ Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision e7b2da23c1741fe8241c31fa592231a9724ea60a)
@@ -1818,12 +1818,6 @@
private ContextMenuStrip AssessmentSectionStateRootContextMenuStrip(AssessmentSectionStateRootContext nodeData, object parentData, TreeViewControl treeViewControl)
{
- var calculateAllItem = new StrictContextMenuItem(
- RiskeerCommonFormsResources.Calculate_All,
- Resources.AssessmentSection_Calculate_All_ToolTip,
- RiskeerCommonFormsResources.CalculateAllIcon,
- (sender, args) => { ActivityProgressDialogRunner.Run(Gui.MainWindow, AssessmentSectionCalculationActivityFactory.CreateActivities(nodeData.WrappedData)); });
-
var importItem = new StrictContextMenuItem(
CoreGuiResources.Import,
CoreGuiResources.Import_ToolTip,
Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/AssessmentSectionStateRootContextTreeNodeInfoTest.cs
===================================================================
diff -u
--- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/AssessmentSectionStateRootContextTreeNodeInfoTest.cs (revision 0)
+++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/AssessmentSectionStateRootContextTreeNodeInfoTest.cs (revision e7b2da23c1741fe8241c31fa592231a9724ea60a)
@@ -0,0 +1,357 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using Core.Common.Base;
+using Core.Common.Controls.TreeView;
+using Core.Common.TestUtil;
+using Core.Gui;
+using Core.Gui.ContextMenu;
+using Core.Gui.TestUtil.ContextMenu;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Riskeer.Common.Data;
+using Riskeer.Common.Data.AssessmentSection;
+using Riskeer.Common.Forms.PresentationObjects;
+using Riskeer.Integration.Data;
+using Riskeer.Integration.Forms.PresentationObjects;
+using CoreGuiResources = Core.Gui.Properties.Resources;
+using RiskeerIntegrationFormsResources = Riskeer.Integration.Forms.Properties.Resources;
+using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources;
+
+namespace Riskeer.Integration.Plugin.Test.TreeNodeInfos
+{
+ [TestFixture]
+ public class AssessmentSectionStateRootContextTreeNodeInfoTest
+ {
+ private const int contextMenuImportAssessmentSectionIndex = 2;
+ private MockRepository mocks;
+
+ [SetUp]
+ public void SetUp()
+ {
+ mocks = new MockRepository();
+ }
+
+ [Test]
+ public void Initialized_Always_ExpectedPropertiesSet()
+ {
+ // Setup
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Assert
+ Assert.IsNotNull(info.Text);
+ Assert.IsNull(info.ForeColor);
+ Assert.IsNotNull(info.Image);
+ Assert.IsNotNull(info.ContextMenuStrip);
+ Assert.IsNotNull(info.EnsureVisibleOnCreate);
+ Assert.IsNotNull(info.ExpandOnCreate);
+ Assert.IsNotNull(info.ChildNodeObjects);
+ Assert.IsNotNull(info.CanRename);
+ Assert.IsNotNull(info.OnNodeRenamed);
+ Assert.IsNotNull(info.CanRemove);
+ Assert.IsNull(info.OnNodeRemoved);
+ Assert.IsNull(info.CanCheck);
+ Assert.IsNull(info.CheckedState);
+ Assert.IsNull(info.OnNodeChecked);
+ Assert.IsNull(info.CanDrag);
+ Assert.IsNull(info.CanDrop);
+ Assert.IsNull(info.CanInsert);
+ Assert.IsNull(info.OnDrop);
+ }
+ }
+
+ [Test]
+ public void Text_Always_ReturnsName()
+ {
+ // Setup
+ const string testName = "ttt";
+
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
+ {
+ Name = testName
+ };
+
+ var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ string text = info.Text(assessmentSectionContext);
+
+ // Assert
+ Assert.AreEqual(testName, text);
+ }
+ }
+
+ [Test]
+ public void Image_Always_ReturnsSetImage()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ Image image = info.Image(assessmentSectionContext);
+
+ // Assert
+ TestHelper.AssertImagesAreEqual(RiskeerIntegrationFormsResources.AssessmentSectionFolderIcon, image);
+ }
+ }
+
+ [Test]
+ public void EnsureVisibleOnCreate_Always_ReturnsTrue()
+ {
+ // Setup
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ bool result = info.EnsureVisibleOnCreate(null, null);
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ExpandOnCreate_Always_ReturnsTrue()
+ {
+ // Setup
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ bool result = info.ExpandOnCreate(null);
+
+ // Assert
+ Assert.IsTrue(result);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ChildNodeObjects_Always_ReturnsChildrenOfData()
+ {
+ // Setup
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ // Call
+ object[] objects = info.ChildNodeObjects(assessmentSectionContext).ToArray();
+
+ // Assert
+ Assert.AreEqual(6, objects.Length);
+
+ var referenceLineContext = (ReferenceLineContext) objects[0];
+ Assert.AreSame(assessmentSection.ReferenceLine, referenceLineContext.WrappedData);
+ Assert.AreSame(assessmentSection, referenceLineContext.AssessmentSection);
+
+ var normContext = (NormContext) objects[1];
+ Assert.AreSame(assessmentSection.FailureMechanismContribution, normContext.WrappedData);
+ Assert.AreSame(assessmentSection, normContext.AssessmentSection);
+
+ var contributionContext = (FailureMechanismContributionContext) objects[2];
+ Assert.AreSame(assessmentSection.FailureMechanismContribution, contributionContext.WrappedData);
+ Assert.AreSame(assessmentSection, contributionContext.Parent);
+
+ var context = (HydraulicBoundaryDatabaseContext) objects[3];
+ Assert.AreSame(assessmentSection.HydraulicBoundaryDatabase, context.WrappedData);
+ Assert.AreSame(assessmentSection, context.AssessmentSection);
+
+ var backgroundData = (BackgroundData) objects[4];
+ Assert.AreSame(assessmentSection.BackgroundData, backgroundData);
+
+ var comment = (Comment) objects[5];
+ Assert.AreSame(assessmentSection.Comments, comment);
+ }
+ }
+
+ [Test]
+ public void ContextMenuStrip_Always_CallsBuilder()
+ {
+ // Setup
+ var menuBuilder = mocks.StrictMock();
+ using (mocks.Ordered())
+ {
+ menuBuilder.Expect(mb => mb.AddOpenItem()).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.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(null, treeViewControl)).Return(menuBuilder);
+ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ plugin.Gui = gui;
+
+ // Call
+ info.ContextMenuStrip(null, null, treeViewControl);
+ }
+ }
+
+ // Assert
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void ContextMenuStrip_Always_AddCustomItems()
+ {
+ // Setup
+ using (var treeView = new TreeViewControl())
+ {
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection);
+ var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
+
+ var gui = mocks.Stub();
+ gui.Stub(cmp => cmp.Get(assessmentSectionContext, treeView)).Return(menuBuilder);
+ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments();
+ gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ plugin.Gui = gui;
+
+ // Call
+ using (ContextMenuStrip menu = GetInfo(plugin).ContextMenuStrip(assessmentSectionContext, null, treeView))
+ {
+ // Assert
+ Assert.AreEqual(10, menu.Items.Count);
+
+ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuImportAssessmentSectionIndex,
+ "&Importeren...",
+ "Importeer de gegevens vanuit een bestand.",
+ CoreGuiResources.ImportIcon);
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void CanRename_Always_ReturnsTrue()
+ {
+ // Setup
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+
+ // Call
+ bool canRename = info.CanRename(null, null);
+
+ // Assert
+ Assert.IsTrue(canRename);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void OnNodeRenamed_WithData_SetProjectNameWithNotification()
+ {
+ // Setup
+ var observer = mocks.Stub();
+ observer.Expect(o => o.UpdateObserver());
+ mocks.ReplayAll();
+
+ var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
+ var assessmentSectionContext = new AssessmentSectionStateRootContext(assessmentSection);
+ assessmentSectionContext.Attach(observer);
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ // Call
+ const string newName = "New Name";
+ info.OnNodeRenamed(assessmentSectionContext, newName);
+
+ // Assert
+ Assert.AreEqual(newName, assessmentSection.Name);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void CanRemove_Always_ReturnsFalse()
+ {
+ // Setup
+ mocks.ReplayAll();
+
+ using (var plugin = new RiskeerPlugin())
+ {
+ TreeNodeInfo info = GetInfo(plugin);
+ // Call
+ bool canRemove = info.CanRemove(null, null);
+
+ // Assert
+ Assert.IsFalse(canRemove);
+ }
+
+ mocks.VerifyAll();
+ }
+
+ private TreeNodeInfo GetInfo(RiskeerPlugin plugin)
+ {
+ return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(AssessmentSectionStateRootContext));
+ }
+ }
+}
\ No newline at end of file