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