Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs =================================================================== diff -u -r0d093476f5f881de3d2a73d05241425898c69e5e -r9984d2faad6ed47635c72787d94f9fce4ab20b2c --- Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision 0d093476f5f881de3d2a73d05241425898c69e5e) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision 9984d2faad6ed47635c72787d94f9fce4ab20b2c) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2021. All rights reserved. +// Copyright (C) Stichting Deltares 2021. All rights reserved. // // This file is part of Riskeer. // @@ -943,6 +943,16 @@ CalculationsStateRootContextChildNodeObjects, CalculationsStateRootContextMenuStrip); + yield return CreateStateRootTreeNodeInfo( + FailurePathsStateRootContextChildNodeObjects, + FailurePathsStateRootContextMenuStrip); + + yield return new TreeNodeInfo + { + Text = context => Resources.RiskeerPlugin_GetStateInfos_FailurePaths, + Image = data => RiskeerCommonFormsResources.GeneralFolderIcon + }; + yield return new TreeNodeInfo { Text = data => Resources.RiskeerPlugin_BackgroundDataContext_Text, @@ -1898,8 +1908,39 @@ .Build(); } + + #region FailurePathsStateRootContext TreeNodeInfo + + private static object[] FailurePathsStateRootContextChildNodeObjects(FailurePathsStateRootContext nodeData) + { + AssessmentSection assessmentSection = nodeData.WrappedData; + + return new object[] + { + new FailurePathsContext(assessmentSection), + new AssemblyResultsContext(assessmentSection) + }; + } + + private ContextMenuStrip FailurePathsStateRootContextMenuStrip(FailurePathsStateRootContext nodeData, + object parentData, TreeViewControl treeViewControl) + { + return Gui.Get(nodeData, treeViewControl) + .AddOpenItem() + .AddSeparator() + .AddRenameItem() + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + #endregion + #endregion + #region StandAloneFailureMechanism TreeNodeInfo private static object[] StandAloneFailureMechanismDisabledChildNodeObjects(IFailureMechanismContext nodeData) Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs =================================================================== diff -u -r0d093476f5f881de3d2a73d05241425898c69e5e -r9984d2faad6ed47635c72787d94f9fce4ab20b2c --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs (.../RiskeerPluginTest.cs) (revision 0d093476f5f881de3d2a73d05241425898c69e5e) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs (.../RiskeerPluginTest.cs) (revision 9984d2faad6ed47635c72787d94f9fce4ab20b2c) @@ -604,10 +604,12 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(42, treeNodeInfos.Length); + Assert.AreEqual(44, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssessmentSection))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssessmentSectionStateRootContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(CalculationsStateRootContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailurePathsStateRootContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailurePathsContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(BackgroundData))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(NormContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ReferenceLineContext))); Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsContextTreeNodeInfoTest.cs (revision 9984d2faad6ed47635c72787d94f9fce4ab20b2c) @@ -0,0 +1,102 @@ +// 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 Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Integration.Forms.PresentationObjects; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Integration.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class FailurePathsContextTreeNodeInfoTest + { + [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.IsNull(info.ContextMenuStrip); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.ExpandOnCreate); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.CheckedState); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + string text = info.Text(null); + + // Assert + Assert.AreEqual("Faalpaden", text); + } + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.GeneralFolderIcon, image); + } + } + + private static TreeNodeInfo GetInfo(RiskeerPlugin plugin) + { + return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailurePathsContext)); + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs (revision 9984d2faad6ed47635c72787d94f9fce4ab20b2c) @@ -0,0 +1,270 @@ +// 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 Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using Core.Gui; +using Core.Gui.ContextMenu; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Integration.Data; +using Riskeer.Integration.Forms.PresentationObjects; +using RiskeerIntegrationFormsResources = Riskeer.Integration.Forms.Properties.Resources; + +namespace Riskeer.Integration.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class FailurePathsStateRootContextTreeNodeInfoTest + { + [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_WithContext_ReturnsName() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + Name = "ttt" + }; + + var context = new FailurePathsStateRootContext(assessmentSection); + + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual(assessmentSection.Name, text); + } + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerIntegrationFormsResources.AssessmentSectionFolderIcon, image); + } + } + + [Test] + public void EnsureVisibleOnCreate_Always_ReturnsTrue() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + bool result = info.EnsureVisibleOnCreate(null, null); + + // Assert + Assert.IsTrue(result); + } + } + + [Test] + public void ExpandOnCreate_Always_ReturnsTrue() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + bool result = info.ExpandOnCreate(null); + + // Assert + Assert.IsTrue(result); + } + } + + [Test] + public void ChildNodeObjects_Always_ReturnsChildrenOfData() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var context = new FailurePathsStateRootContext(assessmentSection); + + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + // Call + object[] objects = info.ChildNodeObjects(context).ToArray(); + + // Assert + Assert.AreEqual(2, objects.Length); + + var failurePathsContext = (FailurePathsContext) objects[0]; + Assert.AreSame(assessmentSection, failurePathsContext.WrappedData); + + var assemblyResultsContext = (AssemblyResultsContext) objects[1]; + Assert.AreSame(assessmentSection, assemblyResultsContext.WrappedData); + } + } + + [Test] + public void ContextMenuStrip_Always_CallsBuilder() + { + // Setup + var mocks = new MockRepository(); + 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.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 CanRename_Always_ReturnsTrue() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + + // Call + bool canRename = info.CanRename(null, null); + + // Assert + Assert.IsTrue(canRename); + } + } + + [Test] + public void OnNodeRenamed_WithData_SetProjectNameWithNotification() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.Stub(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var context = new FailurePathsStateRootContext(assessmentSection); + context.Attach(observer); + + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + // Call + const string newName = "New Name"; + info.OnNodeRenamed(context, newName); + + // Assert + Assert.AreEqual(newName, assessmentSection.Name); + } + + mocks.VerifyAll(); + } + + [Test] + public void CanRemove_Always_ReturnsFalse() + { + // Setup + using (var plugin = new RiskeerPlugin()) + { + TreeNodeInfo info = GetInfo(plugin); + // Call + bool canRemove = info.CanRemove(null, null); + + // Assert + Assert.IsFalse(canRemove); + } + } + + private static TreeNodeInfo GetInfo(RiskeerPlugin plugin) + { + return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(FailurePathsStateRootContext)); + } + } +} \ No newline at end of file