// 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.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.DuneErosion.Data; using Ringtoets.DuneErosion.Data.TestUtil; using Ringtoets.DuneErosion.Forms.PresentationObjects; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.DuneErosion.Plugin.Test.TreeNodeInfos { [TestFixture] public class DuneLocationsContextTreeNodeInfoTest { private MockRepository mocks; private DuneErosionPlugin plugin; private TreeNodeInfo info; [SetUp] public void SetUp() { mocks = new MockRepository(); plugin = new DuneErosionPlugin(); info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(DuneLocationsContext)); } [TearDown] public void TearDown() { plugin.Dispose(); mocks.VerifyAll(); } [Test] public void Initialized_Always_ExpectedPropertiesSet() { // Setup mocks.ReplayAll(); // Assert Assert.AreEqual(typeof(DuneLocationsContext), info.TagType); Assert.IsNotNull(info.Text); Assert.IsNotNull(info.ForeColor); Assert.IsNotNull(info.Image); Assert.IsNotNull(info.ContextMenuStrip); Assert.IsNull(info.ChildNodeObjects); 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 = mocks.Stub(); mocks.ReplayAll(); var mechanism = new DuneErosionFailureMechanism(); var context = new DuneLocationsContext(mechanism.DuneLocations, mechanism, assessmentSection); // Call var text = info.Text(context); // Assert Assert.AreEqual("Hydraulische randvoorwaarden", text); } [Test] public void Image_Always_ReturnsGenericInputOutputIcon() { // Setup mocks.ReplayAll(); // Call var image = info.Image(null); // Assert TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); } [Test] public void ForeColor_NoLocations_ReturnGrayText() { // Setup var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var mechanism = new DuneErosionFailureMechanism(); var context = new DuneLocationsContext(mechanism.DuneLocations, mechanism, assessmentSection); // Call Color textColor = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), textColor); } [Test] public void ForeColor_WithLocations_ReturnControlText() { // Setup var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var mechanism = new DuneErosionFailureMechanism(); mechanism.DuneLocations.Add(new TestDuneLocation()); var context = new DuneLocationsContext(mechanism.DuneLocations, mechanism, assessmentSection); // Call Color textColor = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), textColor); } [Test] public void ContextMenuStrip_Always_CallsBuilder() { // Setup using (var treeViewControl = new TreeViewControl()) { var assessmentSectionMock = mocks.StrictMock(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneLocationsContext(failureMechanism.DuneLocations, failureMechanism, assessmentSectionMock); var menuBuilder = mocks.StrictMock(); using (mocks.Ordered()) { menuBuilder.Expect(mb => mb.AddExportItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } var gui = mocks.StrictMock(); gui.Expect(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(context, null, treeViewControl); } // Assert // Done in tearDown } [Test] public void ContextMenuStrip_Always_AddCustomItem() { // Setup using (var treeViewControl = new TreeViewControl()) { var assessmentSectionMock = mocks.StrictMock(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneLocationsContext(failureMechanism.DuneLocations, failureMechanism, assessmentSectionMock); var builder = new CustomItemsOnlyContextMenuBuilder(); var gui = mocks.StrictMock(); gui.Expect(cmp => cmp.Get(context, treeViewControl)).Return(builder); mocks.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip menu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert Assert.AreEqual(5, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, 2, "Alles be&rekenen", "Voer alle berekeningen binnen dit toetsspoor uit.", RingtoetsCommonFormsResources.CalculateAllIcon, false); } } } } }