Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -r9a83eb890b0d3aac04ee48d4999fae0c92e7e10c -r63e350644449882510f394e9b7d2ee67fcff2f62 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 9a83eb890b0d3aac04ee48d4999fae0c92e7e10c) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 63e350644449882510f394e9b7d2ee67fcff2f62) @@ -321,6 +321,10 @@ FailureMechanismEnabledContextMenuStrip, FailureMechanismDisabledContextMenuStrip); + yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo( + FailurePathChildNodeObjects, + FailurePathContextMenuStrip); + yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( CalculationContextChildNodeObjects, CalculationContextContextMenuStrip, @@ -698,6 +702,62 @@ #endregion + #region MacroStabilityInwardsFailurePathContext TreeNodeInfo + + private static object[] FailurePathChildNodeObjects(MacroStabilityInwardsFailurePathContext context) + { + MacroStabilityInwardsFailureMechanism failureMechanism = context.WrappedData; + IAssessmentSection assessmentSection = context.Parent; + + return new object[] + { + new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName, + GetFailurePathInputs(failureMechanism, assessmentSection), TreeFolderCategory.Input), + new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Outputs_DisplayName, + GetFailurePathOutputs(failureMechanism, assessmentSection), TreeFolderCategory.Output) + }; + } + + private static IEnumerable GetFailurePathInputs(MacroStabilityInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + return new object[] + { + new MacroStabilityInwardsFailureMechanismSectionsContext(failureMechanism, assessmentSection), + failureMechanism.InputComments + }; + } + + private static IEnumerable GetFailurePathOutputs(MacroStabilityInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput; + return new object[] + { + new FailureMechanismAssemblyCategoriesContext(failureMechanism, + assessmentSection, + () => probabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length)), + new MacroStabilityInwardsScenariosContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection), + new ProbabilityFailureMechanismSectionResultContext(failureMechanism.SectionResults, failureMechanism, assessmentSection), + failureMechanism.OutputComments + }; + } + + private ContextMenuStrip FailurePathContextMenuStrip(MacroStabilityInwardsFailurePathContext context, + object parentData, + TreeViewControl treeViewControl) + { + var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); + + return builder.AddOpenItem() + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + #endregion + #region MacroStabilityInwardsCalculationGroupContext TreeNodeInfo private static object[] CalculationGroupContextChildNodeObjects(MacroStabilityInwardsCalculationGroupContext nodeData) Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs =================================================================== diff -u -r9a83eb890b0d3aac04ee48d4999fae0c92e7e10c -r63e350644449882510f394e9b7d2ee67fcff2f62 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs (.../MacroStabilityInwardsPluginTest.cs) (revision 9a83eb890b0d3aac04ee48d4999fae0c92e7e10c) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/MacroStabilityInwardsPluginTest.cs (.../MacroStabilityInwardsPluginTest.cs) (revision 63e350644449882510f394e9b7d2ee67fcff2f62) @@ -126,7 +126,9 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(12, treeNodeInfos.Length); + Assert.AreEqual(13, treeNodeInfos.Length); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsFailureMechanismContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsFailurePathContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsSurfaceLinesContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsSurfaceLine))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsStochasticSoilModelCollectionContext))); @@ -135,7 +137,6 @@ Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsCalculationScenarioContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsCalculationGroupContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsInputContext))); - Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ProbabilityFailureMechanismSectionResultContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsOutputContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(MacroStabilityInwardsScenariosContext))); Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailurePathContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailurePathContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailurePathContextTreeNodeInfoTest.cs (revision 63e350644449882510f394e9b7d2ee67fcff2f62) @@ -0,0 +1,213 @@ +// 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 Core.Gui; +using Core.Gui.ContextMenu; +using Core.Gui.Forms.MainWindow; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Categories; +using Riskeer.Common.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Probability; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Forms.PresentationObjects; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.MacroStabilityInwards.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class MacroStabilityInwardsFailurePathContextTreeNodeInfoTest + { + private MacroStabilityInwardsPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void Setup() + { + plugin = new MacroStabilityInwardsPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(MacroStabilityInwardsFailurePathContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.ForeColor); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(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_WithContext_ReturnsName() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new MacroStabilityInwardsFailurePathContext(new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual("Dijken en dammen - Macrostabiliteit binnenwaarts", text); + mocks.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsFailureMechanismIcon() + { + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.FailureMechanismIcon, image); + } + + [Test] + public void ChildNodeObjects_WithContext_ReturnChildDataNodes() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var context = new MacroStabilityInwardsFailurePathContext(failureMechanism, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(context).ToArray(); + + // Assert + Assert.AreEqual(2, children.Length); + var inputsFolder = (CategoryTreeFolder) children[0]; + Assert.AreEqual("Invoer", inputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); + + Assert.AreEqual(2, inputsFolder.Contents.Count()); + var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputsFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismSectionsContext.AssessmentSection); + + var comment = (Comment) inputsFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.InputComments, comment); + + var outputsFolder = (CategoryTreeFolder) children[1]; + Assert.AreEqual("Oordeel", outputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); + + Assert.AreEqual(4, outputsFolder.Contents.Count()); + var failureMechanismAssemblyCategoriesContext = (FailureMechanismAssemblyCategoriesContext) outputsFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismAssemblyCategoriesContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismAssemblyCategoriesContext.AssessmentSection); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyCategoriesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + + failureMechanismAssemblyCategoriesContext.GetFailureMechanismSectionAssemblyCategoriesFunc(); + MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput; + Assert.AreEqual(probabilityAssessmentInput.GetN(assessmentSection.ReferenceLine.Length), calculator.AssemblyCategoriesInput.N); + } + + var failureMechanismScenariosContext = (MacroStabilityInwardsScenariosContext) outputsFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism, failureMechanismScenariosContext.FailureMechanism); + Assert.AreSame(failureMechanism.CalculationsGroup, failureMechanismScenariosContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismScenariosContext.AssessmentSection); + + var failureMechanismResultsContext = (ProbabilityFailureMechanismSectionResultContext) outputsFolder.Contents.ElementAt(2); + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismResultsContext.AssessmentSection); + + var commentContext = (Comment) outputsFolder.Contents.ElementAt(3); + Assert.AreSame(failureMechanism.OutputComments, commentContext); + } + + [Test] + public void ContextMenuStrip_WithContext_CallsContextMenuBuilderMethods() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + + using (var treeViewControl = new TreeViewControl()) + { + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + var context = new MacroStabilityInwardsFailurePathContext(failureMechanism, assessmentSection); + + 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.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); + } + + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(context, null, treeViewControl); + } + + // Assert + mocks.VerifyAll(); + } + } +} \ No newline at end of file