Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj =================================================================== diff -u -r3b29807e8903b2cea3ee7a00a59b2b50f9de1f12 -ra9f78bc9a33e6fe9ad5cc56d6f45142ad9b96b5c --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision 3b29807e8903b2cea3ee7a00a59b2b50f9de1f12) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Forms.Test.csproj) (revision a9f78bc9a33e6fe9ad5cc56d6f45142ad9b96b5c) @@ -74,7 +74,7 @@ - + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs (revision a9f78bc9a33e6fe9ad5cc56d6f45142ad9b96b5c) @@ -0,0 +1,276 @@ +// 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.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +using Core.Common.Gui.Commands; +using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +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 RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.TreeNodeInfos +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest : NUnitFormTest + { + private MockRepository mocksRepository; + private GrassCoverErosionInwardsGuiPlugin plugin; + private TreeNodeInfo info; + + private const int contextMenuRelevancyIndex = 1; + + [SetUp] + public void SetUp() + { + mocksRepository = new MockRepository(); + plugin = new GrassCoverErosionInwardsGuiPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(GrassCoverErosionInwardsFailureMechanismContext)); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(GrassCoverErosionInwardsFailureMechanismContext), info.TagType); + Assert.IsNotNull(info.ForeColor); + Assert.IsNull(info.EnsureVisibleOnCreate); + Assert.IsNull(info.CanRename); + Assert.IsNull(info.OnNodeRenamed); + Assert.IsNull(info.CanRemove); + Assert.IsNull(info.OnNodeRemoved); + Assert.IsNull(info.CanCheck); + Assert.IsNull(info.IsChecked); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Text_Always_ReturnsName() + { + // Setup + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var mechanism = new GrassCoverErosionInwardsFailureMechanism(); + var mechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(mechanism, assessmentSection); + + // Call + var text = info.Text(mechanismContext); + + // Assert + const string expectedName = "Dijken - Grasbekleding erosie kruin en binnentalud"; + Assert.AreEqual(expectedName, text); + mocksRepository.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsFailureMechanismIcon() + { + // Call + var image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.FailureMechanismIcon, image); + } + + [Test] + public void ChildNodeObjects_Always_ReturnChildDataNodes() + { + // Setup + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + var children = info.ChildNodeObjects(failureMechanismContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + var inputsFolder = (CategoryTreeFolder) children[0]; + Assert.AreEqual("Invoer", inputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); + + Assert.AreEqual(2, inputsFolder.Contents.Count); + var failureMechanismSectionsContext = (FailureMechanismSectionsContext) inputsFolder.Contents[0]; + CollectionAssert.AreEqual(failureMechanism.Sections, failureMechanismSectionsContext.WrappedData); + Assert.AreSame(failureMechanism, failureMechanismSectionsContext.ParentFailureMechanism); + Assert.AreSame(assessmentSection, failureMechanismSectionsContext.ParentAssessmentSection); + + var commentContext = (CommentContext) inputsFolder.Contents[1]; + Assert.AreSame(failureMechanism, commentContext.CommentContainer); + + var calculationsFolder = (GrassCoverErosionInwardsCalculationGroupContext) children[1]; + Assert.AreEqual("Berekeningen", calculationsFolder.WrappedData.Name); + CollectionAssert.AreEqual(failureMechanism.CalculationsGroup.Children, calculationsFolder.WrappedData.Children); + Assert.AreSame(failureMechanism, calculationsFolder.FailureMechanism); + + var outputsFolder = (CategoryTreeFolder) children[2]; + Assert.AreEqual("Uitvoer", outputsFolder.Name); + Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); + + var failureMechanismResultsContext = (FailureMechanismSectionResultContext) outputsFolder.Contents[0]; + Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); + Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.SectionResults); + mocksRepository.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSection = mocksRepository.Stub(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var guiMock = mocksRepository.StrictMock(); + var treeViewControlMock = mocksRepository.StrictMock(); + var menuBuilderMock = mocksRepository.StrictMock(); + + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().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.Build()).Return(null); + + guiMock.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControlMock)).Return(menuBuilderMock); + mocksRepository.ReplayAll(); + + plugin.Gui = guiMock; + + // Call + info.ContextMenuStrip(failureMechanismContext, null, treeViewControlMock); + + // Assert + mocksRepository.VerifyAll(); + } + + [Test] + public void ContextMenuStrip_Always_IsRelevantEnabledAddCalculationGroupAddCalculationItemDisabled() + { + // Setup + using (var treeView = new TreeViewControl()) + { + var assessmentSection = mocksRepository.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var menuBuilderMock = new CustomItemsOnlyContextMenuBuilder(); + + var gui = mocksRepository.StrictMock(); + gui.Expect(cmp => cmp.Get(failureMechanismContext, treeView)).Return(menuBuilderMock); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + // Call + var menu = info.ContextMenuStrip(failureMechanismContext, assessmentSection, treeView); + + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndex, + RingtoetsCommonFormsResources.FailureMechanismContextMenuStrip_Is_relevant, + RingtoetsCommonFormsResources.FailureMechanismContextMenuStrip_Is_relevant_Tooltip, + RingtoetsCommonFormsResources.Checkbox_ticked); + TestHelper.AssertContextMenuStripContainsItem(menu, 3, + RingtoetsCommonFormsResources.CalculationGroup_Add_CalculationGroup, + RingtoetsCommonFormsResources.FailureMechanism_Add_CalculationGroup_Tooltip, + RingtoetsCommonFormsResources.AddFolderIcon, + false); + TestHelper.AssertContextMenuStripContainsItem(menu, 4, + RingtoetsCommonFormsResources.CalculationGroup_Add_Calculation, + GrassCoverErosionInwardsFormsResources.GrassCoverErosionInwardsFailureMechanism_Add_GrassCoverErosionInwardsCalculation_Tooltip, + GrassCoverErosionInwardsFormsResources.CalculationIcon, + false); + + mocksRepository.VerifyAll(); + } + } + + [Test] + public void ContextMenuStrip_ClickOnIsRelevantItem_MakeFailureMechanismNotRelevant() + { + // Setup + var failureMechanismObserver = mocksRepository.Stub(); + failureMechanismObserver.Expect(o => o.UpdateObserver()); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = true + }; + failureMechanism.Attach(failureMechanismObserver); + + var assessmentSection = mocksRepository.Stub(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var viewCommands = mocksRepository.StrictMock(); + viewCommands.Expect(vs => vs.RemoveAllViewsForItem(failureMechanismContext)); + + var treeViewControl = mocksRepository.StrictMock(); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var gui = mocksRepository.StrictMock(); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + gui.Expect(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); + + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + var contextMenu = info.ContextMenuStrip(failureMechanismContext, null, treeViewControl); + + // Call + contextMenu.Items[contextMenuRelevancyIndex].PerformClick(); + + // Assert + Assert.IsFalse(failureMechanism.IsRelevant); + mocksRepository.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag a9f78bc9a33e6fe9ad5cc56d6f45142ad9b96b5c refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?