Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r64b78f0ebd8e643a4285789d096e9c2a8c8a39af -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 64b78f0ebd8e643a4285789d096e9c2a8c8a39af) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -22,7 +22,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -91,6 +91,15 @@ } /// + /// Looks up a localized string similar to Nieuwe berekening. + /// + public static string ClosingStructuresCalculation_DefaultName { + get { + return ResourceManager.GetString("ClosingStructuresCalculation_DefaultName", resourceCulture); + } + } + + /// /// Looks up a localized string similar to BSKW. /// public static string ClosingStructuresFailureMechanism_Code { Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.resx =================================================================== diff -u -r64b78f0ebd8e643a4285789d096e9c2a8c8a39af -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.resx (.../Resources.resx) (revision 64b78f0ebd8e643a4285789d096e9c2a8c8a39af) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Properties/Resources.resx (.../Resources.resx) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -132,4 +132,7 @@ Verdronken koker + + Nieuwe berekening + \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PresentationObjects/ClosingStructuresCalculationContext.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PresentationObjects/ClosingStructuresCalculationContext.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PresentationObjects/ClosingStructuresCalculationContext.cs (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -0,0 +1,48 @@ +// 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; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.PresentationObjects; + +namespace Ringtoets.ClosingStructures.Forms.PresentationObjects +{ + /// + /// Presentation object for all data required to configure an instance of + /// in order to prepare it for performing a calculation. + /// + public class ClosingStructuresCalculationContext : ClosingStructuresContextBase, + ICalculationContext + { + /// + /// Creates a new instance of . + /// + /// The instance wrapped by this context object. + /// The failure mechanism which the context belongs to. + /// The assessment section which the calculation belongs to. + /// When any input argument is null. + public ClosingStructuresCalculationContext(ClosingStructuresCalculation wrappedData, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(wrappedData, failureMechanism, assessmentSection) {} + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Ringtoets.ClosingStructures.Forms.csproj =================================================================== diff -u -rad75a347a7586757599297f2b2e776100d827264 -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Ringtoets.ClosingStructures.Forms.csproj (.../Ringtoets.ClosingStructures.Forms.csproj) (revision ad75a347a7586757599297f2b2e776100d827264) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/Ringtoets.ClosingStructures.Forms.csproj (.../Ringtoets.ClosingStructures.Forms.csproj) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -41,6 +41,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -rad75a347a7586757599297f2b2e776100d827264 -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision ad75a347a7586757599297f2b2e776100d827264) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -34,10 +33,12 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; +using ClosingStructuresDataResources = Ringtoets.ClosingStructures.Data.Properties.Resources; namespace Ringtoets.ClosingStructures.Plugin { @@ -61,9 +62,6 @@ }; } - /// - /// Returns all instances provided for data of . - /// public override IEnumerable GetTreeNodeInfos() { yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo( @@ -77,6 +75,11 @@ CalculationGroupContextContextMenuStrip, CalculationGroupContextOnNodeRemoved); + yield return RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( + null, + null, + null); + yield return new TreeNodeInfo> { Text = context => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName, @@ -101,6 +104,21 @@ }; } + public override IEnumerable GetImportInfos() + { + yield return new ImportInfo + { + CreateFileImporter = (context, filePath) => new ClosingStructuresImporter(context.WrappedData, + context.AssessmentSection.ReferenceLine, + filePath), + Name = RingtoetsCommonFormsResources.StructuresImporter_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsCommonFormsResources.StructuresIcon, + FileFilter = RingtoetsCommonIOResources.DataTypeDisplayName_shape_file_filter, + IsEnabled = context => context.AssessmentSection.ReferenceLine != null + }; + } + #region ViewInfo #region ClosingStructuresFailureMechanismResultView ViewInfo @@ -226,8 +244,32 @@ private static object[] CalculationGroupContextChildNodeObjects(ClosingStructuresCalculationGroupContext context) { - //Part of WTI-550 - return new object[0]; + var childNodeObjects = new List(); + + foreach (ICalculationBase calculationItem in context.WrappedData.Children) + { + var calculation = calculationItem as ClosingStructuresCalculation; + var group = calculationItem as CalculationGroup; + + if (calculation != null) + { + childNodeObjects.Add(new ClosingStructuresCalculationContext(calculation, + context.FailureMechanism, + context.AssessmentSection)); + } + else if (group != null) + { + childNodeObjects.Add(new ClosingStructuresCalculationGroupContext(group, + context.FailureMechanism, + context.AssessmentSection)); + } + else + { + childNodeObjects.Add(calculationItem); + } + } + + return childNodeObjects.ToArray(); } private ContextMenuStrip CalculationGroupContextContextMenuStrip(ClosingStructuresCalculationGroupContext context, object parentData, TreeViewControl treeViewControl) @@ -245,7 +287,7 @@ .AddSeparator() .AddRemoveAllChildrenItem(group, Gui.ViewCommands); } - + builder.AddSeparator() .AddValidateAllCalculationsInGroupItem(context, c => ValidateAll(), ValidateAllDataAvailableAndGetErrorMessage) .AddPerformAllCalculationsInGroupItem(group, context, CalculateAll, ValidateAllDataAvailableAndGetErrorMessage) @@ -276,14 +318,19 @@ CalculateAll(context.FailureMechanism, group.GetCalculations().OfType()); } - private void AddCalculation(ClosingStructuresCalculationGroupContext closingStructuresCalculationGroupContext) + private void AddCalculation(ClosingStructuresCalculationGroupContext context) { - + var calculation = new ClosingStructuresCalculation + { + Name = NamingHelper.GetUniqueName(context.WrappedData.Children, ClosingStructuresDataResources.ClosingStructuresCalculation_DefaultName, c => c.Name) + }; + context.WrappedData.Children.Add(calculation); + context.WrappedData.NotifyObservers(); } private static void CalculationGroupContextOnNodeRemoved(ClosingStructuresCalculationGroupContext context, object parentNodeData) { - var parentGroupContext = (ClosingStructuresCalculationGroupContext)parentNodeData; + var parentGroupContext = (ClosingStructuresCalculationGroupContext) parentNodeData; parentGroupContext.WrappedData.Children.Remove(context.WrappedData); parentGroupContext.NotifyObservers(); @@ -303,20 +350,5 @@ { //Add calculate logic, part of WTI-554 } - - public override IEnumerable GetImportInfos() - { - yield return new ImportInfo - { - CreateFileImporter = (context, filePath) => new ClosingStructuresImporter(context.WrappedData, - context.AssessmentSection.ReferenceLine, - filePath), - Name = RingtoetsCommonFormsResources.StructuresImporter_DisplayName, - Category = RingtoetsCommonFormsResources.Ringtoets_Category, - Image = RingtoetsCommonFormsResources.StructuresIcon, - FileFilter = RingtoetsCommonIOResources.DataTypeDisplayName_shape_file_filter, - IsEnabled = context => context.AssessmentSection.ReferenceLine != null - }; - } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PresentationObjects/ClosingStructuresCalculationContextTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PresentationObjects/ClosingStructuresCalculationContextTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PresentationObjects/ClosingStructuresCalculationContextTest.cs (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -0,0 +1,57 @@ +// 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data; +using Ringtoets.ClosingStructures.Forms.PresentationObjects; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.PresentationObjects; + +namespace Ringtoets.ClosingStructures.Forms.Test.PresentationObjects +{ + [TestFixture] + public class ClosingStructuresCalculationContextTest + { + [Test] + public void ConstructorWithData_Always_ExpectedPropertiesSet() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSectionMock = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new ClosingStructuresCalculation(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + var context = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + // Assert + Assert.IsInstanceOf>(context); + Assert.IsInstanceOf>(context); + Assert.AreEqual(calculation, context.WrappedData); + Assert.AreEqual(failureMechanism, context.FailureMechanism); + Assert.AreEqual(assessmentSectionMock, context.AssessmentSection); + mocksRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj =================================================================== diff -u -rad75a347a7586757599297f2b2e776100d827264 -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj (.../Ringtoets.ClosingStructures.Forms.Test.csproj) (revision ad75a347a7586757599297f2b2e776100d827264) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj (.../Ringtoets.ClosingStructures.Forms.Test.csproj) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -58,11 +58,13 @@ Properties\GlobalAssembly.cs + + Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -0,0 +1,60 @@ +// 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.Controls.TreeView; +using Core.Common.Gui; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Forms.PresentationObjects; +using Ringtoets.ClosingStructures.Plugin; + +namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class ClosingStructuresCalculationContextTreeNodeInfoTest + { + private IGui guiMock; + private TreeNodeInfo info; + private MockRepository mocks; + private ClosingStructuresPlugin plugin; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + guiMock = mocks.Stub(); + plugin = new ClosingStructuresPlugin() + { + Gui = guiMock + }; + + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ClosingStructuresCalculationContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r029ff0ad40fcb7568d712e8be786a57a949a0b8c -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 029ff0ad40fcb7568d712e8be786a57a949a0b8c) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -28,6 +28,7 @@ using Core.Common.Gui.ContextMenu; using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; @@ -40,7 +41,7 @@ namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos { [TestFixture] - public class ClosingStructuresCalculationGroupContextTreeNodeInfoTest + public class ClosingStructuresCalculationGroupContextTreeNodeInfoTest : NUnitFormTest { private const int contextMenuAddCalculationGroupIndexRootGroup = 0; private const int contextMenuAddCalculationIndexRootGroup = 1; @@ -74,7 +75,7 @@ } [TearDown] - public void TearDown() + public override void TearDown() { plugin.Dispose(); mocks.VerifyAll(); @@ -128,6 +129,42 @@ } [Test] + public void ChildNodeObjects_GroupWithMixedContents_ReturnChildren() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + var calculationItemMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + var group = new CalculationGroup(); + var childGroup = new CalculationGroup(); + var childCalculation = new ClosingStructuresCalculation(); + + group.Children.Add(childGroup); + group.Children.Add(calculationItemMock); + group.Children.Add(childCalculation); + + var groupContext = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + // Call + var children = info.ChildNodeObjects(groupContext).ToArray(); + + // Assert + Assert.AreEqual(group.Children.Count, children.Length); + var calculationGroupContext = (ClosingStructuresCalculationGroupContext) children[0]; + Assert.AreSame(childGroup, calculationGroupContext.WrappedData); + Assert.AreSame(failureMechanism, calculationGroupContext.FailureMechanism); + Assert.AreSame(assessmentSectionMock, calculationGroupContext.AssessmentSection); + Assert.AreSame(calculationItemMock, children[1]); + var calculationContext = (ClosingStructuresCalculationContext) children[2]; + Assert.AreSame(childCalculation, calculationContext.WrappedData); + Assert.AreSame(assessmentSectionMock, calculationContext.AssessmentSection); + } + + [Test] public void ContextMenuStrip_WithoutParentNodeDefaultBehavior_CallsContextMenuBuilderMethods() { // Setup @@ -288,11 +325,10 @@ assessmentSectionMock); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - mocks.ReplayAll(); - using (var treeViewControl = new TreeViewControl()) { guiMock.Expect(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); + mocks.ReplayAll(); // Call using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl)) @@ -329,6 +365,149 @@ } [Test] + public void ContextMenuStrip_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var group = new CalculationGroup(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + var calculationGroup = new CalculationGroup + { + Name = "Nieuwe map" + }; + + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + group.Children.Add(calculationGroup); + nodeData.Attach(observerMock); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Precondition + Assert.AreEqual(1, group.Children.Count); + + // Call + contextMenu.Items[contextMenuAddCalculationGroupIndexRootGroup].PerformClick(); + + // Assert + Assert.AreEqual(2, group.Children.Count); + var newlyAddedItem = group.Children.Last(); + Assert.IsInstanceOf(newlyAddedItem); + Assert.AreEqual("Nieuwe map (1)", newlyAddedItem.Name, + "An item with the same name default name already exists, therefore '(1)' needs to be appended."); + } + } + } + + [Test] + public void ContextMenuStrip_ClickOnAddCalculationItem_AddCalculationToCalculationGroupAndNotifyObservers() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var group = new CalculationGroup(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + var calculation = new ClosingStructuresCalculation + { + Name = "Nieuwe berekening" + }; + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + group.Children.Add(calculation); + nodeData.Attach(observerMock); + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Precondition + Assert.AreEqual(1, group.Children.Count); + + // Call + contextMenu.Items[contextMenuAddCalculationIndexRootGroup].PerformClick(); + + // Assert + Assert.AreEqual(2, group.Children.Count); + var newlyAddedItem = group.Children.Last(); + Assert.IsInstanceOf(newlyAddedItem); + Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name, + "An item with the same name default name already exists, therefore '(1)' needs to be appended."); + } + } + } + + [Test] + public void ContextMenuStrip_ClickOnRemoveAllInGroup_RemovesAllChildren() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + var group = new CalculationGroup(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + var calculation = new ClosingStructuresCalculation + { + Name = "Nieuwe berekening" + }; + var viewCommandsMock = mocks.StrictMock(); + viewCommandsMock.Expect(vc => vc.RemoveAllViewsForItem(calculation)); + + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(viewCommandsMock); + + mocks.ReplayAll(); + + group.Children.Add(calculation); + nodeData.Attach(observerMock); + + plugin.Gui = guiMock; + + DialogBoxHandler = (name, wnd) => + { + var dialog = new MessageBoxTester(wnd); + dialog.ClickOk(); + }; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + contextMenu.Items[contextMenuRemoveAllChildrenRootGroupIndex].PerformClick(); + + // Assert + Assert.IsEmpty(group.Children); + } + } + } + + [Test] public void OnNodeRemoved_NestedCalculationGroup_RemoveGroupAndNotifyObservers() { // Setup Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs =================================================================== diff -u -rad75a347a7586757599297f2b2e776100d827264 -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs (.../ClosingStructuresPluginTest.cs) (revision ad75a347a7586757599297f2b2e776100d827264) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs (.../ClosingStructuresPluginTest.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -57,11 +57,12 @@ TreeNodeInfo[] treeNodeInfos = plugin.GetTreeNodeInfos().ToArray(); // Assert - Assert.AreEqual(4, treeNodeInfos.Length); + Assert.AreEqual(5, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ClosingStructuresFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismSectionResultContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ClosingStructuresContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ClosingStructuresCalculationGroupContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(ClosingStructuresCalculationContext))); } } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationContextTest.cs =================================================================== diff -u -rdd72cf407b7d0e9284d101bb2e2854e569b1a29a -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationContextTest.cs (.../HeightStructuresCalculationContextTest.cs) (revision dd72cf407b7d0e9284d101bb2e2854e569b1a29a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationContextTest.cs (.../HeightStructuresCalculationContextTest.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) @@ -36,7 +36,7 @@ { // Setup var mocksRepository = new MockRepository(); - var assessmentSectionMock = mocksRepository.StrictMock(); + var assessmentSectionMock = mocksRepository.Stub(); mocksRepository.ReplayAll(); var calculation = new HeightStructuresCalculation();