Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs =================================================================== diff -u -rc96f5829ddb898717ba2e98091a2219308f05d3e -r82ca29d1fd75e1bf0c3ff8190a8ad3a43e1d16d6 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision c96f5829ddb898717ba2e98091a2219308f05d3e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/PipingGuiPlugin.cs (.../PipingGuiPlugin.cs) (revision 82ca29d1fd75e1bf0c3ff8190a8ad3a43e1d16d6) @@ -100,8 +100,8 @@ CanRemove = PipingCalculationGroupContextCanRemove, OnNodeRemoved = PipingCalculationGroupContextOnNodeRemoved, CanDrag = PipingCalculationGroupContextCanDrag, - CanDrop = PipingCalculationGroupContextCanDrop, - CanInsert = PipingCalculationGroupContextCanInsert, + CanDrop = PipingCalculationGroupContextCanDropOrCanInsert, + CanInsert = PipingCalculationGroupContextCanDropOrCanInsert, OnDrop = PipingCalculationGroupContextOnDrop }; @@ -702,14 +702,9 @@ return true; } - private bool PipingCalculationGroupContextCanDrop(object draggedData, object targetData) + private bool PipingCalculationGroupContextCanDropOrCanInsert(object draggedData, object targetData) { - if (GetAsIPipingCalculationItem(draggedData) != null && NodesHaveSameParentFailureMechanism(draggedData, targetData)) - { - return true; - } - - return false; + return GetAsIPipingCalculationItem(draggedData) != null && NodesHaveSameParentFailureMechanism(draggedData, targetData); } private static IPipingCalculationItem GetAsIPipingCalculationItem(object item) @@ -754,11 +749,6 @@ return null; } - private bool PipingCalculationGroupContextCanInsert(object draggedData, object targetData) - { - return GetAsIPipingCalculationItem(draggedData) != null && NodesHaveSameParentFailureMechanism(draggedData, targetData); - } - private void PipingCalculationGroupContextOnDrop(object droppedData, object newParentData, object oldParentData, int position, TreeViewControl treeViewControl) { IPipingCalculationItem pipingCalculationItem = GetAsIPipingCalculationItem(droppedData); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rc96f5829ddb898717ba2e98091a2219308f05d3e -r82ca29d1fd75e1bf0c3ff8190a8ad3a43e1d16d6 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision c96f5829ddb898717ba2e98091a2219308f05d3e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision 82ca29d1fd75e1bf0c3ff8190a8ad3a43e1d16d6) @@ -30,6 +30,12 @@ private PipingGuiPlugin plugin; private TreeNodeInfo info; + private const int contextMenuAddCalculationGroupIndex = 0; + private const int contextMenuAddCalculationIndex = 1; + private const int contextMenuValidateAllIndex = 3; + private const int contextMenuCalculateAllIndex = 4; + private const int contextMenuClearOutputIndex = 5; + [SetUp] public void SetUp() { @@ -1000,8 +1006,7 @@ public void CanDrag_ParentIsPipingFailureMechanism_ReturnFalse() { // Setup - var pipingFailureMechanism = new PipingFailureMechanism(); - var group = pipingFailureMechanism.CalculationsGroup; + var group = new PipingCalculationGroup(); var pipingFailureMechanismMock = mocks.StrictMock(); mocks.ReplayAll(); @@ -1011,15 +1016,15 @@ pipingFailureMechanismMock); // Call - var canDrag = info.CanDrag(groupContext, pipingFailureMechanism); + var canDrag = info.CanDrag(groupContext, pipingFailureMechanismMock); // Assert Assert.IsFalse(canDrag); } [Test] [Combinatorial] - public void CanDropOrCanInsert_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnMoveOrTrue( + public void CanDropOrCanInsert_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnTrue( [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) { @@ -1063,7 +1068,7 @@ [Test] [Combinatorial] - public void CanDropOrInsert_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnNoneOrFalse( + public void CanDropOrInsert_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnFalse( [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) { @@ -1107,387 +1112,170 @@ mocks.VerifyAll(); } + [Test] + [Combinatorial] + public void OnDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( + [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) + { + // Setup + var treeViewControlMock = mocks.StrictMock(); + var pipingFailureMechanismMock = mocks.StrictMock(); + IPipingCalculationItem draggedItem; + object draggedItemContext; + CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock); -// [Test] -// [Combinatorial] -// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( -// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) -// { -// // Setup -// IPipingCalculationItem draggedItem; -// object draggedItemContext; -// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); -// -// PipingCalculationGroup originalOwnerGroup; -// PipingCalculationGroupContext originalOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); -// originalOwnerGroup.Children.Add(draggedItem); -// -// PipingCalculationGroup newOwnerGroup; -// PipingCalculationGroupContext newOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); -// -// var originalOwnerObserver = mocks.StrictMock(); -// originalOwnerObserver.Expect(o => o.UpdateObserver()); -// -// var updatewasCalled = false; -// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updatewasCalled = true); -// -// var newOwnerGroupContextNode = new TreeNode -// { -// Tag = newOwnerGroupContext -// }; -// -// var originalOwnerGroupContextNode = new TreeNode -// { -// Tag = originalOwnerGroupContext -// }; -// -// var draggedItemContextNode = new TreeNode -// { -// Tag = draggedItemContext -// }; -// draggedItemContextNode.Collapse(); -// -// newOwnerGroupContextNode.Nodes.Add(draggedItemContextNode); -// -// mocks.ReplayAll(); -// -// var treeView = new Core.Common.Controls.TreeView.TreeView(); -// var root = new TreeNode(); -// treeView.Nodes.Add(root); -// root.Nodes.Add(originalOwnerGroupContextNode); -// root.Nodes.Add(newOwnerGroupContextNode); -// -// originalOwnerGroup.Attach(originalOwnerObserver); -// newOwnerGroup.Attach(newOwnerObserver); -// -// // Precondition: -// Assert.IsFalse(draggedItemContextNode.IsExpanded); -// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); -// -// // Call -// info.OnDrop(draggedItemContextNode, newOwnerGroupContextNode, newOwnerGroup.Children.Count); -// -// // Assert -// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); -// Assert.AreSame(draggedItem, newOwnerGroup.Children.Last(), -// "Dragging node at the end of the target PipingCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); -// -// Assert.AreSame(draggedItemContextNode, draggedItemContextNode.TreeView.SelectedNode); -// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); -// Assert.IsFalse(draggedItemContextNode.IsExpanded); -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [Combinatorial] -// public void OnDragDrop_InsertingPipingCalculationItemContextAtDifferentLocationWithingSameGroup_ChangeItemIndexOfCalculationItem( -// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType, -// [Values(0, 2)] int newIndex) -// { -// // Setup -// const string name = "Very cool name"; -// IPipingCalculationItem draggedItem; -// object draggedItemContext; -// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, name); -// -// var existingItemStub = mocks.Stub(); -// existingItemStub.Stub(i => i.Name).Return(""); -// -// PipingCalculationGroup originalOwnerGroup; -// PipingCalculationGroupContext originalOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); -// originalOwnerGroup.Children.Add(existingItemStub); -// originalOwnerGroup.Children.Add(draggedItem); -// originalOwnerGroup.Children.Add(existingItemStub); -// -// bool updatewasCalled = false; -// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updatewasCalled = true); -// -// var existingItemStub1 = CreateStubTreeNode(); -// var existingItemStub2 = CreateStubTreeNode(); -// -// var preUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); -// var postUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); -// TreeNode[] preUpdateNewOwnerChildNodes = { existingItemStub1, preUpdateDraggedItemContextNode, existingItemStub2 }; -// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(originalOwnerGroupContext, preUpdateNewOwnerChildNodes, invocation => -// { -// if (updatewasCalled) -// { -// invocation.ReturnValue = new[] -// { -// existingItemStub1, -// postUpdateDraggedItemContextNode, -// existingItemStub2 -// }; -// } -// }); -// postUpdateDraggedItemContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); -// -// mocks.ReplayAll(); -// -// originalOwnerGroup.Attach(originalOwnerObserver); -// -// // Precondition: -// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); -// -// // Call -// info.OnDrop(preUpdateDraggedItemContextNode, newOwnerGroupContextNode, newIndex); -// -// // Assert -// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); -// Assert.AreNotSame(draggedItem, originalOwnerGroup.Children[1], -// "Should have removed 'draggedItem' from its original location in the collection."); -// Assert.AreSame(draggedItem, originalOwnerGroup.Children[newIndex], -// "Dragging node to specific location within owning PipingCalculationGroup should put the dragged data at that index."); -// Assert.AreEqual(name, draggedItem.Name, -// "No renaming should occur when dragging within the same PipingCalculationGroup."); -// -// Assert.AreSame(postUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode.TreeView.SelectedNode); -// -// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [Combinatorial] -// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupStartWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( -// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) -// { -// // Setup -// IPipingCalculationItem draggedItem; -// object draggedItemContext; -// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); -// -// PipingCalculationGroup originalOwnerGroup; -// PipingCalculationGroupContext originalOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); -// originalOwnerGroup.Children.Add(draggedItem); -// -// PipingCalculationGroup newOwnerGroup; -// PipingCalculationGroupContext newOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); -// -// var sameNamedItem = mocks.Stub(); -// sameNamedItem.Stub(i => i.Name).Return(draggedItem.Name); -// -// var updateWasCalled = false; -// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(); -// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(invocation => updateWasCalled = true); -// -// var preUpdateCalculationContextNode = CreateExpandedNodeStub(draggedItemContext, new TreeNode[0]); -// var postUpdateCalculationContextNode = CreateNodeStubToBeExpanded(draggedItemContext, new TreeNode[0]); -// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(originalOwnerGroupContext, new TreeNode[0], invocation => -// { -// if (updateWasCalled) -// { -// invocation.ReturnValue = new[] -// { -// postUpdateCalculationContextNode -// }; -// } -// }); -// postUpdateCalculationContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); -// -// mocks.ReplayAll(); -// -// newOwnerGroup.Children.Add(sameNamedItem); -// -// originalOwnerGroup.Attach(originalOwnerObserver); -// newOwnerGroup.Attach(newOwnerObserver); -// -// // Precondition: -// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); -// CollectionAssert.Contains(newOwnerGroup.Children.Select(c => c.Name), draggedItem.Name, -// "Name of the dragged item should already exist in new owner."); -// -// // Call -// info.OnDrop(preUpdateCalculationContextNode, newOwnerGroupContextNode, 0); -// -// // Assert -// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); -// Assert.AreSame(draggedItem, newOwnerGroup.Children.First(), -// "Dragging to insert node at start of newOwnerGroup should place the node at the start of the list."); -// switch (draggedItemType) -// { -// case PipingCalculationItemType.Calculation: -// Assert.AreEqual("Nieuwe berekening (1)", draggedItem.Name); -// break; -// case PipingCalculationItemType.Group: -// Assert.AreEqual("Nieuwe map (1)", draggedItem.Name); -// break; -// } -// -// Assert.AreSame(postUpdateCalculationContextNode, postUpdateCalculationContextNode.TreeView.SelectedNode); -// -// Assert.IsTrue(postUpdateCalculationContextNode.IsExpanded); -// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); -// -// mocks.VerifyAll(); -// } -// -// [Test] -// [Combinatorial] -// public void OnDragDrop_DraggingPipingCalculationItemContextOntoGroupWithOtherItems_ExpandedCollapsedStateOfOtherItemsRestored( -// [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) -// { -// // Setup -// IPipingCalculationItem draggedItem; -// object draggedItemContext; -// CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext); -// -// PipingCalculationGroup originalOwnerGroup; -// PipingCalculationGroupContext originalOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext); -// originalOwnerGroup.Children.Add(draggedItem); -// -// PipingCalculationGroup newOwnerGroup; -// PipingCalculationGroupContext newOwnerGroupContext; -// CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext); -// -// var updatewasCalled = false; -// var originalOwnerObserver = CreateObserverStubWithUpdateExpectancy(); -// var newOwnerObserver = CreateObserverStubWithUpdateExpectancy(methodInvocation => updatewasCalled = true); -// -// var nodeStub = CreateStubTreeNode(); -// TreeNode[] childNodesStub = { nodeStub }; -// -// var expandedNodeData = new object(); -// var preUpdateExpandedNode = CreateExpandedNodeStub(expandedNodeData, childNodesStub); -// var postUpdateExpandedNode = CreateNodeStubToBeExpanded(expandedNodeData, childNodesStub); -// -// var collapsedNodeData = new object(); -// var preUpdateCollapsedNode = CreateCollapsedNodeStub(collapsedNodeData, childNodesStub); -// var postUpdateCollapsedNode = CreateNodeStubToBeCollapsed(collapsedNodeData, childNodesStub); -// -// TreeNode[] preUpdateChildNodes = { preUpdateExpandedNode, preUpdateCollapsedNode }; -// TreeNode[] postUpdateChildNodes = { postUpdateExpandedNode, postUpdateCollapsedNode }; -// var newOwnerGroupContextNode = CreateNodeStubToBeExpanded(newOwnerGroupContext, preUpdateChildNodes, invocation => -// { -// if (updatewasCalled) -// { -// invocation.ReturnValue = postUpdateChildNodes; -// } -// }); -// -// var preUpdateDraggedItemContextNode = CreateTreeNodeLeafForData(draggedItemContext); -// var postUpdateDraggedItemContextNode = CreateNodeStubToBeCollapsed(draggedItemContext, new TreeNode[0]); -// postUpdateDraggedItemContextNode.Expect(n => n.Parent).Return(newOwnerGroupContextNode); -// -// mocks.ReplayAll(); -// -// originalOwnerGroup.Attach(originalOwnerObserver); -// newOwnerGroup.Attach(newOwnerObserver); -// -// // Precondition: -// CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); -// -// // Call -// info.OnDrop(preUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode, newOwnerGroup.Children.Count); -// -// // Assert -// CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); -// CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); -// Assert.AreSame(draggedItem, newOwnerGroup.Children.Last(), -// "Dragging node at the end of the target PipingCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); -// -// Assert.AreSame(postUpdateDraggedItemContextNode, postUpdateDraggedItemContextNode.TreeView.SelectedNode); -// Assert.IsFalse(postUpdateCollapsedNode.IsExpanded); -// Assert.IsFalse(postUpdateDraggedItemContextNode.IsExpanded); -// Assert.IsTrue(postUpdateExpandedNode.IsExpanded); -// Assert.IsTrue(newOwnerGroupContextNode.IsExpanded); -// -// mocks.VerifyAll(); -// } + PipingCalculationGroup originalOwnerGroup; + PipingCalculationGroupContext originalOwnerGroupContext; + CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock); + originalOwnerGroup.Children.Add(draggedItem); - private const int contextMenuAddCalculationGroupIndex = 0; - private const int contextMenuAddCalculationIndex = 1; - private const int contextMenuValidateAllIndex = 3; - private const int contextMenuCalculateAllIndex = 4; - private const int contextMenuClearOutputIndex = 5; + PipingCalculationGroup newOwnerGroup; + PipingCalculationGroupContext newOwnerGroupContext; + CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock); - /// - /// Creates a stub that is in the expanded state. - /// - /// The data corresponding with the created node. - /// The child nodes. - private TreeNode CreateExpandedNodeStub(object nodeData, TreeNode[] childNodes) - { - var preUpdateExpandedNode = mocks.Stub(); - preUpdateExpandedNode.Tag = nodeData; - preUpdateExpandedNode.Expect(n => n.IsExpanded).Return(true); - preUpdateExpandedNode.Nodes.AddRange(childNodes); - return preUpdateExpandedNode; - } + var originalOwnerObserver = mocks.StrictMock(); + originalOwnerObserver.Expect(o => o.UpdateObserver()); - /// - /// Creates an stub that is expected to be expanded. - /// - /// The data corresponding with the created node. - /// The child nodes. - /// Optional: action to be called when is being retrieved. - private TreeNode CreateNodeStubToBeExpanded(object nodeData, TreeNode[] childNodes, Action whenNodesCalledAction = null) - { - var postUpdateExpandedNode = new TreeNode(); - postUpdateExpandedNode.Tag = nodeData; - postUpdateExpandedNode.Collapse(); - postUpdateExpandedNode.Nodes.AddRange(childNodes); - return postUpdateExpandedNode; - } + var newOwnerObserver = mocks.StrictMock(); + newOwnerObserver.Expect(o => o.UpdateObserver()); - /// - /// Creates a stub that is in the collapsed state. - /// - /// The data corresponding with the created node. - /// The child nodes. - private TreeNode CreateCollapsedNodeStub(object nodeData, TreeNode[] childNodes) - { - var collapsedNode = new TreeNode(); - collapsedNode.Tag = nodeData; - collapsedNode.Collapse(); - collapsedNode.Nodes.AddRange(childNodes); - return collapsedNode; + mocks.ReplayAll(); + + originalOwnerGroup.Attach(originalOwnerObserver); + newOwnerGroup.Attach(newOwnerObserver); + + // Precondition + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); + + // Call + info.OnDrop(draggedItemContext, newOwnerGroupContext, originalOwnerGroupContext, 0, treeViewControlMock); + + // Assert + CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); + CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); + Assert.AreSame(draggedItem, newOwnerGroup.Children.Last(), + "Dragging node at the end of the target PipingCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); + + mocks.VerifyAll(); } - /// - /// Creates an stub that is expected to be collapsed. - /// - /// The data corresponding with the created node. - /// The child nodes. - private TreeNode CreateNodeStubToBeCollapsed(object nodeData, TreeNode[] childNodes) + [Test] + [Combinatorial] + public void OnDrop_InsertingPipingCalculationItemContextAtDifferentLocationWithinSameGroup_ChangeItemIndexOfCalculationItem( + [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType, + [Values(0, 2)] int newIndex) { - var nodeToBeCollapsed = new TreeNode(); - nodeToBeCollapsed.Tag = nodeData; - nodeToBeCollapsed.Nodes.AddRange(childNodes); - return nodeToBeCollapsed; + // Setup + var treeViewControlMock = mocks.StrictMock(); + var pipingFailureMechanismMock = mocks.StrictMock(); + + const string name = "Very cool name"; + IPipingCalculationItem draggedItem; + object draggedItemContext; + CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, name); + + var existingItemStub = mocks.Stub(); + existingItemStub.Stub(i => i.Name).Return(""); + + PipingCalculationGroup originalOwnerGroup; + PipingCalculationGroupContext originalOwnerGroupContext; + CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock); + originalOwnerGroup.Children.Add(existingItemStub); + originalOwnerGroup.Children.Add(draggedItem); + originalOwnerGroup.Children.Add(existingItemStub); + + var originalOwnerObserver = mocks.StrictMock(); + originalOwnerObserver.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + originalOwnerGroup.Attach(originalOwnerObserver); + + // Precondition + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + + // Call + info.OnDrop(draggedItemContext, originalOwnerGroupContext, originalOwnerGroupContext, newIndex, treeViewControlMock); + + // Assert + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + Assert.AreNotSame(draggedItem, originalOwnerGroup.Children[1], + "Should have removed 'draggedItem' from its original location in the collection."); + Assert.AreSame(draggedItem, originalOwnerGroup.Children[newIndex], + "Dragging node to specific location within owning PipingCalculationGroup should put the dragged data at that index."); + Assert.AreEqual(name, draggedItem.Name, + "No renaming should occur when dragging within the same PipingCalculationGroup."); + + mocks.VerifyAll(); } - /// - /// Creates an stub that expects its - /// method will be called once. - /// - /// Optional: Action to be performed when - /// is being called. - private IObserver CreateObserverStubWithUpdateExpectancy(Action whenCalledAction = null) + [Test] + [Combinatorial] + public void OnDrop_DraggingPipingCalculationItemContextOntoGroupWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( + [Values(PipingCalculationItemType.Calculation, PipingCalculationItemType.Group)] PipingCalculationItemType draggedItemType) { + // Setup + var treeViewControlMock = mocks.StrictMock(); + var pipingFailureMechanismMock = mocks.StrictMock(); + + IPipingCalculationItem draggedItem; + object draggedItemContext; + CreatePipingCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock); + + PipingCalculationGroup originalOwnerGroup; + PipingCalculationGroupContext originalOwnerGroupContext; + CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock); + originalOwnerGroup.Children.Add(draggedItem); + + PipingCalculationGroup newOwnerGroup; + PipingCalculationGroupContext newOwnerGroupContext; + CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock); + + var sameNamedItem = mocks.Stub(); + sameNamedItem.Stub(i => i.Name).Return(draggedItem.Name); + + var originalOwnerObserver = mocks.StrictMock(); + originalOwnerObserver.Expect(o => o.UpdateObserver()); + var newOwnerObserver = mocks.StrictMock(); - newOwnerObserver.Expect(o => o.UpdateObserver()).WhenCalled(invocation => + newOwnerObserver.Expect(o => o.UpdateObserver()); + + treeViewControlMock.Expect(tvc => tvc.TryRenameNodeForData(draggedItemContext)); + + mocks.ReplayAll(); + + newOwnerGroup.Children.Add(sameNamedItem); + + originalOwnerGroup.Attach(originalOwnerObserver); + newOwnerGroup.Attach(newOwnerObserver); + + // Precondition + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); + CollectionAssert.Contains(newOwnerGroup.Children.Select(c => c.Name), draggedItem.Name, + "Name of the dragged item should already exist in new owner."); + + // Call + info.OnDrop(draggedItemContext, newOwnerGroupContext, originalOwnerGroupContext, 0, treeViewControlMock); + + // Assert + CollectionAssert.DoesNotContain(originalOwnerGroup.Children, draggedItem); + CollectionAssert.Contains(newOwnerGroup.Children, draggedItem); + Assert.AreSame(draggedItem, newOwnerGroup.Children.First(), + "Dragging to insert node at start of newOwnerGroup should place the node at the start of the list."); + switch (draggedItemType) { - if (whenCalledAction != null) - { - whenCalledAction(invocation); - } - }); - return newOwnerObserver; + case PipingCalculationItemType.Calculation: + Assert.AreEqual("Nieuwe berekening (1)", draggedItem.Name); + break; + case PipingCalculationItemType.Group: + Assert.AreEqual("Nieuwe map (1)", draggedItem.Name); + break; + } + + mocks.VerifyAll(); } /// @@ -1550,26 +1338,6 @@ } /// - /// Use to creates a stub tree node as a simple node-tree leaf. - /// - private TreeNode CreateStubTreeNode() - { - return CreateTreeNodeLeafForData(new object()); - } - - /// - /// Creates an stub that represents a tree-node leaf. - /// - /// The data associated with the node. - private TreeNode CreateTreeNodeLeafForData(object nodeData) - { - var preUpdateDraggedItemContextNode = mocks.Stub(); - preUpdateDraggedItemContextNode.Tag = nodeData; - preUpdateDraggedItemContextNode.Stub(n => n.IsExpanded).Return(false); - return preUpdateDraggedItemContextNode; - } - - /// /// Type indicator for testing methods on . /// public enum DragDropTestMethod