// 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 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.Common.Forms.Properties;
using Ringtoets.HydraRing.Data;
using Ringtoets.Integration.Forms.PresentationObjects;
using Ringtoets.Integration.Plugin;
namespace Ringtoets.Integration.Forms.Test.TreeNodeInfos
{
public class WaveHeightContextTreeNodeInfoTest
{
private MockRepository mockRepository;
[SetUp]
public void SetUp()
{
mockRepository = new MockRepository();
}
[Test]
public void Initialized_Always_ExpectedPropertiesSet()
{
// Setup
mockRepository.ReplayAll();
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Assert
Assert.AreEqual(typeof(WaveHeightContext), info.TagType);
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);
}
mockRepository.VerifyAll();
}
[Test]
public void Text_Always_ReturnsSetName()
{
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
var text = info.Text(null);
// Assert
const string expectedName = "Golfhoogtes";
Assert.AreEqual(expectedName, text);
}
}
[Test]
public void Image_Always_ReturnsGenericIcon()
{
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
var image = info.Image(null);
// Assert
TestHelper.AssertImagesAreEqual(Resources.GenericInputOutputIcon, image);
}
}
[Test]
public void CanRenameNode_Always_ReturnsFalse()
{
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
var renameAllowed = info.CanRename(null, null);
// Assert
Assert.IsFalse(renameAllowed);
}
}
[Test]
public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods()
{
// Setup
var guiMock = mockRepository.StrictMock();
var menuBuilderMock = mockRepository.StrictMock();
var assessmentSectionMock = mockRepository.Stub();
var nodeData = new WaveHeightContext(assessmentSectionMock);
menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock);
menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock);
menuBuilderMock.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilderMock);
menuBuilderMock.Expect(mb => mb.Build()).Return(null);
guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments();
guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
using (var treeViewControl = new TreeViewControl())
{
guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilderMock);
mockRepository.ReplayAll();
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
plugin.Gui = guiMock;
// Call
info.ContextMenuStrip(nodeData, null, treeViewControl);
}
}
// Assert
mockRepository.VerifyAll();
}
[Test]
public void ContextMenuStrip_NoHydraulicBoundaryDatabaseSet_ContextMenuItemCalculateDisabled()
{
// Setup
var guiMock = mockRepository.StrictMock();
var assessmentSectionMock = mockRepository.Stub();
var nodeData = new WaveHeightContext(assessmentSectionMock);
guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments();
guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
using (var treeViewControl = new TreeViewControl())
{
guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
mockRepository.ReplayAll();
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
plugin.Gui = guiMock;
// Call
var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl);
// Assert
const string expectedItemText = "&Berekenen";
const string expectedItemTooltip = "Er is geen hydraulische randvoorwaardendatabase beschikbaar om de golfhoogtes te berekenen.";
TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, expectedItemText, expectedItemTooltip, Resources.FailureMechanismIcon, false);
}
}
mockRepository.VerifyAll(); // Expect no calls on arguments
}
[Test]
public void ContextMenuStrip_HydraulicBoundaryDatabaseSet_ContextMenuItemCalculateEnabled()
{
// Setup
var guiMock = mockRepository.StrictMock();
var assessmentSectionMock = mockRepository.Stub();
var nodeData = new WaveHeightContext(assessmentSectionMock)
{
WrappedData =
{
HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase()
}
};
guiMock.Stub(g => g.ProjectOpened += null).IgnoreArguments();
guiMock.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
using (var treeViewControl = new TreeViewControl())
{
guiMock.Expect(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
mockRepository.ReplayAll();
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
plugin.Gui = guiMock;
// Call
var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl);
// Assert
const string expectedItemText = "&Berekenen";
const string expectedItemTooltip = "Bereken de golfhoogtes.";
TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, expectedItemText, expectedItemTooltip, Resources.FailureMechanismIcon);
}
}
mockRepository.VerifyAll(); // Expect no calls on arguments
}
[Test]
public void ForeColor_ContextHasNoHydraulicBoundaryDatabase_ReturnDisabledColor()
{
// Setup
var assessmentSection = mockRepository.Stub();
mockRepository.ReplayAll();
var designWaterLevelContext = new WaveHeightContext(assessmentSection);
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
Color color = info.ForeColor(designWaterLevelContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color);
}
mockRepository.VerifyAll();
}
[Test]
public void ForeColor_ContextHasHydraulicBoundaryDatabaseData_ReturnControlText()
{
// Setup
var assessmentSection = mockRepository.Stub();
assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
mockRepository.ReplayAll();
var designWaterLevelContext = new WaveHeightContext(assessmentSection);
using (var plugin = new RingtoetsPlugin())
{
var info = GetInfo(plugin);
// Call
Color color = info.ForeColor(designWaterLevelContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color);
}
mockRepository.VerifyAll();
}
private static TreeNodeInfo GetInfo(RingtoetsPlugin plugin)
{
return plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(WaveHeightContext));
}
}
}