Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -rbd73023d5f8926a411da214fb5ce522056a0e30a -r379d603ad7570ee56a65fecc920e56ca24279065 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision bd73023d5f8926a411da214fb5ce522056a0e30a) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision 379d603ad7570ee56a65fecc920e56ca24279065) @@ -674,5 +674,73 @@ } } } + + [Test] + public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var section = new FailureMechanismSection("A", new[] + { + new Point2D(0, 0) + }); + failureMechanism.AddSection(section); + + failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation() + { + Name = "A", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + } + }); + failureMechanism.CalculationsGroup.Children.Add(new TestClosingStructuresCalculation() + { + Name = "B", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + } + }); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabaseStub = mocksRepository.Stub(); + hydraulicBoundaryDatabaseStub.FilePath = validFilePath; + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabaseStub; + + var failureMechanismContext = new ClosingStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl)) + { + // Call + TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuValidateAllIndex].PerformClick(), messages => + { + var messageList = messages.ToList(); + + // Assert + Assert.AreEqual(4, messageList.Count); + StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]); + StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]); + StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[2]); + StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[3]); + }); + } + } + } } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -r3450f7ca7e4504b963bd760cf28939c02ffc0b68 -r379d603ad7570ee56a65fecc920e56ca24279065 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 3450f7ca7e4504b963bd760cf28939c02ffc0b68) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 379d603ad7570ee56a65fecc920e56ca24279065) @@ -256,7 +256,13 @@ return null; } - private static void ValidateAll(IEnumerable> calculations, IAssessmentSection assessmentSection) {} + private static void ValidateAll(IEnumerable> calculations, IAssessmentSection assessmentSection) + { + foreach (var calculation in calculations) + { + StabilityPointStructuresCalculationService.Validate(calculation, assessmentSection); + } + } private void CalculateAll(StabilityPointStructuresFailureMechanism failureMechanism, IEnumerable> calculations, @@ -583,7 +589,7 @@ StructuresCalculation calculation = context.WrappedData; - return builder.AddValidateCalculationItem(context, delegate { }, ValidateAllDataAvailableAndGetErrorMessageForCalculation) + return builder.AddValidateCalculationItem(context, Validate, ValidateAllDataAvailableAndGetErrorMessageForCalculation) .AddPerformCalculationItem(calculation, context, Calculate, ValidateAllDataAvailableAndGetErrorMessageForCalculation) .AddClearCalculationOutputItem(calculation) .AddSeparator() @@ -611,6 +617,11 @@ context.AssessmentSection)); } + private static void Validate(StabilityPointStructuresCalculationContext context) + { + StabilityPointStructuresCalculationService.Validate(context.WrappedData, context.AssessmentSection); + } + private static void CalculationContextOnNodeRemoved(StabilityPointStructuresCalculationContext context, object parentData) { var calculationGroupContext = parentData as StabilityPointStructuresCalculationGroupContext; Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rdb80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd -r379d603ad7570ee56a65fecc920e56ca24279065 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision db80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 379d603ad7570ee56a65fecc920e56ca24279065) @@ -517,6 +517,75 @@ } [Test] + public void GivenCalculationWithNonExistingFilePath_WhenValidatingFromContextMenu_ThenLogMessagesAdded() + { + // Given + var guiMock = mocks.StrictMock(); + var observerMock = mocks.StrictMock(); + + var section = new FailureMechanismSection("A", new[] + { + new Point2D(1, 2), + new Point2D(3, 4) + }); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.AddSection(section); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0.0, 1.1); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random" + }; + hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); + + var assessmentSectionStub = mocks.Stub(); + + var calculation = new TestStabilityPointStructuresCalculation() + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Linear + } + }; + + var calculationContext = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, assessmentSectionStub); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + + plugin.Gui = guiMock; + + calculation.Attach(observerMock); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) + { + // When + Action action = () => contextMenuStrip.Items[contextMenuValidateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + }); + } + } + } + + [Test] public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() { // Setup Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rdb80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd -r379d603ad7570ee56a65fecc920e56ca24279065 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision db80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 379d603ad7570ee56a65fecc920e56ca24279065) @@ -275,8 +275,8 @@ var assessmentSectionStub = mocks.Stub(); assessmentSectionStub.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); var groupContext = new StabilityPointStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); using (var treeViewControl = new TreeViewControl()) @@ -748,8 +748,8 @@ var assessmentSectionStub = mocks.Stub(); var groupContext = new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); using (var treeViewControl = new TreeViewControl()) { @@ -797,6 +797,80 @@ } [Test] + public void ContextMenuStrip_ClickOnValidateAllItem_ScheduleAllChildCalculations() + { + // Setup + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + failureMechanism.AddSection(new FailureMechanismSection("A", new[] + { + new Point2D(0, 0) + })); + + failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculation() + { + Name = "A", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Linear + } + }); + + failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculation() + { + Name = "B", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Linear + } + }); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabaseStub = mocks.Stub(); + hydraulicBoundaryDatabaseStub.FilePath = validFilePath; + + var assessmentSectionStub = mocks.Stub(); + var groupContext = new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, + failureMechanism, + assessmentSectionStub); + + using (var treeViewControl = new TreeViewControl()) + { + guiMock.Expect(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); + guiMock.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + + mocks.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase = hydraulicBoundaryDatabaseStub; + + plugin.Gui = guiMock; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl)) + { + // Call + TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuValidateAllIndexRootGroup].PerformClick(), messages => + { + var messageList = messages.ToList(); + + // Assert + Assert.AreEqual(4, messageList.Count); + StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]); + StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]); + StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[2]); + StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[3]); + }); + } + } + } + + [Test] public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenStabilityPointStructureSelectedAndDialogClosed_ThenCalculationsAddedWithStabilityPointStructureAssigned() { // Given @@ -817,8 +891,8 @@ }; var nodeData = new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, - failureMechanism, - assessmentSectionMock); + failureMechanism, + assessmentSectionMock); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); @@ -833,8 +907,8 @@ DialogBoxHandler = (name, wnd) => { - var selectionDialog = (StructureSelectionDialog)new FormTester(name).TheObject; - var grid = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; grid.Rows[0].Cells[0].Value = true; @@ -875,8 +949,8 @@ }; var nodeData = new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, - failureMechanism, - assessmentSectionMock); + failureMechanism, + assessmentSectionMock); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); @@ -891,8 +965,8 @@ DialogBoxHandler = (name, wnd) => { - var selectionDialog = (StructureSelectionDialog)new FormTester(name).TheObject; - var grid = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; grid.Rows[0].Cells[0].Value = true; @@ -940,8 +1014,8 @@ }; var nodeData = new StabilityPointStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, - failureMechanism, - assessmentSectionMock); + failureMechanism, + assessmentSectionMock); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); @@ -956,8 +1030,8 @@ DialogBoxHandler = (name, wnd) => { - var selectionDialog = (StructureSelectionDialog)new FormTester(name).TheObject; - var grid = (DataGridViewControl)new ControlTester("DataGridViewControl", selectionDialog).TheObject; + var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject; + var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject; grid.Rows[0].Cells[0].Value = true; @@ -1020,11 +1094,11 @@ var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); var parentNodeData = new StabilityPointStructuresCalculationGroupContext(parentGroup, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); mocks.ReplayAll(); @@ -1058,11 +1132,11 @@ var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); var nodeData = new StabilityPointStructuresCalculationGroupContext(group, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); var parentNodeData = new StabilityPointStructuresCalculationGroupContext(parentGroup, - failureMechanism, - assessmentSectionStub); + failureMechanism, + assessmentSectionStub); var calculation = new StructuresCalculation(); observerMock.Expect(o => o.UpdateObserver()); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -rdb80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd -r379d603ad7570ee56a65fecc920e56ca24279065 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision db80505bcfa73bd0d51e41d82ec4ab9c37c3ecbd) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision 379d603ad7570ee56a65fecc920e56ca24279065) @@ -703,6 +703,79 @@ } } + [Test] + public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations() + { + // Setup + var guiMock = mocksRepository.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var section = new FailureMechanismSection("A", new[] + { + new Point2D(0, 0) + }); + failureMechanism.AddSection(section); + + failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculation() + { + Name = "A", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Linear + } + }); + failureMechanism.CalculationsGroup.Children.Add(new TestStabilityPointStructuresCalculation() + { + Name = "B", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(-1, "nonExisting", 1, 2), + InflowModelType = StabilityPointStructureInflowModelType.LowSill, + LoadSchematizationType = LoadSchematizationType.Linear + } + }); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabaseStub = mocksRepository.Stub(); + hydraulicBoundaryDatabaseStub.FilePath = validFilePath; + + var assessmentSectionMock = mocksRepository.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabaseStub; + + var failureMechanismContext = new StabilityPointStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var plugin = new StabilityPointStructuresPlugin()) + 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 + TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuValidateAllIndex].PerformClick(), messages => + { + var messageList = messages.ToList(); + + // Assert + Assert.AreEqual(4, messageList.Count); + StringAssert.StartsWith("Validatie van 'A' gestart om: ", messageList[0]); + StringAssert.StartsWith("Validatie van 'A' beëindigd om: ", messageList[1]); + StringAssert.StartsWith("Validatie van 'B' gestart om: ", messageList[2]); + StringAssert.StartsWith("Validatie van 'B' beëindigd om: ", messageList[3]); + }); + } + } + } + private static TreeNodeInfo GetInfo(StabilityPointStructuresPlugin plugin) { return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(StabilityPointStructuresFailureMechanismContext));