Index: Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs =================================================================== diff -u -rfff12e249602fb700b2854c14a3b7cdd0b73c023 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs (.../ICalculation.cs) (revision fff12e249602fb700b2854c14a3b7cdd0b73c023) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/ICalculation.cs (.../ICalculation.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -29,6 +29,11 @@ public interface ICalculation : ICalculationBase, ICommentable { /// + /// Gets or sets the name of this calculation item. + /// + new string Name { get; set; } + + /// /// Gets a value indicating whether or not this calculation item contains calculation output. /// bool HasOutput { get; } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs =================================================================== diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs (.../CalculationTreeNodeInfoFactory.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/CalculationTreeNodeInfoFactory.cs (.../CalculationTreeNodeInfoFactory.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -81,12 +81,15 @@ /// /// The icon of the . /// The function for obtaining the child node objects. + /// The function for obtaining the context menu strip. + /// The action to perform on removing a node. /// The type of calculation context to create a object for. /// A object. public static TreeNodeInfo CreateCalculationContextTreeNodeInfo( Bitmap icon, Func childeNodeObjects, - Func contextMenuStrip) + Func contextMenuStrip, + Action onNodeRemoved) where TCalculationContext : ICalculationContext { return new TreeNodeInfo @@ -95,7 +98,16 @@ Image = context => icon, EnsureVisibleOnCreate = (context, parent) => true, ChildNodeObjects = childeNodeObjects, - ContextMenuStrip = contextMenuStrip + ContextMenuStrip = contextMenuStrip, + CanRename = (context, parent) => true, + OnNodeRenamed = (context, newName) => + { + context.WrappedData.Name = newName; + context.WrappedData.NotifyObservers(); + }, + CanRemove = (context, parentData) => CalculationContextCanRemove(context, parentData), + OnNodeRemoved = onNodeRemoved, + CanDrag = (context, parentData) => true }; } @@ -340,5 +352,15 @@ # endregion # endregion + + #region Helper methods for CreateCalculationContextTreeNodeInfo + + private static bool CalculationContextCanRemove(ICalculationContext calculationContext, object parentNodeData) + { + var calculationGroupContext = parentNodeData as ICalculationContext; + return calculationGroupContext != null && calculationGroupContext.WrappedData.Children.Contains(calculationContext.WrappedData); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs =================================================================== diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -985,15 +985,17 @@ var icon = RingtoetsFormsResources.CalculateIcon; Func childNodeObjects = context => new object[0]; Func contextMenuStrip = (context, parent, treeViewControl) => new ContextMenuStrip(); + Action onNodeRemoved = (context, parent) => { }; // Call - var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(icon, childNodeObjects, contextMenuStrip); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(icon, childNodeObjects, contextMenuStrip, onNodeRemoved); // Assert Assert.AreEqual(typeof(TestCalculationContext), treeNodeInfo.TagType); TestHelper.AssertImagesAreEqual(icon, treeNodeInfo.Image(null)); Assert.AreSame(childNodeObjects, treeNodeInfo.ChildNodeObjects); Assert.AreSame(contextMenuStrip, treeNodeInfo.ContextMenuStrip); + Assert.AreSame(onNodeRemoved, treeNodeInfo.OnNodeRemoved); Assert.IsNull(treeNodeInfo.ForeColor); Assert.IsNull(treeNodeInfo.CanCheck); Assert.IsNull(treeNodeInfo.IsChecked); @@ -1016,7 +1018,7 @@ }; var context = new TestCalculationContext(calculation, failureMechanismMock); - var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); // Call var text = treeNodeInfo.Text(context); @@ -1030,7 +1032,7 @@ public void EnsureVisibleOnCreateOfCalculationContextTreeNodeInfo_Always_ReturnsTrue() { // Setup - var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); // Call var result = treeNodeInfo.EnsureVisibleOnCreate(null, null); @@ -1039,6 +1041,133 @@ Assert.IsTrue(result); } + [Test] + public void CanRenameCalculationContextTreeNodeInfo_Always_ReturnTrue() + { + // Setup + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + // Call + var renameAllowed = treeNodeInfo.CanRename(null, null); + + // Assert + Assert.IsTrue(renameAllowed); + } + + [Test] + public void OnNodeRenamedOfCalculationContextTreeNodeInfo_Always_SetNewNameToPipingCalculationScenarioAndNotifyObserver() + { + // Setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculation = new TestCalculation + { + Name = "" + }; + + var context = new TestCalculationContext(calculation, failureMechanismMock); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + context.WrappedData.Attach(observerMock); + + // Call + const string newName = ""; + treeNodeInfo.OnNodeRenamed(context, newName); + + // Assert + Assert.AreEqual(newName, calculation.Name); + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void CanRemoveCalculationContextTreeNodeInfo_ParentIsCalculationGroupWithCalculation_ReturnTrue(bool groupNameEditable) + { + // Setup + var calculationToBeRemoved = new TestCalculation(); + var group = new CalculationGroup("", groupNameEditable); + group.Children.Add(calculationToBeRemoved); + + var mocks = new MockRepository(); + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var context = new TestCalculationContext(calculationToBeRemoved, failureMechanismMock); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + var groupContext = new TestCalculationGroupContext(group, failureMechanismMock); + + // Call + bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext); + + // Assert + Assert.IsTrue(removalAllowed); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void CanRemoveCalculationContextTreeNodeInfo_ParentIsCalculationGroupWithoutCalculation_ReturnFalse(bool groupNameEditable) + { + // Setup + var calculationToBeRemoved = new TestCalculation(); + var group = new CalculationGroup("", groupNameEditable); + + var mocks = new MockRepository(); + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var context = new TestCalculationContext(calculationToBeRemoved, failureMechanismMock); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + var groupContext = new TestCalculationGroupContext(group, failureMechanismMock); + + // Call + bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext); + + // Assert + Assert.IsFalse(removalAllowed); + } + + [Test] + public void CanRemoveCalculationContextTreeNodeInfo_EverythingElse_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var dataMock = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var nodeMock = new TestCalculationContext(new TestCalculation(), failureMechanismMock); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + // Call + bool removalAllowed = treeNodeInfo.CanRemove(nodeMock, dataMock); + + // Assert + Assert.IsFalse(removalAllowed); + mocks.VerifyAll(); // Expect no calls on arguments + } + + [Test] + public void CanDragCalculationContextTreeNodeInfo_Always_ReturnTrue() + { + // Setup + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null, null); + + // Call + var canDrag = treeNodeInfo.CanDrag(null, null); + + // Assert + Assert.IsTrue(canDrag); + } + #endregion # region Nested types Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs =================================================================== diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs (.../GrassCoverErosionInwardsGuiPlugin.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsGuiPlugin.cs (.../GrassCoverErosionInwardsGuiPlugin.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -78,6 +78,7 @@ yield return CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( GrassCoverErosionInwardsFormsResources.CalculationIcon, CalculationContextChildNodeObjects, + null, null); yield return new TreeNodeInfo Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs =================================================================== diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -108,21 +108,11 @@ FailureMechanismContextMenuStrip, Gui); -// yield return new TreeNodeInfo -// { -// ContextMenuStrip = PipingCalculationContextContextMenuStrip, -// ChildNodeObjects = PipingCalculationContextChildNodeObjects, -// CanRename = (pipingCalculationContext, parentData) => true, -// OnNodeRenamed = PipingCalculationContextOnNodeRenamed, -// CanRemove = PipingCalculationContextCanRemove, -// OnNodeRemoved = PipingCalculationContextOnNodeRemoved, -// CanDrag = (pipingCalculationContext, parentData) => true -// }; - yield return CalculationTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( PipingFormsResources.PipingIcon, PipingCalculationContextChildNodeObjects, - PipingCalculationContextContextMenuStrip); + PipingCalculationContextContextMenuStrip, + PipingCalculationContextOnNodeRemoved); yield return CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo( PipingCalculationGroupContextChildNodeObjects, @@ -499,18 +489,6 @@ return childNodes.ToArray(); } - private static void PipingCalculationContextOnNodeRenamed(PipingCalculationScenarioContext pipingCalculationScenarioContext, string newName) - { - pipingCalculationScenarioContext.WrappedData.Name = newName; - pipingCalculationScenarioContext.WrappedData.NotifyObservers(); - } - - private bool PipingCalculationContextCanRemove(PipingCalculationScenarioContext pipingCalculationScenarioContext, object parentNodeData) - { - var calculationGroupContext = parentNodeData as PipingCalculationGroupContext; - return calculationGroupContext != null && calculationGroupContext.WrappedData.Children.Contains(pipingCalculationScenarioContext.WrappedData); - } - private void PipingCalculationContextOnNodeRemoved(PipingCalculationScenarioContext pipingCalculationScenarioContext, object parentNodeData) { var calculationGroupContext = parentNodeData as PipingCalculationGroupContext; Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u -rd0553e74a8d5ff6534acf03faf4a8801c28bf7c0 -r6b43c39e0f54d1054729aaed5aa6dc19149ef72a --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision d0553e74a8d5ff6534acf03faf4a8801c28bf7c0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationScenarioContextTreeNodeInfoTest.cs (.../PipingCalculationScenarioContextTreeNodeInfoTest.cs) (revision 6b43c39e0f54d1054729aaed5aa6dc19149ef72a) @@ -144,58 +144,6 @@ Assert.IsInstanceOf(children[3]); } -// [Test] -// public void CanRenameNode_Always_ReturnTrue() -// { -// // Call -// var renameAllowed = info.CanRename(null, null); -// -// // Assert -// Assert.IsTrue(renameAllowed); -// } -// -// [Test] -// public void OnNodeRenamed_Always_SetNewNameToPipingCalculationScenario() -// { -// // Setup -// var observerMock = mocks.StrictMock(); -// observerMock.Expect(o => o.UpdateObserver()); -// -// var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()) -// { -// Name = "" -// }; -// -// var pipingFailureMechanismMock = mocks.StrictMock(); -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var pipingCalculationsInputs = new PipingCalculationScenarioContext(calculation, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// pipingCalculationsInputs.Attach(observerMock); -// -// // Call -// const string newName = ""; -// info.OnNodeRenamed(pipingCalculationsInputs, newName); -// -// // Assert -// Assert.AreEqual(newName, calculation.Name); -// mocks.VerifyAll(); -// } -// -// [Test] -// public void CanDrag_Always_ReturnTrue() -// { -// // Call -// var canDrag = info.CanDrag(null, null); -// -// // Assert -// Assert.IsTrue(canDrag); -// } -// [Test] public void ContextMenuStrip_PipingCalculationWithoutOutput_ContextMenuItemClearOutputDisabled() { @@ -306,196 +254,110 @@ mocks.VerifyAll(); // Expect no calls on arguments } -// [Test] -// [TestCase(true)] -// [TestCase(false)] -// public void CanRemove_ParentIsCalculationGroupWithCalculation_ReturnTrue(bool groupNameEditable) -// { -// // Setup -// var calculationToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()); -// var group = new CalculationGroup("", groupNameEditable); -// group.Children.Add(calculationToBeRemoved); -// -// var pipingFailureMechanismMock = mocks.StrictMock(); -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var calculationContext = new PipingCalculationScenarioContext(calculationToBeRemoved, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// var groupContext = new PipingCalculationGroupContext(group, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// -// // Call -// bool removalAllowed = info.CanRemove(calculationContext, groupContext); -// -// // Assert -// Assert.IsTrue(removalAllowed); -// } -// -// [Test] -// [TestCase(true)] -// [TestCase(false)] -// public void CanRemove_ParentIsCalculationGroupWithoutCalculation_ReturnFalse(bool groupNameEditable) -// { -// // Setup -// var calculationToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()); -// var group = new CalculationGroup("", groupNameEditable); -// -// var pipingFailureMechanismMock = mocks.StrictMock(); -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var calculationContext = new PipingCalculationScenarioContext(calculationToBeRemoved, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// var groupContext = new PipingCalculationGroupContext(group, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// -// // Call -// bool removalAllowed = info.CanRemove(calculationContext, groupContext); -// -// // Assert -// Assert.IsFalse(removalAllowed); -// } -// -// [Test] -// public void CanRemove_EverythingElse_ReturnFalse() -// { -// // Setup -// var dataMock = mocks.StrictMock(); -// var pipingFailureMechanismMock = mocks.StrictMock(); -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var nodeMock = new PipingCalculationScenarioContext(new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()), -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// -// // Call -// bool removalAllowed = info.CanRemove(nodeMock, dataMock); -// -// // Assert -// Assert.IsFalse(removalAllowed); -// mocks.VerifyAll(); // Expect no calls on arguments -// } -// -// [Test] -// [TestCase(true)] -// [TestCase(false)] -// public void OnNodeRemoved_ParentIsPipingCalculationGroupContext_RemoveCalculationFromGroup(bool groupNameEditable) -// { -// // Setup -// var observer = mocks.StrictMock(); -// observer.Expect(o => o.UpdateObserver()); -// -// var elementToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()); -// -// var group = new CalculationGroup("", groupNameEditable); -// group.Children.Add(elementToBeRemoved); -// group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput())); -// group.Attach(observer); -// -// var pipingFailureMechanismMock = mocks.StrictMock(); -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var calculationContext = new PipingCalculationScenarioContext(elementToBeRemoved, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// var groupContext = new PipingCalculationGroupContext(group, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanismMock, -// assessmentSectionMock); -// -// // Precondition -// Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); -// Assert.AreEqual(2, group.Children.Count); -// -// // Call -// info.OnNodeRemoved(calculationContext, groupContext); -// -// // Assert -// Assert.AreEqual(1, group.Children.Count); -// CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [TestCase(true)] -// [TestCase(false)] -// public void OnNodeRemoved_ParentIsPipingCalculationGroupContext_RemoveCalculationFromSectionResult(bool groupNameEditable) -// { -// // Setup -// var observer = mocks.StrictMock(); -// observer.Expect(o => o.UpdateObserver()); -// -// var pipingFailureMechanism = GetFailureMechanism(); -// var surfaceLines = pipingFailureMechanism.SurfaceLines.ToArray(); -// -// var elementToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()) -// { -// InputParameters = -// { -// SurfaceLine = surfaceLines[0] -// } -// }; -// -// var group = new CalculationGroup("", groupNameEditable); -// group.Children.Add(elementToBeRemoved); -// group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput())); -// group.Attach(observer); -// -// var assessmentSectionMock = mocks.StrictMock(); -// mocks.ReplayAll(); -// -// var calculationContext = new PipingCalculationScenarioContext(elementToBeRemoved, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanism, -// assessmentSectionMock); -// var groupContext = new PipingCalculationGroupContext(group, -// Enumerable.Empty(), -// Enumerable.Empty(), -// pipingFailureMechanism, -// assessmentSectionMock); -// -// group.AddCalculationScenariosToFailureMechanismSectionResult(pipingFailureMechanism); -// -// // Precondition -// Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); -// Assert.AreEqual(2, group.Children.Count); -// var sectionResults = pipingFailureMechanism.SectionResults.ToArray(); -// CollectionAssert.Contains(sectionResults[0].CalculationScenarios, elementToBeRemoved); -// -// // Call -// info.OnNodeRemoved(calculationContext, groupContext); -// -// // Assert -// Assert.AreEqual(1, group.Children.Count); -// CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); -// CollectionAssert.DoesNotContain(sectionResults[0].CalculationScenarios, elementToBeRemoved); -// -// mocks.VerifyAll(); -// } -// [Test] + [TestCase(true)] + [TestCase(false)] + public void OnNodeRemoved_ParentIsPipingCalculationGroupContext_RemoveCalculationFromGroup(bool groupNameEditable) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var elementToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()); + + var group = new CalculationGroup("", groupNameEditable); + group.Children.Add(elementToBeRemoved); + group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput())); + group.Attach(observer); + + var pipingFailureMechanismMock = mocks.StrictMock(); + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculationContext = new PipingCalculationScenarioContext(elementToBeRemoved, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanismMock, + assessmentSectionMock); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanismMock, + assessmentSectionMock); + + // Precondition + Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); + Assert.AreEqual(2, group.Children.Count); + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.AreEqual(1, group.Children.Count); + CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); + + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void OnNodeRemoved_ParentIsPipingCalculationGroupContext_RemoveCalculationFromSectionResult(bool groupNameEditable) + { + // Setup + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var pipingFailureMechanism = GetFailureMechanism(); + var surfaceLines = pipingFailureMechanism.SurfaceLines.ToArray(); + + var elementToBeRemoved = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()) + { + InputParameters = + { + SurfaceLine = surfaceLines[0] + } + }; + + var group = new CalculationGroup("", groupNameEditable); + group.Children.Add(elementToBeRemoved); + group.Children.Add(new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput())); + group.Attach(observer); + + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculationContext = new PipingCalculationScenarioContext(elementToBeRemoved, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionMock); + var groupContext = new PipingCalculationGroupContext(group, + Enumerable.Empty(), + Enumerable.Empty(), + pipingFailureMechanism, + assessmentSectionMock); + + group.AddCalculationScenariosToFailureMechanismSectionResult(pipingFailureMechanism); + + // Precondition + Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); + Assert.AreEqual(2, group.Children.Count); + var sectionResults = pipingFailureMechanism.SectionResults.ToArray(); + CollectionAssert.Contains(sectionResults[0].CalculationScenarios, elementToBeRemoved); + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.AreEqual(1, group.Children.Count); + CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); + CollectionAssert.DoesNotContain(sectionResults[0].CalculationScenarios, elementToBeRemoved); + + mocks.VerifyAll(); + } + + [Test] public void GivenInvalidPipingCalculation_WhenCalculatingFromContextMenu_ThenPipingCalculationNotifiesObserversAndLogMessageAdded() { // Given