Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs =================================================================== diff -u -r817e9356fa95ddbb5a3e80e560186f5dee14aeed -r47ad5af99419ddf01efb941881eed1f9eb8d1211 --- Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision 817e9356fa95ddbb5a3e80e560186f5dee14aeed) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerPlugin.cs (.../RiskeerPlugin.cs) (revision 47ad5af99419ddf01efb941881eed1f9eb8d1211) @@ -993,6 +993,13 @@ SpecificFailurePathEnabledContextMenuStrip, SpecificFailurePathDisabledContextMenuStrip); + yield return new TreeNodeInfo + { + Text = context => Resources.SpecificFailurePathsCategoryTreeFolder_DisplayName, + Image = context => RiskeerCommonFormsResources.GeneralFolderIcon, + ChildNodeObjects = SpecificFailurePathsChildNodeObjects + }; + yield return new TreeNodeInfo { Text = context => RiskeerCommonFormsResources.FailureMechanismSections_DisplayName, @@ -1982,7 +1989,7 @@ return new object[] { new CategoryTreeFolder(Resources.GenericFailurePathsCategoryTreeFolder_DisplayName, GetGenericFailurePaths(assessmentSection)), - new CategoryTreeFolder(Resources.SpecificFailurePathsCategoryTreeFolder_DisplayName, Enumerable.Empty()), + new SpecificFailurePathsContext(assessmentSection.SpecificFailurePaths, assessmentSection), new AssemblyResultsContext(assessmentSection) }; } @@ -2029,54 +2036,19 @@ #endregion - #region StandAloneFailurePath TreeNodeInfo + #region SpecificFailurePaths TreeNodeInfo - private static object[] StandAloneFailurePathDisabledChildNodeObjects(IFailurePathContext nodeData) + private static object[] SpecificFailurePathsChildNodeObjects(SpecificFailurePathsContext nodeData) { - return new object[] - { - nodeData.WrappedData.NotRelevantComments - }; + return nodeData.WrappedData + .Select(sfp => new SpecificFailurePathContext(sfp, nodeData.AssessmentSection)) + .Cast() + .ToArray(); } - private ContextMenuStrip StandAloneFailurePathEnabledContextMenuStrip(IFailurePathContext nodeData, object parentData, TreeViewControl treeViewControl) - { - var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); - - return builder.AddOpenItem() - .AddSeparator() - .AddToggleRelevancyOfFailurePathItem(nodeData, RemoveAllViewsForItem) - .AddSeparator() - .AddCollapseAllItem() - .AddExpandAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - - private void RemoveAllViewsForItem(IFailurePathContext failurePathContext) - { - Gui.ViewCommands.RemoveAllViewsForItem(failurePathContext); - } - - private ContextMenuStrip StandAloneFailurePathDisabledContextMenuStrip(IFailurePathContext nodeData, - object parentData, - TreeViewControl treeViewControl) - { - var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); - - return builder.AddToggleRelevancyOfFailurePathItem(nodeData, RemoveAllViewsForItem) - .AddSeparator() - .AddCollapseAllItem() - .AddExpandAllItem() - .AddSeparator() - .AddPropertiesItem() - .Build(); - } - #endregion - #region SpecificFailureMechanism TreeNodeInfo + #region SpecificFailurePath TreeNodeInfo private static object[] SpecificFailurePathDisabledChildNodeObjects(SpecificFailurePathContext nodeData) { @@ -2154,6 +2126,53 @@ #endregion + #region StandAloneFailurePath TreeNodeInfo + + private static object[] StandAloneFailurePathDisabledChildNodeObjects(IFailurePathContext nodeData) + { + return new object[] + { + nodeData.WrappedData.NotRelevantComments + }; + } + + private ContextMenuStrip StandAloneFailurePathEnabledContextMenuStrip(IFailurePathContext nodeData, object parentData, TreeViewControl treeViewControl) + { + var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); + + return builder.AddOpenItem() + .AddSeparator() + .AddToggleRelevancyOfFailurePathItem(nodeData, RemoveAllViewsForItem) + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + private void RemoveAllViewsForItem(IFailurePathContext failurePathContext) + { + Gui.ViewCommands.RemoveAllViewsForItem(failurePathContext); + } + + private ContextMenuStrip StandAloneFailurePathDisabledContextMenuStrip(IFailurePathContext nodeData, + object parentData, + TreeViewControl treeViewControl) + { + var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); + + return builder.AddToggleRelevancyOfFailurePathItem(nodeData, RemoveAllViewsForItem) + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + #endregion + #region GrassCoverSlipOffInwardsFailurePathContext TreeNodeInfo private static object[] GrassCoverSlipOffInwardsFailurePathEnabledChildNodeObjects(GrassCoverSlipOffInwardsFailurePathContext nodeData) Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs =================================================================== diff -u -r33cd1d7a97d4fb49b252b0d4df3fa56b273625a1 -r47ad5af99419ddf01efb941881eed1f9eb8d1211 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs (.../RiskeerPluginTest.cs) (revision 33cd1d7a97d4fb49b252b0d4df3fa56b273625a1) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerPluginTest.cs (.../RiskeerPluginTest.cs) (revision 47ad5af99419ddf01efb941881eed1f9eb8d1211) @@ -608,7 +608,7 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(44, treeNodeInfos.Length); + Assert.AreEqual(46, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssessmentSectionStateRootContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HydraulicLoadsStateRootContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(CalculationsStateRootContext))); @@ -653,6 +653,8 @@ Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssemblyResultsContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssemblyResultCategoriesContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssemblyResultPerSectionMapContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(SpecificFailurePathsContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(SpecificFailurePathContext))); } } Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs =================================================================== diff -u -re93da099fc3210a3c60ed77f5dff969297708e67 -r47ad5af99419ddf01efb941881eed1f9eb8d1211 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs (.../FailurePathsStateRootContextTreeNodeInfoTest.cs) (revision e93da099fc3210a3c60ed77f5dff969297708e67) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/FailurePathsStateRootContextTreeNodeInfoTest.cs (.../FailurePathsStateRootContextTreeNodeInfoTest.cs) (revision 47ad5af99419ddf01efb941881eed1f9eb8d1211) @@ -246,9 +246,9 @@ Assert.AreSame(assessmentSection.TechnicalInnovation, technicalInnovationFailurePathContext.WrappedData); Assert.AreSame(assessmentSection, technicalInnovationFailurePathContext.Parent); - var specificFailurePathsFolder = (CategoryTreeFolder) objects[1]; - Assert.AreEqual("Specifieke faalpaden", specificFailurePathsFolder.Name); - CollectionAssert.IsEmpty(specificFailurePathsFolder.Contents); + var specificFailurePathsContext = (SpecificFailurePathsContext) objects[1]; + Assert.AreSame(assessmentSection.SpecificFailurePaths, specificFailurePathsContext.WrappedData); + Assert.AreSame(assessmentSection, specificFailurePathsContext.AssessmentSection); var assemblyResultsContext = (AssemblyResultsContext) objects[2]; Assert.AreSame(assessmentSection, assemblyResultsContext.WrappedData); Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathContextTreeNodeInfoTest.cs =================================================================== diff -u -r817e9356fa95ddbb5a3e80e560186f5dee14aeed -r47ad5af99419ddf01efb941881eed1f9eb8d1211 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathContextTreeNodeInfoTest.cs (.../SpecificFailurePathContextTreeNodeInfoTest.cs) (revision 817e9356fa95ddbb5a3e80e560186f5dee14aeed) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathContextTreeNodeInfoTest.cs (.../SpecificFailurePathContextTreeNodeInfoTest.cs) (revision 47ad5af99419ddf01efb941881eed1f9eb8d1211) @@ -162,8 +162,6 @@ var outputComment = (Comment) outputFolder.Contents.ElementAt(0); Assert.AreSame(specificFailurePath.OutputComments, outputComment); - - mocks.VerifyAll(); } [Test] @@ -178,17 +176,15 @@ IsRelevant = false }; - var failureMechanismContext = new SpecificFailurePathContext(failurePath, assessmentSection); + var context = new SpecificFailurePathContext(failurePath, assessmentSection); // Call - object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + object[] children = info.ChildNodeObjects(context).ToArray(); // Assert Assert.AreEqual(1, children.Length); var comment = (Comment) children[0]; Assert.AreSame(failurePath.NotRelevantComments, comment); - - mocks.VerifyAll(); } [Test] Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathsContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathsContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/TreeNodeInfos/SpecificFailurePathsContextTreeNodeInfoTest.cs (revision 47ad5af99419ddf01efb941881eed1f9eb8d1211) @@ -0,0 +1,156 @@ +// 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 NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailurePath; +using Riskeer.Common.Forms.PresentationObjects; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Integration.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class SpecificFailurePathsContextTreeNodeInfoTest + { + private MockRepository mocks; + private TreeNodeInfo info; + private RiskeerPlugin plugin; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RiskeerPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(SpecificFailurePathsContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + mocks.ReplayAll(); + + // 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.IsNotNull(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_ReturnsSetText() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failurePaths = new ObservableList(); + var failureMechanismContext = new SpecificFailurePathsContext(failurePaths, assessmentSection); + + // Call + string text = info.Text(failureMechanismContext); + + // Assert + Assert.AreEqual("Specifieke faalpaden", text); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + mocks.ReplayAll(); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.GeneralFolderIcon, image); + } + + [Test] + public void ChildNodeObjects_WithoutFailurePaths_ReturnChildDataNodes() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failurePaths = new ObservableList(); + var context = new SpecificFailurePathsContext(failurePaths, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(context).ToArray(); + + // Assert + CollectionAssert.IsEmpty(children); + } + + [Test] + public void ChildNodeObjects_WithFailurePaths_ReturnChildDataNodes() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failurePath = new SpecificFailurePath(); + var failurePaths = new ObservableList + { + failurePath + }; + var context = new SpecificFailurePathsContext(failurePaths, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(context).ToArray(); + + // Assert + Assert.AreEqual(1, children.Length); + var failurePathContext = (SpecificFailurePathContext) children[0]; + Assert.AreSame(failurePath, failurePathContext.WrappedData); + Assert.AreSame(assessmentSection, failurePathContext.Parent); + } + } +} \ No newline at end of file