Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanism.cs =================================================================== diff -u -r67d6a305cec6967c1247f3d9cba8a817499d2a1d -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanism.cs (.../ClosingStructuresFailureMechanism.cs) (revision 67d6a305cec6967c1247f3d9cba8a817499d2a1d) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanism.cs (.../ClosingStructuresFailureMechanism.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.Generic; +using System.Linq; using Core.Common.Base; using Ringtoets.ClosingStructures.Data.Properties; using Ringtoets.Common.Data.Calculation; @@ -54,7 +55,7 @@ { get { - yield break; + return CalculationsGroup.GetCalculations().OfType(); } } Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -r151cae0869d7173dd61dfb4d85f6f2b545222e1f -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 151cae0869d7173dd61dfb4d85f6f2b545222e1f) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -37,7 +37,9 @@ using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.TreeNodeInfos; +using Ringtoets.HydraRing.IO; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; using ClosingStructuresDataResources = Ringtoets.ClosingStructures.Data.Properties.Resources; using ClosingStructuresFormsResources = Ringtoets.ClosingStructures.Forms.Properties.Resources; @@ -204,11 +206,12 @@ return builder.AddToggleRelevancyOfFailureMechanismItem(closingStructuresFailureMechanismContext, RemoveAllViewsForItem) .AddSeparator() - .AddValidateAllCalculationsInFailureMechanismItem( - closingStructuresFailureMechanismContext, - c => ValidateAll(), - ValidateAllDataAvailableAndGetErrorMessageForCalculationsInFailureMechanism) - .AddPerformAllCalculationsInFailureMechanismItem(closingStructuresFailureMechanismContext, CalculateAll, ValidateAllDataAvailableAndGetErrorMessageForCalculationsInFailureMechanism) + .AddValidateAllCalculationsInFailureMechanismItem(closingStructuresFailureMechanismContext, + c => ValidateAll(), + ValidateAllDataAvailableAndGetErrorMessageForCalculationsInFailureMechanism) + .AddPerformAllCalculationsInFailureMechanismItem(closingStructuresFailureMechanismContext, + CalculateAll, + ValidateAllDataAvailableAndGetErrorMessageForCalculationsInFailureMechanism) .AddClearAllCalculationOutputInFailureMechanismItem(closingStructuresFailureMechanismContext.WrappedData) .AddSeparator() .AddExpandAllItem() @@ -379,7 +382,7 @@ ClosingStructuresCalculation calculation = context.WrappedData; - return builder.AddValidateCalculationItem(context, null) + return builder.AddValidateCalculationItem(context, null, ValidateAllDataAvailableAndGetErrorMessageForCalculation) .AddPerformCalculationItem(calculation, context, null, ValidateAllDataAvailableAndGetErrorMessageForCalculation) .AddClearCalculationOutputItem(calculation) .AddSeparator() @@ -414,8 +417,24 @@ private static string ValidateAllDataAvailableAndGetErrorMessage(IAssessmentSection assessmentSection, ClosingStructuresFailureMechanism failureMechanism) { - //Check for database connection/part of a validation issue - currently a placeholder - return string.Empty; + if (!failureMechanism.Sections.Any()) + { + return RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported; + } + + if (assessmentSection.HydraulicBoundaryDatabase == null) + { + return RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported; + } + + var validationProblem = HydraulicDatabaseHelper.ValidatePathForCalculation(assessmentSection.HydraulicBoundaryDatabase.FilePath); + if (!string.IsNullOrEmpty(validationProblem)) + { + return string.Format(RingtoetsCommonServiceResources.Hydraulic_boundary_database_connection_failed_0_, + validationProblem); + } + + return null; } private static void CalculateAll(ClosingStructuresFailureMechanism failureMechanism, IEnumerable calculations) Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/Ringtoets.ClosingStructures.Plugin.csproj =================================================================== diff -u -rad75a347a7586757599297f2b2e776100d827264 -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/Ringtoets.ClosingStructures.Plugin.csproj (.../Ringtoets.ClosingStructures.Plugin.csproj) (revision ad75a347a7586757599297f2b2e776100d827264) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/Ringtoets.ClosingStructures.Plugin.csproj (.../Ringtoets.ClosingStructures.Plugin.csproj) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -85,6 +85,21 @@ Ringtoets.Common.IO False + + {d951d6da-fe83-4920-9fdb-63bf96480b54} + Ringtoets.Common.Service + False + + + {70f8cc9c-5bc8-4fb2-b201-eae7fa8088c2} + Ringtoets.HydraRing.Data + False + + + {B69D5B6C-6E14-4FA9-9EBC-8F97678CDB70} + Ringtoets.HydraRing.IO + False + {C6309704-D67B-434C-BC98-9F8910BC1D10} Ringtoets.ClosingStructures.Data Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismTest.cs =================================================================== diff -u -r67d6a305cec6967c1247f3d9cba8a817499d2a1d -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismTest.cs (.../ClosingStructuresFailureMechanismTest.cs) (revision 67d6a305cec6967c1247f3d9cba8a817499d2a1d) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismTest.cs (.../ClosingStructuresFailureMechanismTest.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -22,6 +22,8 @@ using System.Linq; using Core.Common.Base.Geometry; using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; namespace Ringtoets.ClosingStructures.Data.Test @@ -97,5 +99,35 @@ Assert.AreEqual(0, failureMechanism.Sections.Count()); Assert.AreEqual(0, failureMechanism.SectionResults.Count()); } + + [Test] + public void Calculations_MultipleChildrenAdded_ReturnClosingStructuresCalculations() + { + // Setup + var mocks = new MockRepository(); + var failureMechanism = new ClosingStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + new CalculationGroup(), + new ClosingStructuresCalculation(), + mocks.StrictMock(), + new ClosingStructuresCalculation() + } + } + }; + + mocks.ReplayAll(); + + // Call + var calculations = failureMechanism.Calculations.ToList(); + + // Assert + Assert.AreEqual(2, calculations.Count); + Assert.IsTrue(calculations.All(c => c is ClosingStructuresCalculation)); + mocks.VerifyAll(); + } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj =================================================================== diff -u -ra8ffe20fbe684f5020f5158354b33fad488baac9 -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision a8ffe20fbe684f5020f5158354b33fad488baac9) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -41,6 +41,10 @@ ..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + True + Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/packages.config =================================================================== diff -u -r3fad85f24665fdcfe75cba4e2f9ab30c2ca6a4b6 -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/packages.config (.../packages.config) (revision 3fad85f24665fdcfe75cba4e2f9ab30c2ca6a4b6) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/packages.config (.../packages.config) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -23,4 +23,5 @@ --> + \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj =================================================================== diff -u -r438a524144f283209902ae89f058a134380c9538 -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj (.../Ringtoets.ClosingStructures.Forms.Test.csproj) (revision 438a524144f283209902ae89f058a134380c9538) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/Ringtoets.ClosingStructures.Forms.Test.csproj (.../Ringtoets.ClosingStructures.Forms.Test.csproj) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -118,10 +118,18 @@ {4D840673-3812-4338-A352-84854E32B8A0} Ringtoets.Common.Forms + + {d951d6da-fe83-4920-9fdb-63bf96480b54} + Ringtoets.Common.Service + {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil + + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} + Ringtoets.HydraRing.Data + {C6309704-D67B-434C-BC98-9F8910BC1D10} Ringtoets.ClosingStructures.Data Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r078878de01a4c060d2366b7406fe5236940827ad -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision 078878de01a4c060d2366b7406fe5236940827ad) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -19,8 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.IO; using System.Linq; using System.Windows.Forms; +using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.Commands; @@ -34,9 +36,12 @@ using Ringtoets.ClosingStructures.Plugin; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.HydraRing.Data; using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonServicesResources = Ringtoets.Common.Service.Properties.Resources; namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos { @@ -50,22 +55,34 @@ private const int contextMenuCalculateAllIndex = 3; private const int contextMenuClearAllIndex = 4; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryLocationReader"); + private MockRepository mocksRepository; + private ClosingStructuresPlugin plugin; + private TreeNodeInfo info; [SetUp] public void SetUp() { mocksRepository = new MockRepository(); + plugin = new ClosingStructuresPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ClosingStructuresFailureMechanismContext)); } + [TearDown] + public void TearDown() + { + plugin.Dispose(); + + mocksRepository.VerifyAll(); + } + [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup - using (var plugin = new ClosingStructuresPlugin()) - { - var info = GetInfo(plugin); - + mocksRepository.ReplayAll(); + // Assert Assert.AreEqual(typeof(ClosingStructuresFailureMechanismContext), info.TagType); Assert.IsNotNull(info.Text); @@ -85,7 +102,6 @@ Assert.IsNull(info.CanDrop); Assert.IsNull(info.CanInsert); Assert.IsNull(info.OnDrop); - } } [Test] @@ -97,11 +113,7 @@ var failureMechanism = new ClosingStructuresFailureMechanism(); var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); - - using (var plugin = new ClosingStructuresPlugin()) - { - var info = GetInfo(plugin); - + // Call var children = info.ChildNodeObjects(failureMechanismContext).ToArray(); @@ -136,8 +148,6 @@ var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputsFolder.Contents[0]; Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); - } - mocksRepository.VerifyAll(); } [Test] @@ -153,9 +163,6 @@ }; var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); - using (var plugin = new ClosingStructuresPlugin()) - { - var info = GetInfo(plugin); // Call var children = info.ChildNodeObjects(failureMechanismContext).ToArray(); @@ -164,8 +171,6 @@ Assert.AreEqual(1, children.Length); var commentContext = (CommentContext) children[0]; Assert.AreSame(failureMechanism, commentContext.WrappedData); - } - mocksRepository.VerifyAll(); } [Test] @@ -190,21 +195,19 @@ menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); - using (var plugin = new ClosingStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilderMock); mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); // Call info.ContextMenuStrip(failureMechanismContext, null, treeViewControl); } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } [Test] @@ -226,28 +229,25 @@ menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); - using (var plugin = new ClosingStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilderMock); mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); // Call info.ContextMenuStrip(failureMechanismContext, null, treeViewControl); } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } [Test] public void ContextMenuStrip_FailureMechanismIsRelevant_AddCustomItems() { // Setup - using (var plugin = new ClosingStructuresPlugin()) using (var treeView = new TreeViewControl()) { var assessmentSectionMock = mocksRepository.Stub(); @@ -263,8 +263,6 @@ mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); - // Call using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView)) { @@ -294,15 +292,12 @@ false); } } - - mocksRepository.VerifyAll(); } [Test] public void ContextMenuStrip_FailureMechanismIsNotRelevant_AddCustomItems() { // Setup - using (var plugin = new ClosingStructuresPlugin()) using (var treeView = new TreeViewControl()) { var assessmentSectionMock = mocksRepository.Stub(); @@ -321,8 +316,6 @@ mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); - // Call using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView)) { @@ -335,7 +328,6 @@ RingtoetsCommonFormsResources.Checkbox_empty); } } - mocksRepository.VerifyAll(); } [Test] @@ -352,16 +344,13 @@ viewCommandsMock.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); guiMock.Stub(g => g.ViewCommands).Return(viewCommandsMock); - using (var plugin = new ClosingStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) { // Call @@ -370,7 +359,7 @@ } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } [Test] @@ -386,16 +375,13 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var guiMock = mocksRepository.StrictMock(); - using (var plugin = new ClosingStructuresPlugin()) using (var treeViewControl = new TreeViewControl()) { guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); mocksRepository.ReplayAll(); plugin.Gui = guiMock; - var info = GetInfo(plugin); - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) { // Call @@ -404,12 +390,323 @@ } // Assert - mocksRepository.VerifyAll(); + // Assert is done in TearDown } - private static TreeNodeInfo GetInfo(ClosingStructuresPlugin plugin) + [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemCalculateAllDisabledAndTooltipSet() { - return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(ClosingStructuresFailureMechanismContext)); + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + var assessmentSectionMock = mocksRepository.StrictMock(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateAllIcon, + false); + } + } } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocksRepository.Stub(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.CalculateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateAllIndex]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Calculate_all, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServicesResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateAllIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicDatabaseSet_ContextMenuItemCalculateAllEnabled() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndex, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Calculate_all_ToolTip, + RingtoetsCommonFormsResources.CalculateAllIcon); + } + } + } + + [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + var assessmentSectionMock = mocksRepository.StrictMock(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocksRepository.Stub(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndex, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.ValidateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateAllIndex]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Validate_all, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServicesResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateAllIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicDatabaseSet_ContextMenuItemValidateAllEnabled() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var nodeData = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndex, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.FailureMechanism_Validate_all_ToolTip, + RingtoetsCommonFormsResources.ValidateAllIcon); + } + } + } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r151cae0869d7173dd61dfb4d85f6f2b545222e1f -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision 151cae0869d7173dd61dfb4d85f6f2b545222e1f) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -19,9 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.IO; 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.ContextMenu; @@ -35,9 +37,12 @@ using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.HydraRing.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonServicesResources = Ringtoets.Common.Service.Properties.Resources; namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos { @@ -47,6 +52,7 @@ private const int contextMenuValidateIndex = 0; private const int contextMenuCalculateIndex = 1; private const int contextMenuClearIndex = 2; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryLocationReader"); private IGui guiMock; private TreeNodeInfo info; @@ -237,13 +243,15 @@ TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, RingtoetsCommonFormsResources.Validate, - RingtoetsCommonFormsResources.Validate_ToolTip, - RingtoetsCommonFormsResources.ValidateIcon); + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, RingtoetsCommonFormsResources.Calculate, - RingtoetsCommonFormsResources.Calculate_ToolTip, - RingtoetsCommonFormsResources.CalculateIcon); + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, RingtoetsCommonFormsResources.Clear_output, @@ -255,6 +263,305 @@ } [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + var calculation = new ClosingStructuresCalculation(); + + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + var guiMock = mocks.StrictMock(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.CalculateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateIndex]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Calculate, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServicesResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicBoundaryDatabaseSet_ContextMenuItemPerformCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + RingtoetsCommonFormsResources.Calculate, + RingtoetsCommonFormsResources.Calculate_ToolTip, + RingtoetsCommonFormsResources.CalculateIcon); + } + } + } + + [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + var calculation = new ClosingStructuresCalculation(); + + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.ValidateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateIndex]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Validate, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServicesResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicBoundaryDatabaseSet_ContextMenuItemValidateCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var calculation = new ClosingStructuresCalculation(); + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + RingtoetsCommonFormsResources.Validate, + RingtoetsCommonFormsResources.Validate_ToolTip, + RingtoetsCommonFormsResources.ValidateIcon); + } + } + } + + [Test] public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() { // Setup @@ -264,11 +571,11 @@ var observerMock = mocks.StrictMock(); var assessmentSectionMock = mocks.Stub(); var calculationContext = new ClosingStructuresCalculationContext(elementToBeRemoved, + failureMechanism, + assessmentSectionMock); + var groupContext = new ClosingStructuresCalculationGroupContext(group, failureMechanism, assessmentSectionMock); - var groupContext = new ClosingStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSectionMock); observerMock.Expect(o => o.UpdateObserver()); @@ -292,7 +599,7 @@ private class TestClosingStructuresOutput : ProbabilityAssessmentOutput { - public TestClosingStructuresOutput() : base(0, 0, 0, 0, 0) { } + public TestClosingStructuresOutput() : base(0, 0, 0, 0, 0) {} } } } \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r9214f74184b5923e0fb04b86d50c5bf8e5e57cdc -rb6a9219d1e628e4430ccf880e8ea390cec04fc04 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 9214f74184b5923e0fb04b86d50c5bf8e5e57cdc) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b6a9219d1e628e4430ccf880e8ea390cec04fc04) @@ -19,9 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.IO; 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; @@ -36,7 +38,10 @@ using Ringtoets.ClosingStructures.Plugin; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.HydraRing.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources; namespace Ringtoets.ClosingStructures.Forms.Test.TreeNodeInfos { @@ -56,6 +61,8 @@ private const int contextMenuCalculateAllIndexNestedGroup = 4; private const int contextMenuClearAllIndexNestedGroup = 5; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryLocationReader"); + private IGui guiMock; private TreeNodeInfo info; private MockRepository mocks; @@ -365,6 +372,391 @@ } [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.CalculateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = null; + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.CalculateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllDisabledAndTooltipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateAllIndexRootGroup]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Calculate_all, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServiceResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateAllIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicDatabaseSet_ContextMenuItemCalculateAllEnabled() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup, + RingtoetsCommonFormsResources.Calculate_all, + RingtoetsCommonFormsResources.CalculationGroup_CalculateAll_ToolTip, + RingtoetsCommonFormsResources.CalculateAllIcon); + } + } + } + + [Test] + public void ContextMenuStrip_NoFailureMechanismSections_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + var assessmentSectionMock = mocks.Stub(); + + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_failure_mechanism_sections_imported, + RingtoetsCommonFormsResources.ValidateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.Plugin_AllDataAvailable_No_hydraulic_boundary_database_imported, + RingtoetsCommonFormsResources.ValidateAllIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemValidateAllDisabledAndTooltipSet() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateAllIndexRootGroup]; + + Assert.AreEqual(RingtoetsCommonFormsResources.Validate_all, contextMenuItem.Text); + StringAssert.Contains(string.Format(RingtoetsCommonServiceResources.Hydraulic_boundary_database_connection_failed_0_, ""), contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateAllIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicDatabaseSet_ContextMenuItemValidateAllEnabled() + { + // Setup + var group = new CalculationGroup + { + Children = + { + new ClosingStructuresCalculation() + } + }; + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + + var failureMechanism = new ClosingStructuresFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test", new[] + { + new Point2D(0, 0) + })); + failureMechanism.CalculationsGroup.Children.Add(new ClosingStructuresCalculation()); + + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + var nodeData = new ClosingStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionMock); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup, + RingtoetsCommonFormsResources.Validate_all, + RingtoetsCommonFormsResources.CalculationGroup_Validate_all_ToolTip, + RingtoetsCommonFormsResources.ValidateAllIcon); + } + } + } + + [Test] public void ContextMenuStrip_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers() { // Setup