Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs =================================================================== diff -u -r40384a737099f1ed7e6665d88165782d40951d6d -rab5256dd19a9824ee179ecce6d8561d1ab83e6e9 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision 40384a737099f1ed7e6665d88165782d40951d6d) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision ab5256dd19a9824ee179ecce6d8561d1ab83e6e9) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Linq; using Core.Common.Base; using Core.Common.Controls.TreeView; using Core.Common.TestUtil; @@ -319,6 +320,181 @@ mocks.VerifyAll(); } + [Test] + [Combinatorial] + public void OnDropOfCalculationGroupContextTreeNodeInfo_DraggingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( + [Values(CalculationItemType.Calculation, CalculationItemType.Group)] CalculationItemType draggedItemType) + { + // Setup + var mocks = new MockRepository(); + var treeViewControlMock = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + var originalOwnerObserver = mocks.StrictMock(); + var newOwnerObserver = mocks.StrictMock(); + + originalOwnerObserver.Expect(o => o.UpdateObserver()); + newOwnerObserver.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + ICalculationBase draggedItem; + object draggedItemContext; + CreateCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanismMock); + + CalculationGroup originalOwnerGroup; + TestCalculationGroupContext originalOwnerGroupContext; + CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, failureMechanismMock); + originalOwnerGroup.Children.Add(draggedItem); + + CalculationGroup newOwnerGroup; + TestCalculationGroupContext newOwnerGroupContext; + CreateCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, failureMechanismMock); + + originalOwnerGroup.Attach(originalOwnerObserver); + newOwnerGroup.Attach(newOwnerObserver); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Precondition + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + CollectionAssert.DoesNotContain(newOwnerGroup.Children, draggedItem); + + // Call + treeNodeInfo.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 TestCalculationGroup should put the dragged data at the end of 'newOwnerGroup'."); + + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] + public void OnDropOfCalculationGroupContextTreeNodeInfo_InsertingCalculationItemContextAtDifferentLocationWithinSameGroup_ChangeItemIndexOfCalculationItem( + [Values(CalculationItemType.Calculation, CalculationItemType.Group)] CalculationItemType draggedItemType, + [Values(0, 2)] int newIndex) + { + // Setup + var mocks = new MockRepository(); + var treeViewControlMock = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + var existingItemStub = mocks.Stub(); + var originalOwnerObserver = mocks.StrictMock(); + + existingItemStub.Stub(ci => ci.Name).Return(""); + originalOwnerObserver.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + const string name = "Very cool name"; + + object draggedItemContext; + ICalculationBase draggedItem; + CreateCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanismMock, name); + + CalculationGroup originalOwnerGroup; + TestCalculationGroupContext originalOwnerGroupContext; + CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, failureMechanismMock); + + originalOwnerGroup.Children.Add(existingItemStub); + originalOwnerGroup.Children.Add(draggedItem); + originalOwnerGroup.Children.Add(existingItemStub); + + originalOwnerGroup.Attach(originalOwnerObserver); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Precondition + CollectionAssert.Contains(originalOwnerGroup.Children, draggedItem); + + // Call + treeNodeInfo.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 TestCalculationGroup should put the dragged data at that index."); + Assert.AreEqual(name, draggedItem.Name, + "No renaming should occur when dragging within the same TestCalculationGroup."); + + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] + public void OnDropOfCalculationGroupContextTreeNodeInfo_DraggingCalculationItemContextOntoGroupWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( + [Values(CalculationItemType.Calculation, CalculationItemType.Group)] CalculationItemType draggedItemType) + { + // Setup + var mocks = new MockRepository(); + var treeViewControlMock = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + + ICalculationBase draggedItem; + object draggedItemContext; + CreateCalculationItemAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanismMock); + + CalculationGroup originalOwnerGroup; + TestCalculationGroupContext originalOwnerGroupContext; + CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, failureMechanismMock); + originalOwnerGroup.Children.Add(draggedItem); + + CalculationGroup newOwnerGroup; + TestCalculationGroupContext newOwnerGroupContext; + CreateCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, failureMechanismMock); + + var sameNamedItem = mocks.Stub(); + sameNamedItem.Stub(sni => sni.Name).Return(draggedItem.Name); + + var originalOwnerObserver = mocks.StrictMock(); + originalOwnerObserver.Expect(o => o.UpdateObserver()); + + var newOwnerObserver = mocks.StrictMock(); + newOwnerObserver.Expect(o => o.UpdateObserver()); + + treeViewControlMock.Expect(tvc => tvc.TryRenameNodeForData(draggedItemContext)); + + mocks.ReplayAll(); + + newOwnerGroup.Children.Add(sameNamedItem); + + originalOwnerGroup.Attach(originalOwnerObserver); + newOwnerGroup.Attach(newOwnerObserver); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // 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 + treeNodeInfo.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) + { + case CalculationItemType.Calculation: + Assert.AreEqual("Nieuwe berekening", draggedItem.Name); + break; + case CalculationItemType.Group: + Assert.AreEqual("Nieuwe map", draggedItem.Name); + break; + } + + mocks.VerifyAll(); + } + /// /// Creates an instance of and the corresponding . /// @@ -397,6 +573,11 @@ private class TestCalculation : Observable, ICalculation { + public TestCalculation() + { + Name = "Nieuwe berekening"; + } + public string Name { get; set; } public string Comments { get; set; } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rf0c2ddbf7c66e63f843811d2a8687f9679c4043b -rab5256dd19a9824ee179ecce6d8561d1ab83e6e9 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision f0c2ddbf7c66e63f843811d2a8687f9679c4043b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision ab5256dd19a9824ee179ecce6d8561d1ab83e6e9) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -479,248 +478,7 @@ mocks.VerifyAll(); } - [Test] - [Combinatorial] - public void OnDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( - [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - ICalculationBase draggedItem; - object draggedItemContext; - CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection); - - CalculationGroup originalOwnerGroup; - GrassCoverErosionInwardsCalculationGroupContext originalOwnerGroupContext; - CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - originalOwnerGroup.Children.Add(draggedItem); - - CalculationGroup newOwnerGroup; - GrassCoverErosionInwardsCalculationGroupContext newOwnerGroupContext; - CreateCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - - var originalOwnerObserver = mocks.StrictMock(); - originalOwnerObserver.Expect(o => o.UpdateObserver()); - - var newOwnerObserver = mocks.StrictMock(); - newOwnerObserver.Expect(o => o.UpdateObserver()); - - 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(); - } - - [Test] - [Combinatorial] - public void OnDrop_InsertingPipingCalculationItemContextAtDifferentLocationWithinSameGroup_ChangeItemIndexOfCalculationItem( - [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType, - [Values(0, 2)] int newIndex) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - const string name = "Very cool name"; - ICalculationBase draggedItem; - object draggedItemContext; - CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection, name); - - var existingItemStub = mocks.Stub(); - existingItemStub.Stub(ci => ci.Name).Return(""); - - CalculationGroup originalOwnerGroup; - GrassCoverErosionInwardsCalculationGroupContext originalOwnerGroupContext; - CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - 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(); - } - - [Test] - [Combinatorial] - public void OnDrop_DraggingPipingCalculationItemContextOntoGroupWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( - [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - ICalculationBase draggedItem; - object draggedItemContext; - CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection); - - CalculationGroup originalOwnerGroup; - GrassCoverErosionInwardsCalculationGroupContext originalOwnerGroupContext; - CreateCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - originalOwnerGroup.Children.Add(draggedItem); - - CalculationGroup newOwnerGroup; - GrassCoverErosionInwardsCalculationGroupContext newOwnerGroupContext; - CreateCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - - var sameNamedItem = mocks.Stub(); - sameNamedItem.Stub(sni => sni.Name).Return(draggedItem.Name); - - var originalOwnerObserver = mocks.StrictMock(); - originalOwnerObserver.Expect(o => o.UpdateObserver()); - - var newOwnerObserver = mocks.StrictMock(); - 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) - { - case CalculationType.Calculation: - Assert.AreEqual("Nieuwe berekening", draggedItem.Name); - break; - case CalculationType.Group: - Assert.AreEqual("Nieuwe map", draggedItem.Name); - break; - } - - mocks.VerifyAll(); - } - private const int contextMenuAddCalculationGroupIndex = 0; private const int contextMenuAddCalculationItemIndex = 1; - - /// - /// Creates an instance of and the corresponding - /// . - /// - /// The created group without any children. - /// The context object for , without any other data. - /// The grass cover erosion inwards failure mechanism the item and context belong to. - /// The assessment section the item and context belong to. - private void CreateCalculationGroupAndContext(out CalculationGroup data, out GrassCoverErosionInwardsCalculationGroupContext dataContext, GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) - { - data = new CalculationGroup(); - - dataContext = new GrassCoverErosionInwardsCalculationGroupContext(data, - failureMechanism, - assessmentSection); - } - - /// - /// Creates an instance of and the corresponding context. - /// - /// Defines the implementation of to be constructed. - /// Output: The concrete create class based on . - /// Output: The corresponding with . - /// The grass cover erosion inwards failure mechanism the item and context belong to. - /// The assessment section the item and context belong to. - /// Optional: The name of . - /// - private static void CreateCalculationAndContext(CalculationType type, out ICalculationBase data, out object dataContext, GrassCoverErosionInwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection, string initialName = null) - { - switch (type) - { - case CalculationType.Calculation: - var calculation = new GrassCoverErosionInwardsCalculation(failureMechanism.GeneralInput); - if (initialName != null) - { - calculation.Name = initialName; - } - data = calculation; - dataContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSection); - break; - case CalculationType.Group: - var group = new CalculationGroup(); - if (initialName != null) - { - group.Name = initialName; - } - data = group; - dataContext = new GrassCoverErosionInwardsCalculationGroupContext(group, - failureMechanism, - assessmentSection); - break; - default: - throw new NotSupportedException(); - } - } - - /// - /// Type indicator for implementations of to be created in a test. - /// - public enum CalculationType - { - /// - /// Indicates . - /// - Calculation, - - /// - /// Indicates . - /// - Group - } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rf0c2ddbf7c66e63f843811d2a8687f9679c4043b -rab5256dd19a9824ee179ecce6d8561d1ab83e6e9 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision f0c2ddbf7c66e63f843811d2a8687f9679c4043b) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision ab5256dd19a9824ee179ecce6d8561d1ab83e6e9) @@ -1355,175 +1355,6 @@ mocks.VerifyAll(); } - [Test] - [Combinatorial] - public void OnDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( - [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - ICalculationBase draggedItem; - object draggedItemContext; - CreatePipingCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection); - - CalculationGroup originalOwnerGroup; - PipingCalculationGroupContext originalOwnerGroupContext; - CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - originalOwnerGroup.Children.Add(draggedItem); - - CalculationGroup newOwnerGroup; - PipingCalculationGroupContext newOwnerGroupContext; - CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - - var originalOwnerObserver = mocks.StrictMock(); - originalOwnerObserver.Expect(o => o.UpdateObserver()); - - var newOwnerObserver = mocks.StrictMock(); - newOwnerObserver.Expect(o => o.UpdateObserver()); - - 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(); - } - - [Test] - [Combinatorial] - public void OnDrop_InsertingPipingCalculationItemContextAtDifferentLocationWithinSameGroup_ChangeItemIndexOfCalculationItem( - [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType, - [Values(0, 2)] int newIndex) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - const string name = "Very cool name"; - ICalculationBase draggedItem; - object draggedItemContext; - CreatePipingCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection, name); - - var existingItemStub = mocks.Stub(); - existingItemStub.Stub(ci => ci.Name).Return(""); - - CalculationGroup originalOwnerGroup; - PipingCalculationGroupContext originalOwnerGroupContext; - CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - 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(); - } - - [Test] - [Combinatorial] - public void OnDrop_DraggingPipingCalculationItemContextOntoGroupWithSameNamedItem_MoveCalculationItemInstanceToNewGroupAndRename( - [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType) - { - // Setup - var treeViewControlMock = mocks.StrictMock(); - var pipingFailureMechanismMock = mocks.StrictMock(); - var assessmentSection = mocks.StrictMock(); - - ICalculationBase draggedItem; - object draggedItemContext; - CreatePipingCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, pipingFailureMechanismMock, assessmentSection); - - CalculationGroup originalOwnerGroup; - PipingCalculationGroupContext originalOwnerGroupContext; - CreatePipingCalculationGroupAndContext(out originalOwnerGroup, out originalOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - originalOwnerGroup.Children.Add(draggedItem); - - CalculationGroup newOwnerGroup; - PipingCalculationGroupContext newOwnerGroupContext; - CreatePipingCalculationGroupAndContext(out newOwnerGroup, out newOwnerGroupContext, pipingFailureMechanismMock, assessmentSection); - - var sameNamedItem = mocks.Stub(); - sameNamedItem.Stub(sni => sni.Name).Return(draggedItem.Name); - - var originalOwnerObserver = mocks.StrictMock(); - originalOwnerObserver.Expect(o => o.UpdateObserver()); - - var newOwnerObserver = mocks.StrictMock(); - 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) - { - case PipingCalculationType.Calculation: - Assert.AreEqual("Nieuwe berekening", draggedItem.Name); - break; - case PipingCalculationType.Group: - Assert.AreEqual("Nieuwe map", draggedItem.Name); - break; - } - - mocks.VerifyAll(); - } - private const int contextMenuAddGenerateCalculationsIndex = 1; private const int contextMenuAddCalculationGroupIndex = 0; private const int contextMenuAddCalculationIndex = 1; @@ -1532,70 +1363,6 @@ private const int contextMenuClearOutputIndex = 5; /// - /// Creates an instance of and the corresponding - /// . - /// - /// The created group without any children. - /// The context object for , without any other data. - /// The piping failure mechanism the item and context belong to. - /// The assessment section the item and context belong to. - private void CreatePipingCalculationGroupAndContext(out CalculationGroup data, out PipingCalculationGroupContext dataContext, PipingFailureMechanism pipingFailureMechanism, IAssessmentSection assessmentSection) - { - data = new CalculationGroup(); - - dataContext = new PipingCalculationGroupContext(data, - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); - } - - /// - /// Creates an instance of and the corresponding context. - /// - /// Defines the implementation of to be constructed. - /// Output: The concrete create class based on . - /// Output: The corresponding with . - /// The piping failure mechanism the item and context belong to. - /// The assessment section the item and context belong to. - /// Optional: The name of . - /// - private static void CreatePipingCalculationAndContext(PipingCalculationType type, out ICalculationBase data, out object dataContext, PipingFailureMechanism pipingFailureMechanism, IAssessmentSection assessmentSection, string initialName = null) - { - switch (type) - { - case PipingCalculationType.Calculation: - var calculation = new PipingCalculationScenario(new GeneralPipingInput(), new NormProbabilityPipingInput()); - if (initialName != null) - { - calculation.Name = initialName; - } - data = calculation; - dataContext = new PipingCalculationScenarioContext(calculation, - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); - break; - case PipingCalculationType.Group: - var group = new CalculationGroup(); - if (initialName != null) - { - group.Name = initialName; - } - data = group; - dataContext = new PipingCalculationGroupContext(group, - Enumerable.Empty(), - Enumerable.Empty(), - pipingFailureMechanism, - assessmentSection); - break; - default: - throw new NotSupportedException(); - } - } - - /// /// Creates a new instance of with sections and a surface line. /// /// A new instance of . @@ -1640,21 +1407,5 @@ return failureMechanism; } - - /// - /// Type indicator for implementations of to be created in a test. - /// - public enum PipingCalculationType - { - /// - /// Indicates . - /// - Calculation, - - /// - /// Indicates . - /// - Group - } } } \ No newline at end of file