Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -reb812a61015ed168e94ac94a097f73f5793516ee -rc96c84bcf4cad9cba0d75dcd299b1e62bd9d925e --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision eb812a61015ed168e94ac94a097f73f5793516ee) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -266,6 +266,10 @@ CalculationsChildNodeObjects, CalculationsContextMenuStrip); + yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo( + FailurePathChildNodeObjects, + FailurePathContextMenuStrip); + yield return new TreeNodeInfo { Text = context => RiskeerCommonFormsResources.DikeProfiles_DisplayName, @@ -497,7 +501,7 @@ #region TreeNodeInfos - #region GrassCoverErosionInwardsFailureMechanismContext TreeNodeInfo + #region GrassCoverErosionInwardsCalculationsContext TreeNodeInfo private static object[] CalculationsChildNodeObjects(GrassCoverErosionInwardsCalculationsContext context) { @@ -506,12 +510,12 @@ return new object[] { - new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetInputs(wrappedData, assessmentSection), TreeFolderCategory.Input), + new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetCalculationsInputs(wrappedData, assessmentSection), TreeFolderCategory.Input), new GrassCoverErosionInwardsCalculationGroupContext(wrappedData.CalculationsGroup, null, wrappedData, assessmentSection) }; } - private static IEnumerable GetInputs(GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + private static IEnumerable GetCalculationsInputs(GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { return new object[] { @@ -573,6 +577,58 @@ #endregion + #region GrassCoverErosionInwardsFailurePathContext TreeNodeInfo + + private static object[] FailurePathChildNodeObjects(GrassCoverErosionInwardsFailurePathContext context) + { + GrassCoverErosionInwardsFailureMechanism wrappedData = context.WrappedData; + IAssessmentSection assessmentSection = context.Parent; + + return new object[] + { + new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName, GetFailurePathInputs(wrappedData, assessmentSection), TreeFolderCategory.Input), + new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Outputs_DisplayName, GetFailurePathOutputs(wrappedData, assessmentSection), TreeFolderCategory.Output) + }; + } + + private static IEnumerable GetFailurePathInputs(GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + return new object[] + { + new GrassCoverErosionInwardsFailureMechanismSectionsContext(failureMechanism, assessmentSection), + failureMechanism.InputComments + }; + } + + private static IEnumerable GetFailurePathOutputs(GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + return new object[] + { + new FailureMechanismAssemblyCategoriesContext(failureMechanism, assessmentSection, () => failureMechanism.GeneralInput.N), + new GrassCoverErosionInwardsScenariosContext(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection), + new ProbabilityFailureMechanismSectionResultContext( + failureMechanism.SectionResults, failureMechanism, assessmentSection), + failureMechanism.OutputComments + }; + } + + private ContextMenuStrip FailurePathContextMenuStrip(GrassCoverErosionInwardsFailurePathContext context, + object parentData, + TreeViewControl treeViewControl) + { + var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); + + return builder.AddOpenItem() + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + #endregion + #region GrassCoverErosionInwardsCalculationGroupContext TreeNodeInfo private static object[] CalculationGroupContextChildNodeObjects(GrassCoverErosionInwardsCalculationGroupContext context) Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs =================================================================== diff -u -r1a0ad304560f29f90c11f0f0a208cc68dc0feedd -rc96c84bcf4cad9cba0d75dcd299b1e62bd9d925e --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision 1a0ad304560f29f90c11f0f0a208cc68dc0feedd) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/GrassCoverErosionInwardsPluginTest.cs (.../GrassCoverErosionInwardsPluginTest.cs) (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -116,8 +116,9 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(11, treeNodeInfos.Length); + Assert.AreEqual(12, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationsContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsFailurePathContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(DikeProfilesContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationGroupContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationScenarioContext))); Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationsContextTreeNodeInfoTest.cs =================================================================== diff -u -reb812a61015ed168e94ac94a097f73f5793516ee -rc96c84bcf4cad9cba0d75dcd299b1e62bd9d925e --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationsContextTreeNodeInfoTest.cs) (revision eb812a61015ed168e94ac94a097f73f5793516ee) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationsContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationsContextTreeNodeInfoTest.cs) (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; @@ -34,9 +35,6 @@ using NUnit.Extensions.Forms; 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.Hydraulics; @@ -96,6 +94,34 @@ } [Test] + public void Text_Always_ReturnsName() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new GrassCoverErosionInwardsCalculationsContext(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual("Dijken en dammen - Grasbekleding erosie kruin en binnentalud", 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_Always_ReturnChildDataNodes() { // Setup Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsFailurePathContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsFailurePathContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsFailurePathContextTreeNodeInfoTest.cs (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -0,0 +1,212 @@ +// 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.Forms.PresentationObjects; +using Riskeer.GrassCoverErosionInwards.Data; +using Riskeer.GrassCoverErosionInwards.Forms.PresentationObjects; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.GrassCoverErosionInwards.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class GrassCoverErosionInwardsFailurePathContextTreeNodeInfoTest + { + private GrassCoverErosionInwardsPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void Setup() + { + plugin = new GrassCoverErosionInwardsPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(GrassCoverErosionInwardsFailurePathContext)); + } + + [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_Always_ReturnsName() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new GrassCoverErosionInwardsFailurePathContext(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Call + string text = info.Text(context); + + // Assert + Assert.AreEqual("Dijken en dammen - Grasbekleding erosie kruin en binnentalud", 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_Always_ReturnChildDataNodes() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var context = new GrassCoverErosionInwardsFailurePathContext(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(); + Assert.AreEqual(failureMechanism.GeneralInput.N, calculator.AssemblyCategoriesInput.N); + } + + var scenariosContext = (GrassCoverErosionInwardsScenariosContext) outputsFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.CalculationsGroup, scenariosContext.WrappedData); + Assert.AreSame(failureMechanism, scenariosContext.ParentFailureMechanism); + + var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputsFolder.Contents.ElementAt(2); + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); + + var outputComment = (Comment) outputsFolder.Contents.ElementAt(3); + Assert.AreSame(failureMechanism.OutputComments, outputComment); + mocks.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + + using (var treeViewControl = new TreeViewControl()) + { + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var context = new GrassCoverErosionInwardsFailurePathContext(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 Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationsContextTreeNodeInfoTest.cs =================================================================== diff -u -r02952ce44b631f296213e2c133a0d4c72fc574b1 -rc96c84bcf4cad9cba0d75dcd299b1e62bd9d925e --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationsContextTreeNodeInfoTest.cs (.../PipingCalculationsContextTreeNodeInfoTest.cs) (revision 02952ce44b631f296213e2c133a0d4c72fc574b1) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingCalculationsContextTreeNodeInfoTest.cs (.../PipingCalculationsContextTreeNodeInfoTest.cs) (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -115,7 +115,7 @@ } [Test] - public void Image_Always_ReturnsPipingIcon() + public void Image_Always_ReturnsFailureMechanismIcon() { // Setup mocks.ReplayAll(); @@ -124,7 +124,7 @@ Image image = info.Image(null); // Assert - TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.HydraulicCalculationIcon, image); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.FailureMechanismIcon, image); } [Test] Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingFailurePathContextTreeNodeInfoTest.cs =================================================================== diff -u -r3a12a88a3bd19ce54dee64c3ee747df3f8475ce3 -rc96c84bcf4cad9cba0d75dcd299b1e62bd9d925e --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingFailurePathContextTreeNodeInfoTest.cs (.../PipingFailurePathContextTreeNodeInfoTest.cs) (revision 3a12a88a3bd19ce54dee64c3ee747df3f8475ce3) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/TreeNodeInfos/PipingFailurePathContextTreeNodeInfoTest.cs (.../PipingFailurePathContextTreeNodeInfoTest.cs) (revision c96c84bcf4cad9cba0d75dcd299b1e62bd9d925e) @@ -26,7 +26,6 @@ using Core.Gui; using Core.Gui.ContextMenu; using Core.Gui.Forms.MainWindow; -using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Riskeer.AssemblyTool.KernelWrapper.Calculators; @@ -35,21 +34,32 @@ 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.Piping.Data; using Riskeer.Piping.Forms.PresentationObjects; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; -using CoreGuiResources = Core.Gui.Properties.Resources; namespace Riskeer.Piping.Plugin.Test.TreeNodeInfos { [TestFixture] - public class PipingFailurePathContextTreeNodeInfoTest : NUnitFormTest + public class PipingFailurePathContextTreeNodeInfoTest { private PipingPlugin plugin; private TreeNodeInfo info; + [SetUp] + public void Setup() + { + plugin = new PipingPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingFailurePathContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() { @@ -93,20 +103,23 @@ } [Test] - public void Image_Always_ReturnsPipingIcon() + public void Image_Always_ReturnsFailureMechanismIcon() { // Call Image image = info.Image(null); // Assert - TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.HydraulicCalculationIcon, image); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.FailureMechanismIcon, image); } [Test] public void ChildNodeObjects_Always_ReturnChildDataNodes() { // Setup - var assessmentSection = new AssessmentSectionStub(); + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + var failureMechanism = new PipingFailureMechanism(); var context = new PipingFailurePathContext(failureMechanism, assessmentSection); @@ -158,6 +171,7 @@ var commentContext = (Comment) outputsFolder.Contents.ElementAt(3); Assert.AreSame(failureMechanism.OutputComments, commentContext); + mocks.VerifyAll(); } [Test] @@ -198,18 +212,5 @@ // Assert mocks.VerifyAll(); } - - public override void Setup() - { - plugin = new PipingPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(PipingFailurePathContext)); - } - - public override void TearDown() - { - plugin.Dispose(); - - base.TearDown(); - } } } \ No newline at end of file