Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs =================================================================== diff -u -rd83bc80d11262310f469ccc3032ffc534af61789 -rf0c2ddbf7c66e63f843811d2a8687f9679c4043b --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision d83bc80d11262310f469ccc3032ffc534af61789) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision f0c2ddbf7c66e63f843811d2a8687f9679c4043b) @@ -19,7 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base; +using Core.Common.Controls.TreeView; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; @@ -87,7 +89,7 @@ } [Test] - public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnTrue() + public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnsTrue() { // Setup var mocks = new MockRepository(); @@ -108,7 +110,7 @@ } [Test] - public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnFalse() + public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnsFalse() { // Setup var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); @@ -149,7 +151,7 @@ } [Test] - public void CanRemoveOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnTrue() + public void CanRemoveOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnsTrue() { // Setup var mocks = new MockRepository(); @@ -169,7 +171,7 @@ } [Test] - public void CanRemoveOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnFalse() + public void CanRemoveOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnsFalse() { // Setup var mocks = new MockRepository(); @@ -188,7 +190,7 @@ } [Test] - public void CanDragOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnTrue() + public void CanDragOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnsTrue() { // Setup var mocks = new MockRepository(); @@ -208,7 +210,7 @@ } [Test] - public void CanDragOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnFalse() + public void CanDragOfCalculationGroupContextTreeNodeInfo_WithoutParentNodeDefaultBehavior_ReturnsFalse() { // Setup var mocks = new MockRepository(); @@ -226,6 +228,97 @@ Assert.IsFalse(canDrag); } + [Test] + [Combinatorial] + public void CanDropOrCanInsertOfCalculationGroupContextTreeNodeInfo_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnsTrue( + [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, + [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) + { + // Setup + var mocks = new MockRepository(); + var failureMechanism = mocks.StrictMock(); + + mocks.ReplayAll(); + + object draggedItemContext; + ICalculationBase draggedItem; + CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanism); + + CalculationGroup targetGroup; + TestCalculationGroupContext targetGroupContext; + CreateCalculationGroupAndContext(out targetGroup, out targetGroupContext, failureMechanism); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + switch (methodToTest) + { + case DragDropTestMethod.CanDrop: + // Call + var canDrop = treeNodeInfo.CanDrop(draggedItemContext, targetGroupContext); + + // Assert + Assert.IsTrue(canDrop); + break; + case DragDropTestMethod.CanInsert: + // Call + bool canInsert = treeNodeInfo.CanInsert(draggedItemContext, targetGroupContext); + + // Assert + Assert.IsTrue(canInsert); + break; + default: + Assert.Fail(methodToTest + " not supported."); + break; + } + mocks.VerifyAll(); + } + + [Test] + [Combinatorial] + public void CanDropOrInsertOfCalculationGroupContextTreeNodeInfo_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnsFalse( + [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, + [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) + { + // Setup + var mocks = new MockRepository(); + var sourceFailureMechanism = mocks.StrictMock(); + var targetFailureMechanism = mocks.StrictMock(); + + mocks.ReplayAll(); + + object draggedItemContext; + ICalculationBase draggedItem; + CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, targetFailureMechanism); + + CalculationGroup targetGroup; + TestCalculationGroupContext targetGroupContext; + CreateCalculationGroupAndContext(out targetGroup, out targetGroupContext, sourceFailureMechanism); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + switch (methodToTest) + { + case DragDropTestMethod.CanDrop: + // Call + var canDrop = treeNodeInfo.CanDrop(draggedItemContext, targetGroupContext); + + // Assert + Assert.IsFalse(canDrop); + break; + case DragDropTestMethod.CanInsert: + // Call + bool canInsert = treeNodeInfo.CanInsert(draggedItemContext, targetGroupContext); + + // Assert + Assert.IsFalse(canInsert); + break; + default: + Assert.Fail(methodToTest + " not supported."); + break; + } + mocks.VerifyAll(); + } + private class TestCalculationGroupContext : Observable, ICalculationContext { public TestCalculationGroupContext(CalculationGroup wrappedData, IFailureMechanism failureMechanism) @@ -238,5 +331,128 @@ public IFailureMechanism FailureMechanism { get; private set; } } + + private class TestCalculationContext : Observable, ICalculationContext + { + public TestCalculationContext(TestCalculation wrappedData, IFailureMechanism failureMechanism) + { + WrappedData = wrappedData; + FailureMechanism = failureMechanism; + } + + public TestCalculation WrappedData { get; private set; } + + public IFailureMechanism FailureMechanism { get; private set; } + } + + private class TestCalculation : Observable, ICalculation + { + public string Name { get; set; } + + public string Comments { get; set; } + + public bool HasOutput + { + get + { + return false; + } + } + + public void ClearOutput() + { + + } + + public void ClearHydraulicBoundaryLocation() + { + + } + + public ICalculationInput GetObservableInput() + { + return null; + } + } + + /// + /// Creates an instance of and the corresponding . + /// + /// The created group without any children. + /// The context object for , without any other data. + /// The failure mechanism the item and context it belong to. + private void CreateCalculationGroupAndContext(out CalculationGroup data, out TestCalculationGroupContext dataContext, IFailureMechanism failureMechanism) + { + data = new CalculationGroup(); + dataContext = new TestCalculationGroupContext(data, failureMechanism); + } + + /// + /// Creates an instance of and the corresponding context. + /// + /// Defines the implementation of to be constructed. + /// Output: The concrete create class based on . + /// Output: The context corresponding with . + /// The failure mechanism the item and context belong to. + /// Optional: The name of . + /// + private static void CreateCalculationAndContext(CalculationType type, out ICalculationBase data, out object dataContext, IFailureMechanism failureMechanism, string initialName = null) + { + switch (type) + { + case CalculationType.Calculation: + var calculation = new TestCalculation(); + if (initialName != null) + { + calculation.Name = initialName; + } + data = calculation; + dataContext = new TestCalculationContext(calculation, failureMechanism); + break; + case CalculationType.Group: + var group = new CalculationGroup(); + if (initialName != null) + { + group.Name = initialName; + } + data = group; + dataContext = new TestCalculationGroupContext(group, failureMechanism); + break; + default: + throw new NotSupportedException(); + } + } + + /// + /// Type indicator for testing methods on . + /// + public enum DragDropTestMethod + { + /// + /// Indicates . + /// + CanDrop, + + /// + /// Indicates . + /// + CanInsert + } + + /// + /// 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/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rd83bc80d11262310f469ccc3032ffc534af61789 -rf0c2ddbf7c66e63f843811d2a8687f9679c4043b --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision d83bc80d11262310f469ccc3032ffc534af61789) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision f0c2ddbf7c66e63f843811d2a8687f9679c4043b) @@ -481,102 +481,6 @@ [Test] [Combinatorial] - public void CanDropOrCanInsert_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnTrue( - [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, - [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) - { - // Setup - ICalculationBase draggedItem; - object draggedItemContext; - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.StrictMock(); - - mocks.ReplayAll(); - - CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanism, assessmentSection); - - CalculationGroup targetGroup; - GrassCoverErosionInwardsCalculationGroupContext targetGroupContext; - CreateCalculationGroupAndContext(out targetGroup, out targetGroupContext, failureMechanism, assessmentSection); - - failureMechanism.CalculationsGroup.Children.Add(draggedItem); - failureMechanism.CalculationsGroup.Children.Add(targetGroup); - - switch (methodToTest) - { - case DragDropTestMethod.CanDrop: - // Call - var canDrop = info.CanDrop(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsTrue(canDrop); - break; - case DragDropTestMethod.CanInsert: - // Call - bool canInsert = info.CanInsert(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsTrue(canInsert); - break; - default: - Assert.Fail(methodToTest + " not supported."); - break; - } - mocks.VerifyAll(); - } - - [Test] - [Combinatorial] - public void CanDropOrInsert_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnFalse( - [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, - [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) - { - // Setup - ICalculationBase draggedItem; - object draggedItemContext; - - var targetFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - var assessmentSection = mocks.StrictMock(); - - mocks.ReplayAll(); - - CreateCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, targetFailureMechanism, assessmentSection); - - var sourceFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - sourceFailureMechanism.CalculationsGroup.Children.Add(draggedItem); - - CalculationGroup targetGroup; - GrassCoverErosionInwardsCalculationGroupContext targetGroupContext; - CreateCalculationGroupAndContext(out targetGroup, out targetGroupContext, sourceFailureMechanism, assessmentSection); - - targetFailureMechanism.CalculationsGroup.Children.Add(targetGroup); - - switch (methodToTest) - { - case DragDropTestMethod.CanDrop: - // Call - var canDrop = info.CanDrop(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsFalse(canDrop); - break; - case DragDropTestMethod.CanInsert: - // Call - bool canInsert = info.CanInsert(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsFalse(canInsert); - break; - default: - Assert.Fail(methodToTest + " not supported."); - break; - } - mocks.VerifyAll(); - } - - [Test] - [Combinatorial] public void OnDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( [Values(CalculationType.Calculation, CalculationType.Group)] CalculationType draggedItemType) { @@ -804,22 +708,6 @@ } /// - /// Type indicator for testing methods on . - /// - public enum DragDropTestMethod - { - /// - /// Indicates . - /// - CanDrop, - - /// - /// Indicates . - /// - CanInsert - } - - /// /// Type indicator for implementations of to be created in a test. /// public enum CalculationType Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rd83bc80d11262310f469ccc3032ffc534af61789 -rf0c2ddbf7c66e63f843811d2a8687f9679c4043b --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision d83bc80d11262310f469ccc3032ffc534af61789) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TreeNodeInfos/PipingCalculationGroupContextTreeNodeInfoTest.cs (.../PipingCalculationGroupContextTreeNodeInfoTest.cs) (revision f0c2ddbf7c66e63f843811d2a8687f9679c4043b) @@ -610,7 +610,6 @@ var group = new CalculationGroup(); var parentGroup = new CalculationGroup(); - var parentData = new PipingFailureMechanism(); var pipingFailureMechanismMock = mocks.StrictMock(); var assessmentSectionMock = mocks.StrictMock(); var nodeData = new PipingCalculationGroupContext(group, @@ -1358,102 +1357,6 @@ [Test] [Combinatorial] - public void CanDropOrCanInsert_DraggingPipingCalculationItemContextOntoGroupNotContainingItem_ReturnTrue( - [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, - [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType) - { - // Setup - ICalculationBase draggedItem; - object draggedItemContext; - - var failureMechanism = new PipingFailureMechanism(); - var assessmentSection = mocks.StrictMock(); - - mocks.ReplayAll(); - - CreatePipingCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, failureMechanism, assessmentSection); - - CalculationGroup targetGroup; - PipingCalculationGroupContext targetGroupContext; - CreatePipingCalculationGroupAndContext(out targetGroup, out targetGroupContext, failureMechanism, assessmentSection); - - failureMechanism.CalculationsGroup.Children.Add(draggedItem); - failureMechanism.CalculationsGroup.Children.Add(targetGroup); - - switch (methodToTest) - { - case DragDropTestMethod.CanDrop: - // Call - var canDrop = info.CanDrop(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsTrue(canDrop); - break; - case DragDropTestMethod.CanInsert: - // Call - bool canInsert = info.CanInsert(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsTrue(canInsert); - break; - default: - Assert.Fail(methodToTest + " not supported."); - break; - } - mocks.VerifyAll(); - } - - [Test] - [Combinatorial] - public void CanDropOrInsert_DraggingCalculationItemContextOntoGroupNotContainingItemOtherFailureMechanism_ReturnFalse( - [Values(DragDropTestMethod.CanDrop, DragDropTestMethod.CanInsert)] DragDropTestMethod methodToTest, - [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType) - { - // Setup - ICalculationBase draggedItem; - object draggedItemContext; - - var targetFailureMechanism = new PipingFailureMechanism(); - var assessmentSection = mocks.StrictMock(); - - mocks.ReplayAll(); - - CreatePipingCalculationAndContext(draggedItemType, out draggedItem, out draggedItemContext, targetFailureMechanism, assessmentSection); - - var sourceFailureMechanism = new PipingFailureMechanism(); - sourceFailureMechanism.CalculationsGroup.Children.Add(draggedItem); - - CalculationGroup targetGroup; - PipingCalculationGroupContext targetGroupContext; - CreatePipingCalculationGroupAndContext(out targetGroup, out targetGroupContext, sourceFailureMechanism, assessmentSection); - - targetFailureMechanism.CalculationsGroup.Children.Add(targetGroup); - - switch (methodToTest) - { - case DragDropTestMethod.CanDrop: - // Call - var canDrop = info.CanDrop(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsFalse(canDrop); - break; - case DragDropTestMethod.CanInsert: - // Call - bool canInsert = info.CanInsert(draggedItemContext, targetGroupContext); - - // Assert - Assert.IsFalse(canInsert); - break; - default: - Assert.Fail(methodToTest + " not supported."); - break; - } - mocks.VerifyAll(); - } - - [Test] - [Combinatorial] public void OnDrop_DraggingPipingCalculationItemContextOntoGroupEnd_MoveCalculationItemInstanceToNewGroup( [Values(PipingCalculationType.Calculation, PipingCalculationType.Group)] PipingCalculationType draggedItemType) { @@ -1739,22 +1642,6 @@ } /// - /// Type indicator for testing methods on . - /// - public enum DragDropTestMethod - { - /// - /// Indicates . - /// - CanDrop, - - /// - /// Indicates . - /// - CanInsert - } - - /// /// Type indicator for implementations of to be created in a test. /// public enum PipingCalculationType