Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsTreeNodeInfoFactoryTest.cs =================================================================== diff -u -r3178e116f5e59e03078d465efeb303c5e232c7bf -r8b60c9e846480f3ffeeb263bfea5d3367bf6bee3 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsTreeNodeInfoFactoryTest.cs (.../RingtoetsTreeNodeInfoFactoryTest.cs) (revision 3178e116f5e59e03078d465efeb303c5e232c7bf) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsTreeNodeInfoFactoryTest.cs (.../RingtoetsTreeNodeInfoFactoryTest.cs) (revision 8b60c9e846480f3ffeeb263bfea5d3367bf6bee3) @@ -74,11 +74,12 @@ mocks.ReplayAll(); const string groupName = "testName"; - var group = new CalculationGroup - { - Name = groupName - }; - var groupContext = new TestCalculationGroupContext(group, failureMechanism); + var groupContext = new TestCalculationGroupContext(new CalculationGroup + { + Name = groupName + }, + new CalculationGroup(), + failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -107,13 +108,15 @@ { // Setup var mocks = new MockRepository(); - var calculationGroup = new TestCalculationGroupContext(new CalculationGroup(), mocks.Stub()); + var failureMechanism = mocks.Stub(); mocks.ReplayAll(); + var groupContext = new TestCalculationGroupContext(new CalculationGroup(), new CalculationGroup(), failureMechanism); + TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call - bool result = treeNodeInfo.EnsureVisibleOnCreate(null, calculationGroup); + bool result = treeNodeInfo.EnsureVisibleOnCreate(null, groupContext); // Assert Assert.IsTrue(result); @@ -138,11 +141,10 @@ { // Setup var mocks = new MockRepository(); - var calculationGroup = mocks.StrictMock(); var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var groupContext = new TestCalculationGroupContext(calculationGroup, failureMechanism); + var groupContext = new TestCalculationGroupContext(new CalculationGroup(), new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -178,7 +180,7 @@ const string newName = "new name"; var group = new CalculationGroup(); - var nodeData = new TestCalculationGroupContext(group, failureMechanism); + var nodeData = new TestCalculationGroupContext(group, new CalculationGroup(), failureMechanism); nodeData.Attach(observer); @@ -200,8 +202,9 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var nodeData = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); - var parentNodeData = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); + var parentGroup = new CalculationGroup(); + var nodeData = new TestCalculationGroupContext(new CalculationGroup(), parentGroup, failureMechanism); + var parentNodeData = new TestCalculationGroupContext(parentGroup, new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -220,7 +223,7 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var nodeData = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); + var nodeData = new TestCalculationGroupContext(new CalculationGroup(), new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -239,8 +242,9 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var groupContext = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); - var parentGroupContext = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); + var parentGroup = new CalculationGroup(); + var groupContext = new TestCalculationGroupContext(new CalculationGroup(), parentGroup, failureMechanism); + var parentGroupContext = new TestCalculationGroupContext(new CalculationGroup(), new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -259,7 +263,7 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var groupContext = new TestCalculationGroupContext(new CalculationGroup(), failureMechanism); + var groupContext = new TestCalculationGroupContext(new CalculationGroup(), new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); // Call @@ -540,7 +544,7 @@ private static void CreateCalculationGroupAndContext(out CalculationGroup data, out TestCalculationGroupContext dataContext, IFailureMechanism failureMechanism) { data = new CalculationGroup(); - dataContext = new TestCalculationGroupContext(data, failureMechanism); + dataContext = new TestCalculationGroupContext(data, new CalculationGroup(), failureMechanism); } /// @@ -563,7 +567,7 @@ calculation.Name = initialName; } data = calculation; - dataContext = new TestCalculationContext(calculation, failureMechanism); + dataContext = new TestCalculationContext(calculation, new CalculationGroup(), failureMechanism); break; case CalculationItemType.Group: var group = new CalculationGroup(); @@ -572,7 +576,7 @@ group.Name = initialName; } data = group; - dataContext = new TestCalculationGroupContext(group, failureMechanism); + dataContext = new TestCalculationGroupContext(group, new CalculationGroup(), failureMechanism); break; default: throw new NotSupportedException(); @@ -621,7 +625,7 @@ Name = calculationName }; - var context = new TestCalculationContext(calculation, failureMechanism); + var context = new TestCalculationContext(calculation, new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); // Call @@ -673,7 +677,7 @@ Name = "" }; - var context = new TestCalculationContext(calculation, failureMechanism); + var context = new TestCalculationContext(calculation, new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); context.WrappedData.Attach(observer); @@ -701,10 +705,10 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var context = new TestCalculationContext(calculationToBeRemoved, failureMechanism); + var context = new TestCalculationContext(calculationToBeRemoved, group, failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); - var groupContext = new TestCalculationGroupContext(group, failureMechanism); + var groupContext = new TestCalculationGroupContext(group, new CalculationGroup(), failureMechanism); // Call bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext); @@ -727,10 +731,10 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var context = new TestCalculationContext(calculationToBeRemoved, failureMechanism); + var context = new TestCalculationContext(calculationToBeRemoved, group, failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); - var groupContext = new TestCalculationGroupContext(group, failureMechanism); + var groupContext = new TestCalculationGroupContext(group, new CalculationGroup(), failureMechanism); // Call bool removalAllowed = treeNodeInfo.CanRemove(context, groupContext); @@ -749,7 +753,7 @@ var failureMechanism = mocks.StrictMock(); mocks.ReplayAll(); - var calculationContext = new TestCalculationContext(new TestCalculation(), failureMechanism); + var calculationContext = new TestCalculationContext(new TestCalculation(), new CalculationGroup(), failureMechanism); TreeNodeInfo treeNodeInfo = RingtoetsTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(null, null, null); // Call @@ -1052,27 +1056,33 @@ private class TestCalculationGroupContext : Observable, ICalculationContext { - public TestCalculationGroupContext(CalculationGroup wrappedData, IFailureMechanism failureMechanism) + public TestCalculationGroupContext(CalculationGroup wrappedData, CalculationGroup parent, IFailureMechanism failureMechanism) { WrappedData = wrappedData; + Parent = parent; FailureMechanism = failureMechanism; } public CalculationGroup WrappedData { get; } + public CalculationGroup Parent { get; } + public IFailureMechanism FailureMechanism { get; } } private class TestCalculationContext : Observable, ICalculationContext { - public TestCalculationContext(TestCalculation wrappedData, IFailureMechanism failureMechanism) + public TestCalculationContext(TestCalculation wrappedData, CalculationGroup parent, IFailureMechanism failureMechanism) { WrappedData = wrappedData; + Parent = parent; FailureMechanism = failureMechanism; } public TestCalculation WrappedData { get; } + public CalculationGroup Parent { get; } + public IFailureMechanism FailureMechanism { get; } }