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