Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -r46e5ad5e2214e4c35c065738d3f33347893254e9 -r240fbc1c83da30eae57a9dace4f4a136c8213437 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 46e5ad5e2214e4c35c065738d3f33347893254e9) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -233,13 +233,20 @@ private static void InitializeHeightStructuresData(AssessmentSection demoAssessmentSection) { HeightStructuresFailureMechanism failureMechanism = demoAssessmentSection.HeightStructures; + failureMechanism.HeightStructures.Add(CreateDemoHeightStructure()); var calculation = new HeightStructuresCalculation(); failureMechanism.CalculationsGroup.Children.Add(calculation); calculation.InputParameters.HydraulicBoundaryLocation = demoAssessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001); calculation.InputParameters.NotifyObservers(); } + private static HeightStructure CreateDemoHeightStructure() + { + return new HeightStructure("KUNST1", "KUNST1", new Point2D(12345.56789, 9876.54321), + 45.0, 5.9, 0.01, 18.5, 0.05, 0.1, 1.5, 4.0, 0.05, 1.0, 50000.0, 0.02, 6.5, 0.1); + } + #endregion #region PipingFailureMechanism Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs =================================================================== diff -u -r46e5ad5e2214e4c35c065738d3f33347893254e9 -r240fbc1c83da30eae57a9dace4f4a136c8213437 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision 46e5ad5e2214e4c35c065738d3f33347893254e9) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -274,6 +274,9 @@ private static void AssertHeightStructuresFailureMechanism(AssessmentSection demoAssessmentSection) { + Assert.AreEqual(1, demoAssessmentSection.HeightStructures.HeightStructures.Count); + AssertExpectedHeightStructureValues(demoAssessmentSection.HeightStructures.HeightStructures[0]); + Assert.AreEqual(1, demoAssessmentSection.HeightStructures.CalculationsGroup.Children.Count); HeightStructuresCalculation calculation = demoAssessmentSection.HeightStructures .CalculationsGroup.GetCalculations() @@ -282,6 +285,27 @@ AssertExpectedHeightStructuresInput(calculation.InputParameters); } + private static void AssertExpectedHeightStructureValues(HeightStructure heightStructure) + { + Assert.AreEqual("KUNST1", heightStructure.Name); + Assert.AreEqual("KUNST1", heightStructure.Id); + Assert.AreEqual(new Point2D(12345.56789, 9876.54321), heightStructure.Location); + Assert.AreEqual(45.0, heightStructure.OrientationOfTheNormalOfTheStructure.Value); + Assert.AreEqual(5.9, heightStructure.LevelOfCrestOfStructure.Mean.Value); + Assert.AreEqual(0.01, heightStructure.LevelOfCrestOfStructure.StandardDeviation.Value); + Assert.AreEqual(18.5, heightStructure.FlowWidthAtBottomProtection.Mean.Value); + Assert.AreEqual(0.05, heightStructure.FlowWidthAtBottomProtection.StandardDeviation.Value); + Assert.AreEqual(0.1, heightStructure.CriticalOvertoppingDischarge.Mean.Value); + Assert.AreEqual(1.5, heightStructure.CriticalOvertoppingDischarge.StandardDeviation.Value); + Assert.AreEqual(4.0, heightStructure.WidthOfFlowApertures.Mean.Value); + Assert.AreEqual(0.05, heightStructure.WidthOfFlowApertures.StandardDeviation.Value); + Assert.AreEqual(1.0, heightStructure.FailureProbabilityOfStructureGivenErosion); + Assert.AreEqual(50000.0, heightStructure.StorageStructureArea.Mean.Value); + Assert.AreEqual(0.02, heightStructure.StorageStructureArea.StandardDeviation.Value); + Assert.AreEqual(6.5, heightStructure.AllowableIncreaseOfLevelForStorage.Mean.Value); + Assert.AreEqual(0.1, heightStructure.AllowableIncreaseOfLevelForStorage.StandardDeviation.Value); + } + private static void AssertExpectedHeightStructuresInput(HeightStructuresInput inputParameters) { Assert.AreEqual(1300001, inputParameters.HydraulicBoundaryLocation.Id); Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Resources/Structures.png =================================================================== diff -u -r423010168fe01b2373e9be55f047659911e670f5 -r240fbc1c83da30eae57a9dace4f4a136c8213437 Binary files differ Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r15ba2de00ab1dd0df317409a272ef686ee688297 -r240fbc1c83da30eae57a9dace4f4a136c8213437 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 15ba2de00ab1dd0df317409a272ef686ee688297) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -119,6 +119,31 @@ .Build() }; + yield return new TreeNodeInfo + { + Text = context => RingtoetsCommonFormsResources.StructuresCollection_DisplayName, + Image = context => RingtoetsCommonFormsResources.GeneralFolderIcon, + ForeColor = context => context.WrappedData.Any() + ? Color.FromKnownColor(KnownColor.ControlText) + : Color.FromKnownColor(KnownColor.GrayText), + ChildNodeObjects = context => context.WrappedData.Cast().ToArray(), + ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) + .AddImportItem() + .AddSeparator() + .AddExpandAllItem() + .AddCollapseAllItem() + .Build() + }; + + yield return new TreeNodeInfo + { + Text = structure => structure.Name, + Image = structure => RingtoetsCommonFormsResources.StructuresIcon, + ContextMenuStrip = (structure, parentData, treeViewControl) => Gui.Get(structure, treeViewControl) + .AddPropertiesItem() + .Build() + }; + yield return new TreeNodeInfo { Text = output => RingtoetsCommonFormsResources.CalculationOutput_DisplayName, @@ -139,22 +164,6 @@ .AddOpenItem() .Build() }; - - yield return new TreeNodeInfo - { - Text = context => RingtoetsCommonFormsResources.StructuresCollection_DisplayName, - Image = context => RingtoetsCommonFormsResources.GeneralFolderIcon, - ForeColor = context => context.WrappedData.Any() - ? Color.FromKnownColor(KnownColor.ControlText) - : Color.FromKnownColor(KnownColor.GrayText), - ChildNodeObjects = context => context.WrappedData.Cast().ToArray(), - ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) - .AddImportItem() - .AddSeparator() - .AddExpandAllItem() - .AddCollapseAllItem() - .Build() - }; } private void CalculateAll(HeightStructuresFailureMechanism failureMechanism, Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj =================================================================== diff -u -r15ba2de00ab1dd0df317409a272ef686ee688297 -r240fbc1c83da30eae57a9dace4f4a136c8213437 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision 15ba2de00ab1dd0df317409a272ef686ee688297) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -77,6 +77,7 @@ + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructureTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructureTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructureTreeNodeInfoTest.cs (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -0,0 +1,150 @@ +// Copyright (C) Stichting Deltares 2016. 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.Base.Geometry; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Plugin; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.HeightStructures.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class HeightStructureTreeNodeInfoTest + { + private MockRepository mocks; + private HeightStructuresPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructure)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Setup + mocks.ReplayAll(); + + // Assert + Assert.AreEqual(typeof(HeightStructure), info.TagType); + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNull(info.ChildNodeObjects); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.EnsureVisibleOnCreate); + 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_ReturnNameOfStructure() + { + // Setup + mocks.ReplayAll(); + string name = "very nice name!"; + var structure = CreateSimpleHeightStructure(name); + + // Call + string text = info.Text(structure); + + // Assert + Assert.AreEqual(name, text); + } + + [Test] + public void Text_Always_ReturnHeightStructureIcon() + { + // Setup + mocks.ReplayAll(); + + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var menuBuilderMock = mocks.StrictMock(); + menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.Build()).Return(null); + + using (var treeViewControl = new TreeViewControl()) + { + var nodeData = CreateSimpleHeightStructure("A"); + + var guiMock = mocks.StrictMock(); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilderMock); + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + info.ContextMenuStrip(nodeData, null, treeViewControl); + } + // Assert + // Assert expectancies are called in TearDown() + } + + private static HeightStructure CreateSimpleHeightStructure(string name) + { + return new HeightStructure(name, "1", new Point2D(1, 2), 12.34, + 1.1, 0.4, + 2.2, 0.5, + 3.3, 0.6, + 4.4, 0.7, + 5.5, + 6.6, 0.8, + 7.7, 0.9); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r15ba2de00ab1dd0df317409a272ef686ee688297 -r240fbc1c83da30eae57a9dace4f4a136c8213437 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 15ba2de00ab1dd0df317409a272ef686ee688297) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 240fbc1c83da30eae57a9dace4f4a136c8213437) @@ -97,12 +97,13 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(8, treeNodeInfos.Length); + Assert.AreEqual(9, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCalculationGroupContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCalculationContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresInputContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCollectionContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructure))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ProbabilityAssessmentOutput))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(EmptyProbabilityAssessmentOutput))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismSectionResultContext)));