// Copyright (C) Stichting Deltares 2018. 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.Collections.Generic;
using System.Drawing;
using System.Linq;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.TestUtil;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Data.TestUtil;
using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.MacroStabilityInwards.Plugin.Test.TreeNodeInfos
{
[TestFixture]
public class MacroStabilityInwardsStochasticSoilModelCollectionContextTreeNodeInfoTest : NUnitFormTest
{
private MockRepository mocks;
private MacroStabilityInwardsPlugin plugin;
private TreeNodeInfo info;
[Test]
public void Initialized_Always_ExpectedPropertiesSet()
{
// Setup
mocks.ReplayAll();
// Assert
Assert.IsNotNull(info.Text);
Assert.IsNotNull(info.ForeColor);
Assert.IsNotNull(info.Image);
Assert.IsNotNull(info.ContextMenuStrip);
Assert.IsNull(info.EnsureVisibleOnCreate);
Assert.IsNull(info.ExpandOnCreate);
Assert.IsNotNull(info.ChildNodeObjects);
Assert.IsNull(info.CanRename);
Assert.IsNull(info.OnNodeRenamed);
Assert.IsNull(info.CanRemove);
Assert.IsNull(info.OnNodeRemoved);
Assert.IsNull(info.CanCheck);
Assert.IsNull(info.CheckedState);
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_ReturnsTextFromResource()
{
// Setup
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
var stochasticSoilModelCollectionContext = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
failureMechanism.StochasticSoilModels,
failureMechanism,
assessmentSection);
// Call
string text = info.Text(stochasticSoilModelCollectionContext);
// Assert
Assert.AreEqual("Stochastische ondergrondmodellen", text);
}
[Test]
public void Image_Always_ReturnsSetImage()
{
// Setup
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
var stochasticSoilModelCollectionContext = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
failureMechanism.StochasticSoilModels,
failureMechanism,
assessmentSection);
// Call
Image image = info.Image(stochasticSoilModelCollectionContext);
// Assert
TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GeneralFolderIcon, image);
}
[Test]
public void ForeColor_CollectionWithoutSoilProfiles_ReturnsGrayText()
{
// Setup
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
var stochasticSoilModelCollectionContext = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
failureMechanism.StochasticSoilModels,
failureMechanism,
assessmentSection);
// Call
Color foreColor = info.ForeColor(stochasticSoilModelCollectionContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), foreColor);
}
[Test]
public void ForeColor_CollectionWithSoilProfiles_ReturnsControlText()
{
// Setup
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
failureMechanism.StochasticSoilModels.AddRange(new[]
{
MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel()
}, "path");
var stochasticSoilModelCollectionContext = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
failureMechanism.StochasticSoilModels,
failureMechanism,
assessmentSection);
// Call
Color foreColor = info.ForeColor(stochasticSoilModelCollectionContext);
// Assert
Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), foreColor);
}
[Test]
public void ChildNodeObjects_Always_ReturnsChildrenOfData()
{
// Setup
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var soilProfile1 = new MacroStabilityInwardsSoilProfile1D("soilProfile1", 0, new List
{
new MacroStabilityInwardsSoilLayer1D(10)
});
var soilProfile2 = new MacroStabilityInwardsSoilProfile1D("soilProfile2", 0, new List
{
new MacroStabilityInwardsSoilLayer1D(10)
});
var stochasticSoilProfile1 = new MacroStabilityInwardsStochasticSoilProfile(1.0, soilProfile1);
var stochasticSoilProfile2 = new MacroStabilityInwardsStochasticSoilProfile(1.0, soilProfile2);
MacroStabilityInwardsStochasticSoilModel stochasticSoilModel =
MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel(new[]
{
stochasticSoilProfile1,
stochasticSoilProfile2
});
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
var stochasticSoilModelCollectionContext = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
failureMechanism.StochasticSoilModels,
failureMechanism,
assessmentSection);
failureMechanism.StochasticSoilModels.AddRange(new[]
{
stochasticSoilModel
}, "path");
// Call
object[] objects = info.ChildNodeObjects(stochasticSoilModelCollectionContext);
// Assert
CollectionAssert.AreEqual(new[]
{
stochasticSoilModel
}, objects);
}
[Test]
public void ContextMenuStrip_Always_CallsBuilder()
{
// Setup
var assessmentSection = mocks.Stub();
var menuBuilder = mocks.StrictMock();
using (mocks.Ordered())
{
menuBuilder.Expect(mb => mb.AddImportItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddUpdateItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.Build()).Return(null);
}
using (var treeViewControl = new TreeViewControl())
{
var context = new MacroStabilityInwardsStochasticSoilModelCollectionContext(
new MacroStabilityInwardsStochasticSoilModelCollection(),
new MacroStabilityInwardsFailureMechanism(),
assessmentSection);
var gui = mocks.Stub();
gui.Stub(g => g.Get(context, treeViewControl)).Return(menuBuilder);
mocks.ReplayAll();
plugin.Gui = gui;
// Call
info.ContextMenuStrip(context, null, treeViewControl);
}
// Assert
// Assert expectancies are called in TearDown()
}
public override void Setup()
{
mocks = new MockRepository();
plugin = new MacroStabilityInwardsPlugin();
info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(MacroStabilityInwardsStochasticSoilModelCollectionContext));
}
public override void TearDown()
{
plugin.Dispose();
mocks.VerifyAll();
base.TearDown();
}
}
}