Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSection.cs =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSection.cs (.../AssessmentSection.cs) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/AssessmentSection.cs (.../AssessmentSection.cs) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -220,6 +220,7 @@ referenceLine = value; Piping.PipingProbabilityAssessmentInput.SectionLength = value?.Length ?? double.NaN; MacroStabilityInwards.MacroStabilityInwardsProbabilityAssessmentInput.SectionLength = value?.Length ?? double.NaN; + MacroStabilityOutwards.MacroStabilityOutwardsProbabilityAssessmentInput.SectionLength = value?.Length ?? double.NaN; } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContext.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContext.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContext.cs (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -0,0 +1,43 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Data.StandAlone; + +namespace Ringtoets.Integration.Forms.PresentationObjects.StandAlone +{ + /// + /// This class is a presentation object for an instance of . + /// + public class MacroStabilityOutwardsFailureMechanismContext : FailureMechanismContext + { + /// + /// Initializes a new instance of the class. + /// + /// The failure mechanism. + /// The parent of . + /// Thrown when any input argument is null. + public MacroStabilityOutwardsFailureMechanismContext(MacroStabilityOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) : + base(failureMechanism, assessmentSection) {} + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/MacroStabilityOutwardsFailureMechanismProperties.cs =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/MacroStabilityOutwardsFailureMechanismProperties.cs (.../MacroStabilityOutwardsFailureMechanismProperties.cs) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/MacroStabilityOutwardsFailureMechanismProperties.cs (.../MacroStabilityOutwardsFailureMechanismProperties.cs) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -126,6 +126,7 @@ set { data.MacroStabilityOutwardsProbabilityAssessmentInput.A = value; + data.NotifyObservers(); } } Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -31,6 +31,7 @@ + Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -79,6 +79,7 @@ using Ringtoets.Integration.Forms; using Ringtoets.Integration.Forms.Commands; using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Integration.Forms.PresentationObjects.StandAlone; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; using Ringtoets.Integration.Forms.Views.SectionResultViews; @@ -223,8 +224,8 @@ ), new FailureMechanismContextAssociation( typeof(MacroStabilityOutwardsFailureMechanism), - (mechanism, assessmentSection) => new FailureMechanismContext( - mechanism, + (mechanism, assessmentSection) => new MacroStabilityOutwardsFailureMechanismContext( + (MacroStabilityOutwardsFailureMechanism) mechanism, assessmentSection) ), new FailureMechanismContextAssociation( @@ -309,6 +310,10 @@ { CreateInstance = context => new StandAloneFailureMechanismProperties(context.WrappedData) }; + yield return new PropertyInfo + { + CreateInstance = context => new MacroStabilityOutwardsFailureMechanismProperties(context.WrappedData) + }; yield return new PropertyInfo, CalculationGroupContextProperties> { CreateInstance = context => new CalculationGroupContextProperties(context) @@ -650,6 +655,12 @@ StandAloneFailureMechanismEnabledContextMenuStrip, StandAloneFailureMechanismDisabledContextMenuStrip); + yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo( + MacroStabilityOutwardsFailureMechanismEnabledChildNodeObjects, + MacroStabilityOutwardsFailureMechanismDisabledChildNodeObjects, + MacroStabilityOutwardsFailureMechanismEnabledContextMenuStrip, + MacroStabilityOutwardsFailureMechanismDisabledContextMenuStrip); + yield return new TreeNodeInfo { Text = context => RingtoetsCommonFormsResources.FailureMechanismSections_DisplayName, @@ -1416,6 +1427,88 @@ #endregion + #region MacroStabilityOutwardsFailureMechanismContext TreeNodeInfo + + private static object[] MacroStabilityOutwardsFailureMechanismEnabledChildNodeObjects(MacroStabilityOutwardsFailureMechanismContext nodeData) + { + return new object[] + { + new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Inputs_DisplayName, + GetInputs(nodeData.WrappedData, nodeData.Parent), + TreeFolderCategory.Input), + new CategoryTreeFolder(RingtoetsCommonFormsResources.FailureMechanism_Outputs_DisplayName, + GetOutputs(nodeData.WrappedData), + TreeFolderCategory.Output) + }; + } + + private static object[] MacroStabilityOutwardsFailureMechanismDisabledChildNodeObjects(MacroStabilityOutwardsFailureMechanismContext nodeData) + { + return new object[] + { + nodeData.WrappedData.NotRelevantComments + }; + } + + private static IEnumerable GetInputs(MacroStabilityOutwardsFailureMechanism nodeData, IAssessmentSection assessmentSection) + { + return new object[] + { + new FailureMechanismSectionsContext(nodeData, assessmentSection), + nodeData.InputComments + }; + } + + private static IEnumerable GetOutputs(MacroStabilityOutwardsFailureMechanism nodeData) + { + var macrostabilityOutwards = nodeData as IHasSectionResults; + var failureMechanismSectionResultContexts = new object[2]; + + if (macrostabilityOutwards != null) + { + failureMechanismSectionResultContexts[0] = + new FailureMechanismSectionResultContext(macrostabilityOutwards.SectionResults, nodeData); + } + failureMechanismSectionResultContexts[1] = nodeData.OutputComments; + return failureMechanismSectionResultContexts; + } + + private ContextMenuStrip MacroStabilityOutwardsFailureMechanismEnabledContextMenuStrip(MacroStabilityOutwardsFailureMechanismContext nodeData, object parentData, TreeViewControl treeViewControl) + { + var builder = new RingtoetsContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); + + return builder.AddOpenItem() + .AddSeparator() + .AddToggleRelevancyOfFailureMechanismItem(nodeData, RemoveAllViewsForItem) + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .AddSeparator() + .AddPropertiesItem() + .Build(); + } + + private void RemoveAllViewsForItem(MacroStabilityOutwardsFailureMechanismContext failureMechanismContext) + { + Gui.ViewCommands.RemoveAllViewsForItem(failureMechanismContext); + } + + private ContextMenuStrip MacroStabilityOutwardsFailureMechanismDisabledContextMenuStrip(MacroStabilityOutwardsFailureMechanismContext nodeData, + object parentData, + TreeViewControl treeViewControl) + { + var builder = new RingtoetsContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); + + return builder.AddToggleRelevancyOfFailureMechanismItem(nodeData, RemoveAllViewsForItem) + .AddSeparator() + .AddCollapseAllItem() + .AddExpandAllItem() + .Build(); + } + + #endregion + + #region CategoryTreeFolder TreeNodeInfo /// Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionTest.cs =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionTest.cs (.../AssessmentSectionTest.cs) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/AssessmentSectionTest.cs (.../AssessmentSectionTest.cs) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -425,8 +425,9 @@ assessmentSection.ReferenceLine = referenceLine; // Assert - Assert.AreEqual(Math2D.Length(referenceLine.Points), assessmentSection.Piping.PipingProbabilityAssessmentInput.SectionLength); - Assert.AreEqual(Math2D.Length(referenceLine.Points), assessmentSection.MacroStabilityInwards.MacroStabilityInwardsProbabilityAssessmentInput.SectionLength); + Assert.AreEqual(referenceLine.Length, assessmentSection.Piping.PipingProbabilityAssessmentInput.SectionLength); + Assert.AreEqual(referenceLine.Length, assessmentSection.MacroStabilityInwards.MacroStabilityInwardsProbabilityAssessmentInput.SectionLength); + Assert.AreEqual(referenceLine.Length, assessmentSection.MacroStabilityOutwards.MacroStabilityOutwardsProbabilityAssessmentInput.SectionLength); } [Test] @@ -441,6 +442,7 @@ // Assert Assert.AreEqual(double.NaN, assessmentSection.Piping.PipingProbabilityAssessmentInput.SectionLength); Assert.AreEqual(double.NaN, assessmentSection.MacroStabilityInwards.MacroStabilityInwardsProbabilityAssessmentInput.SectionLength); + Assert.AreEqual(double.NaN, assessmentSection.MacroStabilityOutwards.MacroStabilityOutwardsProbabilityAssessmentInput.SectionLength); } private IFailureMechanism[] GetExpectedContributingFailureMechanisms(AssessmentSection section) Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContextTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContextTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PresentationObjects/StandAlone/MacroStabilityOutwardsFailureMechanismContextTest.cs (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Forms.PresentationObjects.StandAlone; + +namespace Ringtoets.Integration.Forms.Test.PresentationObjects.StandAlone +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismContextTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + var context = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf>(context); + Assert.AreSame(assessmentSection, context.Parent); + Assert.AreSame(failureMechanism, context.WrappedData); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_AssessmentSectionIsNull_ThrowArgumentNullException() + { + // Setup + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + // Call + TestDelegate call = () => new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, null); + + // Assert + Assert.Throws(call); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/MacroStabilityOutwardsFailureMechanismPropertiesTest.cs =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/MacroStabilityOutwardsFailureMechanismPropertiesTest.cs (.../MacroStabilityOutwardsFailureMechanismPropertiesTest.cs) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/PropertyClasses/MacroStabilityOutwardsFailureMechanismPropertiesTest.cs (.../MacroStabilityOutwardsFailureMechanismPropertiesTest.cs) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -21,9 +21,11 @@ using System; using System.ComponentModel; +using Core.Common.Base; using Core.Common.Gui.PropertyBag; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Integration.Data.StandAlone; @@ -193,10 +195,15 @@ [TestCase(-0.1)] [TestCase(1.1)] [TestCase(8)] - public void A_SetInvalidValue_ThrowsArgumentOutOfRangeException(double value) + public void A_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value) { // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + mocks.ReplayAll(); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + failureMechanism.Attach(observer); var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism); // Call @@ -205,6 +212,7 @@ // Assert var exception = Assert.Throws(call); Assert.AreEqual("De waarde moet in het bereik [0,0, 1,0] liggen.", exception.Message); + mocks.VerifyAll(); } [Test] @@ -213,17 +221,24 @@ [TestCase(1)] [TestCase(0.0000001)] [TestCase(0.9999999)] - public void A_SetValidValue_SetsValue(double value) + public void A_SetValidValue_SetsValueAndUpdatesObserver(double value) { // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + failureMechanism.Attach(observer); var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism); // Call properties.A = value; // Assert Assert.AreEqual(value, failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A); + mocks.VerifyAll(); } [Test] Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -37,6 +37,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/PropertyInfos/MacroStabilityOutwardsFailureMechanismPropertyInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/PropertyInfos/MacroStabilityOutwardsFailureMechanismPropertyInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/PropertyInfos/MacroStabilityOutwardsFailureMechanismPropertyInfoTest.cs (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -0,0 +1,83 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Forms.PresentationObjects.StandAlone; +using Ringtoets.Integration.Forms.PropertyClasses; + +namespace Ringtoets.Integration.Plugin.Test.PropertyInfos +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismPropertyInfoTest + { + private RingtoetsPlugin plugin; + private PropertyInfo info; + + [SetUp] + public void SetUp() + { + plugin = new RingtoetsPlugin(); + info = plugin.GetPropertyInfos().First(tni => tni.PropertyObjectType == typeof(MacroStabilityOutwardsFailureMechanismProperties)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(MacroStabilityOutwardsFailureMechanismContext), info.DataType); + Assert.AreEqual(typeof(MacroStabilityOutwardsFailureMechanismProperties), info.PropertyObjectType); + } + + [Test] + public void CreateInstance_Always_NewPropertiesWithFailureMechanismAsData() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var context = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + IObjectProperties objectProperties = info.CreateInstance(context); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(failureMechanism, objectProperties.Data); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7 -r8820d80a97281c96db5f89d5af6c74d26e0f5bca --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 2ef5183542af0464fab4ebadb3a6c2c4f7ff46b7) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -55,6 +55,7 @@ + @@ -69,6 +70,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs (revision 8820d80a97281c96db5f89d5af6c74d26e0f5bca) @@ -0,0 +1,435 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.Commands; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Integration.Data.StandAlone; +using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Ringtoets.Integration.Forms.PresentationObjects.StandAlone; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest + { + private const int contextMenuRelevancyIndexWhenNotRelevant = 0; + private const int contextMenuRelevancyIndexWhenRelevant = 2; + private MockRepository mocks; + private TreeNodeInfo info; + private RingtoetsPlugin plugin; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new RingtoetsPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(MacroStabilityOutwardsFailureMechanismContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + mocks.ReplayAll(); + + // 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.IsChecked); + 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 assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + string text = info.Text(failureMechanismContext); + + // Assert + Assert.AreEqual(failureMechanism.Name, text); + } + + [Test] + public void Image_Always_ReturnsSetImage() + { + // Setup + mocks.ReplayAll(); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.FailureMechanismIcon, image); + } + + [Test] + public void ForeColor_Always_ReturnsControlText() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var context = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + Color textColor = info.ForeColor(context); + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), textColor); + } + + [Test] + public void ChildNodeObjects_FailureMechanismIsRelevant_ReturnChildDataNodes() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + + // Assert + Assert.AreEqual(2, children.Length); + var inputFolder = (CategoryTreeFolder) children[0]; + Assert.AreEqual("Invoer", inputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputFolder.Category); + + var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData); + Assert.AreSame(assessmentSection, failureMechanismSectionsContext.AssessmentSection); + + var inputComment = (Comment) inputFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.InputComments, inputComment); + + var outputFolder = (CategoryTreeFolder) children[1]; + Assert.AreEqual("Oordeel", outputFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputFolder.Category); + var failureMechanismResultsContext = (FailureMechanismSectionResultContext) + outputFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); + + var outputComment = (Comment) outputFolder.Contents.ElementAt(1); + Assert.AreSame(failureMechanism.OutputComments, outputComment); + } + + [Test] + public void ChildNodeObjects_FailureMechanismIsNotRelevant_ReturnOnlyFailureMechanismNotRelevantComments() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + IsRelevant = false + }; + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(1, 2), + new Point2D(5, 6) + })); + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + + // Assert + Assert.AreEqual(1, children.Length); + var comment = (Comment) children[0]; + Assert.AreSame(failureMechanism.NotRelevantComments, comment); + } + + [Test] + public void ContextMenuStrip_FailureMechanismIsRelevant_CallsContextMenuBuilderMethods() + { + // Setup + using (var treeView = new TreeViewControl()) + { + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var assessmentSection = mocks.Stub(); + var context = new MacroStabilityOutwardsFailureMechanismContext(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.AddCustomItem(null)).IgnoreArguments().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, treeView)).Return(menuBuilder); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(context, assessmentSection, treeView); + + // Assert + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismIsNotRelevant_CallsContextMenuBuilderMethods() + { + // Setup + using (var treeView = new TreeViewControl()) + { + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + IsRelevant = false + }; + var assessmentSection = mocks.Stub(); + var context = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var menuBuilder = mocks.StrictMock(); + using (mocks.Ordered()) + { + menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().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.Build()).Return(null); + } + + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(context, treeView)).Return(menuBuilder); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(context, assessmentSection, treeView); + + // Assert + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismIsRelevant_IsRelevantEnabled() + { + // Setup + using (var treeView = new TreeViewControl()) + { + var assessmentSection = mocks.Stub(); + var failureMechanism = new MacroStabilityOutwardsFailureMechanism(); + var context = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(context, treeView)).Return(menuBuilder); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(context, assessmentSection, treeView)) + { + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant, + "I&s relevant", + "Geeft aan of dit toetsspoor relevant is of niet.", + RingtoetsCommonFormsResources.Checkbox_ticked); + } + + // Assert + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismIsRelevantAndClickOnIsRelevantItem_MakeFailureMechanismNotRelevant() + { + // Setup + var failureMechanismObserver = mocks.Stub(); + failureMechanismObserver.Expect(o => o.UpdateObserver()); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + IsRelevant = true + }; + failureMechanism.Attach(failureMechanismObserver); + + var assessmentSection = mocks.Stub(); + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); + + using (var treeViewControl = new TreeViewControl()) + { + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var gui = mocks.Stub(); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) + { + // Call + contextMenu.Items[contextMenuRelevancyIndexWhenRelevant].PerformClick(); + + // Assert + Assert.IsFalse(failureMechanism.IsRelevant); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismIsNotRelevantAndClickOnIsRelevantItem_MakeFailureMechanismRelevant() + { + // Setup + var failureMechanismObserver = mocks.Stub(); + failureMechanismObserver.Expect(o => o.UpdateObserver()); + + var failureMechanism = new MacroStabilityOutwardsFailureMechanism + { + IsRelevant = false + }; + failureMechanism.Attach(failureMechanismObserver); + + var assessmentSection = mocks.Stub(); + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) + { + // Call + contextMenu.Items[contextMenuRelevancyIndexWhenNotRelevant].PerformClick(); + + // Assert + Assert.IsTrue(failureMechanism.IsRelevant); + } + } + } + + /// + /// Used in ChildNodeObjects_FailureMechanismIsRelevant_OutputNodeAddedForResult(Type) + /// + private void ChildNodeObjects_FailureMechanismIsRelevantWithSectionResults_OutputNodeAdded() where T : FailureMechanismSectionResult + { + // Setup + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.StrictMultiMock>(typeof(IFailureMechanism)); + failureMechanism.Expect(fm => ((IFailureMechanism) fm).IsRelevant).Return(true); + failureMechanism.Expect(fm => fm.SectionResults).Return(new List()).Repeat.Any(); + failureMechanism.Expect(fm => ((IFailureMechanism) fm).InputComments).Return(new Comment()); + failureMechanism.Expect(fm => ((IFailureMechanism) fm).OutputComments).Return(new Comment()); + var failureMechanismContext = mocks.Stub(failureMechanism, assessmentSection); + + mocks.ReplayAll(); + + // Call + object[] children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + + // Assert + var outputFolder = (CategoryTreeFolder) children[1]; + + var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputFolder.Contents.ElementAt(0); + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); + } + } +} \ No newline at end of file