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