Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r33efdf255d012f47a045c7f3181487e0453cf5e2 -re17e5b2635c772e29fb45610f10a3b4021ab7eaa --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 33efdf255d012f47a045c7f3181487e0453cf5e2) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision e17e5b2635c772e29fb45610f10a3b4021ab7eaa) @@ -72,6 +72,16 @@ { // Assert Assert.AreEqual(typeof(GrassCoverErosionInwardsCalculationContext), info.TagType); + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.EnsureVisibleOnCreate); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNotNull(info.CanRename); + Assert.IsNotNull(info.OnNodeRenamed); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanDrag); Assert.IsNull(info.ForeColor); Assert.IsNull(info.CanCheck); Assert.IsNull(info.IsChecked); @@ -92,7 +102,7 @@ } [Test] - public void ChildNodeObjects_WithoutOutputData_ReturnCommentNodeInputNodeAndEmptyOutputChildNode() + public void ChildNodeObjects_CalculationWithoutOutput_ReturnCollectionWithEmptyOutputObject() { var assessmentSectionMock = mocks.StrictMock(); mocks.ReplayAll(); @@ -106,23 +116,59 @@ // Assert Assert.AreEqual(3, children.Length); + var commentContext = children[0] as CommentContext; Assert.IsNotNull(commentContext); Assert.AreSame(calculationContext.WrappedData, commentContext.CommentContainer); - var grassCoverErosionInwardsCalculationContext = (GrassCoverErosionInwardsInputContext) children[1]; - Assert.AreSame(calculationContext.WrappedData.InputParameters, grassCoverErosionInwardsCalculationContext.WrappedData); + var heightStructuresInputContext = children[1] as GrassCoverErosionInwardsInputContext; + Assert.IsNotNull(heightStructuresInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, heightStructuresInputContext.WrappedData); - var emptyOutput = (EmptyGrassCoverErosionInwardsOutput) children[2]; + var emptyOutput = children[2] as EmptyGrassCoverErosionInwardsOutput; Assert.IsNotNull(emptyOutput); + mocks.VerifyAll(); } [Test] + public void ChildNodeObjects_CalculationWithOutput_ReturnCollectionWithOutputObject() + { + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput(), new GeneralNormProbabilityInput()) + { + Output = new GrassCoverErosionInwardsOutput(0, 0, 0, 0, 0) + }; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + // Call + var children = info.ChildNodeObjects(calculationContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + + var commentContext = children[0] as CommentContext; + Assert.IsNotNull(commentContext); + Assert.AreSame(calculationContext.WrappedData, commentContext.CommentContainer); + + var heightStructuresInputContext = children[1] as GrassCoverErosionInwardsInputContext; + Assert.IsNotNull(heightStructuresInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, heightStructuresInputContext.WrappedData); + + var output = children[2] as GrassCoverErosionInwardsOutput; + Assert.IsNotNull(output); + + mocks.VerifyAll(); + } + + [Test] public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup - var gui = mocks.StrictMock(); + var guiMock = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); var menuBuilderMock = mocks.Stub(); @@ -148,11 +194,11 @@ var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); - gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(menuBuilderMock); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(menuBuilderMock); mocks.ReplayAll(); - plugin.Gui = gui; + plugin.Gui = guiMock; // Call info.ContextMenuStrip(nodeData, null, treeViewControlMock); @@ -172,12 +218,12 @@ new GeneralNormProbabilityInput()); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); - var gui = mocks.StrictMock(); - gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + var guiMock = mocks.StrictMock(); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); - plugin.Gui = gui; + plugin.Gui = guiMock; // Call var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); @@ -196,7 +242,7 @@ public void ContextMenuStrip_FailureMechanismSectionsSetNoHydraulicBoundaryDatabase_ContextMenuItemPerformCalculationDisabledAndTooltipSet() { // Setup - var gui = mocks.StrictMock(); + var guiMock = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); @@ -213,11 +259,11 @@ var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); - gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); - plugin.Gui = gui; + plugin.Gui = guiMock; // Call var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); @@ -236,7 +282,7 @@ public void ContextMenuStrip_FailureMechanismSetHydraulicBoundaryDatabaseNotValid_ContextMenuItemPerformCalculationDisabledAndTooltipSet() { // Setup - var gui = mocks.StrictMock(); + var guiMock = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); @@ -253,11 +299,11 @@ var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); - gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); - plugin.Gui = gui; + plugin.Gui = guiMock; // Call ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); @@ -277,7 +323,7 @@ public void ContextMenuStrip_FailureMechanismSectionsAndHydraulicBoundaryDatabaseSet_ContextMenuItemPerformCalculationEnabled() { // Setup - var gui = mocks.StrictMock(); + var guiMock = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); @@ -302,11 +348,11 @@ var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); - gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); mocks.ReplayAll(); - plugin.Gui = gui; + plugin.Gui = guiMock; // Call var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); @@ -326,7 +372,7 @@ // Given var gui = mocks.DynamicMock(); var mainWindow = mocks.DynamicMock(); - var observer = mocks.StrictMock(); + var observerMock = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); var calculateContextMenuItemIndex = 0; @@ -349,8 +395,10 @@ }; hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase + }; var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput(), new GeneralNormProbabilityInput()) { @@ -370,7 +418,7 @@ plugin.Gui = gui; - calculation.Attach(observer); + calculation.Attach(observerMock); var contextMenuAdapter = info.ContextMenuStrip(calculationContext, null, treeViewControlMock); @@ -401,8 +449,8 @@ public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup(bool groupNameEditable) { // Setup - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); var elementToBeRemoved = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput(), new GeneralNormProbabilityInput()); @@ -411,7 +459,7 @@ group.Children.Add(elementToBeRemoved); group.Children.Add(new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput(), new GeneralNormProbabilityInput())); - group.Attach(observer); + group.Attach(observerMock); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var assessmentSectionMock = mocks.StrictMock(); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj =================================================================== diff -u -ra2293026e111698c108d23f2f1fc7a09764a1bb6 -re17e5b2635c772e29fb45610f10a3b4021ab7eaa --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision a2293026e111698c108d23f2f1fc7a09764a1bb6) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision e17e5b2635c772e29fb45610f10a3b4021ab7eaa) @@ -57,6 +57,7 @@ + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (revision e17e5b2635c772e29fb45610f10a3b4021ab7eaa) @@ -0,0 +1,150 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Common.Controls.TreeView; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Plugin; +using HeightStructuresFormsResources = Ringtoets.HeightStructures.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.HeightStructures.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class HeightStructuresCalculationContextTreeNodeInfoTest + { + private MockRepository mocks; + private HeightStructuresGuiPlugin plugin; + private TreeNodeInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new HeightStructuresGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructuresCalculationContext)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(HeightStructuresCalculationContext), info.TagType); + Assert.IsNotNull(info.Text); + Assert.IsNotNull(info.Image); + Assert.IsNotNull(info.EnsureVisibleOnCreate); + Assert.IsNotNull(info.ChildNodeObjects); + Assert.IsNotNull(info.ContextMenuStrip); + Assert.IsNotNull(info.CanRename); + Assert.IsNotNull(info.OnNodeRenamed); + Assert.IsNotNull(info.CanRemove); + Assert.IsNotNull(info.OnNodeRemoved); + Assert.IsNotNull(info.CanDrag); + Assert.IsNull(info.ForeColor); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Image_Always_ReturnsCalculationIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(HeightStructuresFormsResources.CalculationIcon, image); + } + + [Test] + public void ChildNodeObjects_CalculationWithoutOutput_ReturnCollectionWithEmptyOutputObject() + { + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculation = new HeightStructuresCalculation(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var calculationContext = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + // Call + var children = info.ChildNodeObjects(calculationContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + + var commentContext = children[0] as CommentContext; + Assert.IsNotNull(commentContext); + Assert.AreSame(calculationContext.WrappedData, commentContext.CommentContainer); + + var heightStructuresInputContext = children[1] as HeightStructuresInputContext; + Assert.IsNotNull(heightStructuresInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, heightStructuresInputContext.WrappedData); + + var emptyOutput = children[2] as EmptyHeightStructuresOutput; + Assert.IsNotNull(emptyOutput); + + mocks.VerifyAll(); + } + + [Test] + public void ChildNodeObjects_CalculationWithOutput_ReturnCollectionWithOutputObject() + { + var assessmentSectionMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var calculation = new HeightStructuresCalculation + { + Output = new HeightStructuresOutput() + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var calculationContext = new HeightStructuresCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + // Call + var children = info.ChildNodeObjects(calculationContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + + var commentContext = children[0] as CommentContext; + Assert.IsNotNull(commentContext); + Assert.AreSame(calculationContext.WrappedData, commentContext.CommentContainer); + + var heightStructuresInputContext = children[1] as HeightStructuresInputContext; + Assert.IsNotNull(heightStructuresInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, heightStructuresInputContext.WrappedData); + + var output = children[2] as HeightStructuresOutput; + Assert.IsNotNull(output); + + mocks.VerifyAll(); + } + } +}