// 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.Gui; using Core.Common.Gui.ContextMenu; 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.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Plugin; using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources; namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.TreeNodeInfos { [TestFixture] public class GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest { private MockRepository mocks; private GrassCoverErosionInwardsGuiPlugin plugin; private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); plugin = new GrassCoverErosionInwardsGuiPlugin(); info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationContext)); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Assert Assert.AreEqual(typeof(GrassCoverErosionInwardsCalculationContext), info.TagType); 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_ReturnsPlaceHolderIcon() { // Call var image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(GrassCoverErosionInwardsFormsResources.CalculationIcon, image); } [Test] public void ChildNodeObjects_WithOutputData_ReturnOutputChildNode() { var calculation = mocks.StrictMock(new GeneralGrassCoverErosionInwardsInput()); var assessmentSectionMock = mocks.StrictMock(); mocks.ReplayAll(); 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 grassCoverErosionInwardsCalculationContext = (GrassCoverErosionInwardsInputContext) children[1]; Assert.AreSame(calculationContext.WrappedData.InputParameters, grassCoverErosionInwardsCalculationContext.WrappedData); var emptyOutput = (EmptyGrassCoverErosionInwardsOutput) children[2]; Assert.IsNotNull(emptyOutput); } [Test] public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() { // Setup var gui = mocks.StrictMock(); var treeViewControlMock = mocks.StrictMock(); var menuBuilderMock = mocks.Stub(); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddImportItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.Build()).Return(null); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var assessmentSectionMock = mocks.StrictMock(); var calculation = mocks.StrictMock(new GeneralGrassCoverErosionInwardsInput()); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(menuBuilderMock); mocks.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(nodeData, null, treeViewControlMock); // Assert mocks.VerifyAll(); // Expect no calls on arguments } } }