Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs =================================================================== diff -u -r7d242b8efca25dd01d33ba0481d707f7ee4baebd -r1811626955b35ce3019b250013b92a56f00a561a --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision 7d242b8efca25dd01d33ba0481d707f7ee4baebd) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/CalculationTreeNodeInfoFactoryTest.cs (.../CalculationTreeNodeInfoFactoryTest.cs) (revision 1811626955b35ce3019b250013b92a56f00a561a) @@ -36,7 +36,7 @@ public class CalculationTreeNodeInfoFactoryTest { [Test] - public void Text_CreatedCalculationGroupContextTreeNodeInfo_AlwaysReturnsWrappedDataName() + public void TextOfCalculationGroupContextTreeNodeInfo_Always_ReturnsWrappedDataName() { // Setup var mocks = new MockRepository(); @@ -61,7 +61,7 @@ } [Test] - public void Image_CreatedCalculationGroupContextTreeNodeInfo_AlwaysReturnsFolderIcon() + public void ImageOfCalculationGroupContextTreeNodeInfo_Always_ReturnsFolderIcon() { // Setup var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); @@ -74,7 +74,7 @@ } [Test] - public void EnsureVisibleOnCreate_CreatedCalculationGroupContextTreeNodeInfo_AlwaysReturnsTrue() + public void EnsureVisibleOnCreateOfCalculationGroupContextTreeNodeInfo_Always_ReturnsTrue() { // Setup var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); @@ -86,8 +86,112 @@ Assert.IsTrue(result); } - private class TestCalculationGroupContext : ICalculationContext + [Test] + public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_ParentIsCalculationGroupContext_ReturnTrue() { + // Setup + var mocks = new MockRepository(); + var calculationGroupMock = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + + mocks.ReplayAll(); + + var groupContext = new TestCalculationGroupContext(calculationGroupMock, failureMechanismMock); + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Call + bool isRenamingAllowed = treeNodeInfo.CanRename(null, groupContext); + + // Assert + Assert.IsTrue(isRenamingAllowed); + mocks.VerifyAll(); + } + + [Test] + public void CanRenameNodeOfCalculationGroupContextTreeNodeInfo_EverythingElse_ReturnFalse() + { + // Setup + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Call + bool isRenamingAllowed = treeNodeInfo.CanRename(null, null); + + // Assert + Assert.IsFalse(isRenamingAllowed); + } + + [Test] + public void OnNodeRenamedOfCalculationGroupContextTreeNodeInfo_WithData_RenameGroupAndNotifyObservers() + { + // Setup + var mocks = new MockRepository(); + var observer = mocks.StrictMock(); + var failureMechanismMock = mocks.StrictMock(); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + const string newName = "new name"; + var group = new CalculationGroup(); + var nodeData = new TestCalculationGroupContext(group, failureMechanismMock); + + nodeData.Attach(observer); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Call + treeNodeInfo.OnNodeRenamed(nodeData, newName); + + // Assert + Assert.AreEqual(newName, group.Name); + mocks.VerifyAll(); + } + + [Test] + public void CanRemoveOfCalculationGroupContextTreeNodeInfo_CalculationGroupWithoutParent_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var group = new CalculationGroup(); + var nodeData = new TestCalculationGroupContext(group, failureMechanismMock); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Call + bool isRemovalAllowed = treeNodeInfo.CanRemove(nodeData, null); + + // Assert + Assert.IsFalse(isRemovalAllowed); + mocks.VerifyAll(); + } + + [Test] + public void CanRemoveOfCalculationGroupContextTreeNodeInfo_NestedCalculationGroup_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var failureMechanismMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var nodeData = new TestCalculationGroupContext(new CalculationGroup(), failureMechanismMock); + var parentNodeData = new TestCalculationGroupContext(new CalculationGroup(), failureMechanismMock); + + var treeNodeInfo = CalculationTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(null, null, null); + + // Call + bool isRemovalAllowed = treeNodeInfo.CanRemove(nodeData, parentNodeData); + + // Assert + Assert.IsTrue(isRemovalAllowed); + mocks.VerifyAll(); + } + + private class TestCalculationGroupContext : Observable, ICalculationContext + { public TestCalculationGroupContext(CalculationGroup wrappedData, IFailureMechanism failureMechanism) { WrappedData = wrappedData; @@ -97,12 +201,6 @@ public CalculationGroup WrappedData { get; private set; } public IFailureMechanism FailureMechanism { get; private set; } - - public void Attach(IObserver observer) {} - - public void Detach(IObserver observer) {} - - public void NotifyObservers() {} } } } \ No newline at end of file