// Copyright (C) Stichting Deltares 2017. 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Base.Geometry;
using Core.Common.Controls.DataGrid;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
using Core.Common.Gui.Commands;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Forms.MainWindow;
using Core.Common.Gui.TestUtil.ContextMenu;
using Core.Common.TestUtil;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Forms;
using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Service.TestUtil;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Data.TestUtil;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.HydraRing.Calculation.Calculator.Factory;
using Ringtoets.HydraRing.Calculation.Data.Input.Structures;
using Ringtoets.HydraRing.Calculation.TestUtil.Calculator;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.HeightStructures.Plugin.Test.TreeNodeInfos
{
[TestFixture]
public class HeightStructuresCalculationGroupContextTreeNodeInfoTest : NUnitFormTest
{
private const int contextMenuGenerateCalculationsIndexRootGroup = 3;
private const int contextMenuAddCalculationGroupIndexRootGroup = 5;
private const int contextMenuAddCalculationIndexRootGroup = 6;
private const int contextMenuUpdateForeshoreProfileIndexRootGroup = 8;
private const int contextMenuUpdateStructureAllIndexRootGroup = 9;
private const int contextMenuValidateAllIndexRootGroup = 11;
private const int contextMenuCalculateAllIndexRootGroup = 12;
private const int contextMenuClearAllIndexRootGroup = 14;
private const int contextMenuDuplicateIndexNestedGroup = 3;
private const int contextMenuAddCalculationGroupIndexNestedGroup = 5;
private const int contextMenuAddCalculationIndexNestedGroup = 6;
private const int contextMenuUpdateForeshoreProfileIndexNestedGroup = 9;
private const int contextMenuUpdateStructureAllIndexNestedGroup = 10;
private const int contextMenuValidateAllIndexNestedGroup = 12;
private const int contextMenuCalculateAllIndexNestedGroup = 13;
private const int contextMenuClearAllIndexNestedGroup = 15;
private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter");
private IGui gui;
private TreeNodeInfo info;
private MockRepository mocks;
private HeightStructuresPlugin plugin;
public override void Setup()
{
mocks = new MockRepository();
gui = mocks.Stub();
plugin = new HeightStructuresPlugin
{
Gui = gui
};
info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructuresCalculationGroupContext));
}
public override void TearDown()
{
plugin.Dispose();
mocks.VerifyAll();
base.TearDown();
}
[Test]
public void Initialized_Always_ExpectedPropertiesSet()
{
// Setup
mocks.ReplayAll();
// Assert
Assert.IsNotNull(info.Text);
Assert.IsNull(info.ForeColor);
Assert.IsNotNull(info.Image);
Assert.IsNotNull(info.ContextMenuStrip);
Assert.IsNotNull(info.EnsureVisibleOnCreate);
Assert.IsNull(info.ExpandOnCreate);
Assert.IsNotNull(info.ChildNodeObjects);
Assert.IsNotNull(info.CanRename);
Assert.IsNotNull(info.OnNodeRenamed);
Assert.IsNotNull(info.CanRemove);
Assert.IsNotNull(info.OnNodeRemoved);
Assert.IsNull(info.CanCheck);
Assert.IsNull(info.IsChecked);
Assert.IsNull(info.OnNodeChecked);
Assert.IsNotNull(info.CanDrag);
Assert.IsNotNull(info.CanDrop);
Assert.IsNotNull(info.CanInsert);
Assert.IsNotNull(info.OnDrop);
}
[Test]
public void ChildNodeObjects_EmptyGroup_ReturnEmpty()
{
// Setup
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var groupContext = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
// Call
object[] children = info.ChildNodeObjects(groupContext);
// Assert
CollectionAssert.IsEmpty(children);
}
[Test]
public void ChildNodeObjects_GroupWithMixedContents_ReturnChildren()
{
// Setup
var assessmentSection = mocks.Stub();
var calculationItem = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new HeightStructuresFailureMechanism();
var group = new CalculationGroup();
var childGroup = new CalculationGroup();
var childCalculation = new StructuresCalculation();
group.Children.Add(childGroup);
group.Children.Add(calculationItem);
group.Children.Add(childCalculation);
var groupContext = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
// Call
object[] children = info.ChildNodeObjects(groupContext).ToArray();
// Assert
Assert.AreEqual(group.Children.Count, children.Length);
var calculationGroupContext = (HeightStructuresCalculationGroupContext) children[0];
Assert.AreSame(childGroup, calculationGroupContext.WrappedData);
Assert.AreSame(group, calculationGroupContext.Parent);
Assert.AreSame(failureMechanism, calculationGroupContext.FailureMechanism);
Assert.AreSame(assessmentSection, calculationGroupContext.AssessmentSection);
Assert.AreSame(calculationItem, children[1]);
var calculationContext = (HeightStructuresCalculationContext) children[2];
Assert.AreSame(childCalculation, calculationContext.WrappedData);
Assert.AreSame(group, calculationContext.Parent);
Assert.AreSame(assessmentSection, calculationContext.AssessmentSection);
}
[Test]
public void ContextMenuStrip_WithoutParentNodeDefaultBehavior_CallsContextMenuBuilderMethods()
{
// Setup
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var groupContext = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = mocks.StrictMock();
using (mocks.Ordered())
{
menuBuilder.Expect(mb => mb.AddImportItem()).Return(menuBuilder);
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.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddDeleteChildrenItem()).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())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
info.ContextMenuStrip(groupContext, null, treeViewControl);
}
// Assert
// Assert expectancies called in TearDown()
}
[Test]
public void ContextMenuStrip_WithoutParentNodeDefaultBehavior_AddCustomItems()
{
// Setup
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var groupContext = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl))
{
// Assert
Assert.AreEqual(21, menu.Items.Count);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup,
"Genereer &berekeningen...",
"Er zijn geen kunstwerken beschikbaar om berekeningen voor te genereren.",
RingtoetsCommonFormsResources.GenerateScenariosIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexRootGroup,
"&Map toevoegen",
"Voeg een nieuwe map toe aan deze map met berekeningen.",
RingtoetsCommonFormsResources.AddFolderIcon);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexRootGroup,
"Berekening &toevoegen",
"Voeg een nieuwe berekening toe aan deze map met berekeningen.",
RingtoetsCommonFormsResources.FailureMechanismIcon);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndexRootGroup,
"&Bijwerken voorlandprofielen...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu,
contextMenuUpdateStructureAllIndexRootGroup,
"&Bijwerken kunstwerken...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup,
"Alles &valideren",
"Er zijn geen berekeningen om te valideren.",
RingtoetsCommonFormsResources.ValidateAllIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup,
"Alles be&rekenen",
"Er zijn geen berekeningen om uit te voeren.",
RingtoetsCommonFormsResources.CalculateAllIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearAllIndexRootGroup,
"&Wis alle uitvoer...",
"Er zijn geen berekeningen met uitvoer om te wissen.",
RingtoetsCommonFormsResources.ClearIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_WithoutParentNodeWithStructuresImported_GenerateItemEnabledWithTooltip()
{
// Setup
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.HeightStructures.AddRange(new[]
{
new TestHeightStructure()
}, "some path");
var assessmentSection = mocks.Stub();
var groupContext = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase());
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, null, treeViewControl))
{
// Assert
Assert.AreEqual(21, menu.Items.Count);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuGenerateCalculationsIndexRootGroup,
"Genereer &berekeningen...",
"Genereer berekeningen op basis van geselecteerde kunstwerken.",
RingtoetsCommonFormsResources.GenerateScenariosIcon);
}
}
}
[Test]
public void ContextMenuStrip_NestedCalculationGroup_CallsContextMenuBuilderMethods()
{
// Setup
var group = new CalculationGroup();
var parentGroup = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var groupContext = new HeightStructuresCalculationGroupContext(group,
parentGroup,
failureMechanism,
assessmentSection);
var parentGroupContext = new HeightStructuresCalculationGroupContext(parentGroup,
null,
failureMechanism,
assessmentSection);
var menuBuilder = mocks.StrictMock();
using (mocks.Ordered())
{
menuBuilder.Expect(mb => mb.AddImportItem()).Return(menuBuilder);
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.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddRenameItem()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder);
menuBuilder.Expect(mb => mb.AddDeleteItem()).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())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl);
}
// Assert
// Assert expectancies called in TearDown()
}
[Test]
public void ContextMenuStrip_NestedCalculationGroup_AddCustomItems()
{
// Setup
var group = new CalculationGroup();
var parentGroup = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var groupContext = new HeightStructuresCalculationGroupContext(group,
parentGroup,
failureMechanism,
assessmentSection);
var parentGroupContext = new HeightStructuresCalculationGroupContext(parentGroup,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl))
{
// Assert
Assert.AreEqual(22, menu.Items.Count);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuDuplicateIndexNestedGroup,
"D&upliceren",
"Dupliceer dit element.",
RingtoetsCommonFormsResources.CopyHS);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationGroupIndexNestedGroup,
"&Map toevoegen",
"Voeg een nieuwe map toe aan deze map met berekeningen.",
RingtoetsCommonFormsResources.AddFolderIcon);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuAddCalculationIndexNestedGroup,
"Berekening &toevoegen",
"Voeg een nieuwe berekening toe aan deze map met berekeningen.",
RingtoetsCommonFormsResources.FailureMechanismIcon);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndexNestedGroup,
"&Bijwerken voorlandprofielen...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu,
contextMenuUpdateStructureAllIndexNestedGroup,
"&Bijwerken kunstwerken...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexNestedGroup,
"Alles &valideren",
"Er zijn geen berekeningen om te valideren.",
RingtoetsCommonFormsResources.ValidateAllIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexNestedGroup,
"Alles be&rekenen",
"Er zijn geen berekeningen om uit te voeren.",
RingtoetsCommonFormsResources.CalculateAllIcon,
false);
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearAllIndexNestedGroup,
"&Wis alle uitvoer...",
"Er zijn geen berekeningen met uitvoer om te wissen.",
RingtoetsCommonFormsResources.ClearIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_HydraulicBoundaryDatabaseNotCoupled_ContextMenuItemCalculateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks);
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndexRootGroup,
"Alles be&rekenen",
"Er is geen hydraulische randvoorwaardendatabase geïmporteerd.",
RingtoetsCommonFormsResources.CalculateAllIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_HydraulicBoundaryDatabaseCoupledToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath");
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateAllIndexRootGroup];
Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text);
StringAssert.Contains("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. ", contextMenuItem.ToolTipText);
TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculateAllIcon, contextMenuItem.Image);
Assert.IsFalse(contextMenuItem.Enabled);
}
}
}
[Test]
public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemCalculateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath,
Version = "1.0"
});
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup,
"Alles be&rekenen",
"De bijdrage van dit toetsspoor is nul.",
RingtoetsCommonFormsResources.CalculateAllIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath,
Version = "1.0"
});
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateAllIndexRootGroup,
"Alles be&rekenen",
"Voer alle berekeningen binnen deze map met berekeningen uit.",
RingtoetsCommonFormsResources.CalculateAllIcon);
}
}
}
[Test]
public void ContextMenuStrip_HydraulicBoundaryDatabaseNotCoupled_ContextMenuItemValidateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks);
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndexRootGroup,
"Alles &valideren",
"Er is geen hydraulische randvoorwaardendatabase geïmporteerd.",
RingtoetsCommonFormsResources.ValidateAllIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_HydraulicBoundaryDatabaseCoupledToInvalidFile_ContextMenuItemValidateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath");
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateAllIndexRootGroup];
Assert.AreEqual("Alles &valideren", contextMenuItem.Text);
StringAssert.Contains("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. ", contextMenuItem.ToolTipText);
TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ValidateAllIcon, contextMenuItem.Image);
Assert.IsFalse(contextMenuItem.Enabled);
}
}
}
[Test]
public void ContextMenuStrip_FailureMechanismContributionZero_ContextMenuItemValidateAllDisabledAndTooltipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath,
Version = "1.0"
});
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup,
"Alles &valideren",
"De bijdrage van dit toetsspoor is nul.",
RingtoetsCommonFormsResources.ValidateAllIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateAllEnabled()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation());
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath,
Version = "1.0"
});
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateAllIndexRootGroup,
"Alles &valideren",
"Valideer alle berekeningen binnen deze map met berekeningen.",
RingtoetsCommonFormsResources.ValidateAllIcon);
}
}
}
[Test]
public void ContextMenuStrip_CalculationGroupWithCalculationWithForeshoreProfileAndInputOutOfSync_ContextMenuItemUpdateForeshoreProfilesEnabledAndToolTipSet()
{
// Setup
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks);
var failureMechanism = new TestHeightStructuresFailureMechanism();
var calculation = new StructuresCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile()
}
};
var nodeData = new HeightStructuresCalculationGroupContext(
new CalculationGroup
{
Children =
{
calculation
}
},
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
plugin.Gui = gui;
calculation.InputParameters.UseBreakWater = true;
// Call
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(menu,
contextMenuUpdateForeshoreProfileIndexRootGroup,
"&Bijwerken voorlandprofielen...",
"Alle berekeningen met een voorlandprofiel bijwerken.",
RingtoetsCommonFormsResources.UpdateItemIcon);
}
}
}
[Test]
public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateForeshoreProfilesClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified()
{
// Given
var calculationObserver = mocks.StrictMock();
var calculationInputObserver = mocks.StrictMock();
calculationInputObserver.Expect(o => o.UpdateObserver());
IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(mocks);
var failureMechanism = new TestHeightStructuresFailureMechanism();
var calculation = new StructuresCalculation
{
InputParameters =
{
ForeshoreProfile = new TestForeshoreProfile(true)
}
};
var nodeData = new HeightStructuresCalculationGroupContext(
new CalculationGroup
{
Children =
{
calculation
}
},
null,
failureMechanism,
assessmentSection);
calculation.Attach(calculationObserver);
calculation.InputParameters.Attach(calculationInputObserver);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
plugin.Gui = gui;
calculation.InputParameters.UseBreakWater = false;
using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// When
contextMenuStrip.Items[contextMenuUpdateForeshoreProfileIndexRootGroup].PerformClick();
// Then
Assert.IsTrue(calculation.InputParameters.IsForeshoreProfileInputSynchronized);
}
}
}
[Test]
public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations()
{
// Setup
var mainWindow = mocks.Stub();
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculation
{
Name = "A",
InputParameters =
{
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
});
failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculation
{
Name = "B",
InputParameters =
{
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
});
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.Id).Return(string.Empty);
assessmentSection.Stub(a => a.FailureMechanismContribution).Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath
});
var groupContext = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mainWindow);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
int nrOfCalculators = failureMechanism.Calculations.Count();
var calculatorFactory = mocks.Stub();
calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath, string.Empty))
.Return(new TestStructuresCalculator())
.Repeat
.Times(nrOfCalculators);
mocks.ReplayAll();
DialogBoxHandler = (name, wnd) =>
{
// Expect an activity dialog which is automatically closed
};
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl))
using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
{
// Call
TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndexRootGroup].PerformClick(), messages =>
{
List messageList = messages.ToList();
// Assert
Assert.AreEqual(14, messageList.Count);
Assert.AreEqual("Uitvoeren van berekening 'A' is gestart.", messageList[0]);
CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[4]);
CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]);
Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[6]);
CalculationServiceTestHelper.AssertValidationStartMessage(messageList[7]);
CalculationServiceTestHelper.AssertValidationEndMessage(messageList[8]);
CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[9]);
StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", messageList[10]);
CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[11]);
Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[12]);
Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]);
});
}
}
}
[Test]
public void ContextMenuStrip_ClickOnValidateAllItem_ScheduleAllChildCalculations()
{
// Setup
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var failureMechanism = new TestHeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculation
{
Name = "A",
InputParameters =
{
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
});
failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculation
{
Name = "B",
InputParameters =
{
HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation()
}
});
string validFilePath = Path.Combine(testDataPath, "complete.sqlite");
var assessmentSection = mocks.Stub();
assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
{
FilePath = validFilePath
});
var groupContext = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(groupContext, null, treeViewControl))
{
// Call
TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuValidateAllIndexRootGroup].PerformClick(), messages =>
{
List messageList = messages.ToList();
// Assert
Assert.AreEqual(4, messageList.Count);
CalculationServiceTestHelper.AssertValidationStartMessage(messageList[0]);
CalculationServiceTestHelper.AssertValidationEndMessage(messageList[1]);
CalculationServiceTestHelper.AssertValidationStartMessage(messageList[2]);
CalculationServiceTestHelper.AssertValidationEndMessage(messageList[3]);
});
}
}
}
[Test]
public void ContextMenuStrip_ClickOnAddGroupItem_AddGroupToCalculationGroupAndNotifyObservers()
{
// Setup
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var calculationGroup = new CalculationGroup
{
Name = "Nieuwe map"
};
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
group.Children.Add(calculationGroup);
nodeData.Attach(observer);
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Precondition
Assert.AreEqual(1, group.Children.Count);
// Call
contextMenu.Items[contextMenuAddCalculationGroupIndexRootGroup].PerformClick();
// Assert
Assert.AreEqual(2, group.Children.Count);
ICalculationBase newlyAddedItem = group.Children.Last();
Assert.IsInstanceOf(newlyAddedItem);
Assert.AreEqual("Nieuwe map (1)", newlyAddedItem.Name,
"An item with the same name default name already exists, therefore '(1)' needs to be appended.");
}
}
}
[Test]
public void ContextMenuStrip_ClickOnAddCalculationItem_AddCalculationToCalculationGroupAndNotifyObservers()
{
// Setup
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
var calculation = new StructuresCalculation
{
Name = "Nieuwe berekening"
};
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.ViewCommands).Return(mocks.Stub());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
group.Children.Add(calculation);
nodeData.Attach(observer);
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Precondition
Assert.AreEqual(1, group.Children.Count);
// Call
contextMenu.Items[contextMenuAddCalculationIndexRootGroup].PerformClick();
// Assert
Assert.AreEqual(2, group.Children.Count);
ICalculationBase newlyAddedItem = group.Children.Last();
Assert.IsInstanceOf>(newlyAddedItem);
Assert.AreEqual("Nieuwe berekening (1)", newlyAddedItem.Name,
"An item with the same name default name already exists, therefore '(1)' needs to be appended.");
}
}
}
[Test]
public void ContextMenuStrip_CalculationGroupWithoutCalculations_ContextMenuItemUpdateStructuresDisabledAndToolTipSet()
{
// Setup
var group = new CalculationGroup();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateStructureAllIndexRootGroup,
"&Bijwerken kunstwerken...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutStructure_ContextMenuItemUpdateStructuresDisabledAndToolTipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
};
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateStructureAllIndexRootGroup,
"&Bijwerken kunstwerken...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_CalculationGroupWithCalculationWithStructureAndInputInSync_ContextMenuItemUpdateStructuresDisabledAndToolTipSet()
{
// Setup
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation
{
InputParameters =
{
Structure = new TestHeightStructure()
}
}
}
};
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateStructureAllIndexRootGroup,
"&Bijwerken kunstwerken...",
"Er zijn geen berekeningen om bij te werken.",
RingtoetsCommonFormsResources.UpdateItemIcon,
false);
}
}
}
[Test]
public void ContextMenuStrip_CalculationGroupWithCalculationWithStructureAndInputOutOfSync_ContextMenuItemUpdateStructuresEnabledAndToolTipSet()
{
// Setup
var testHeightStructure = new TestHeightStructure();
var group = new CalculationGroup
{
Children =
{
new StructuresCalculation
{
InputParameters =
{
Structure = testHeightStructure
}
}
}
};
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var nodeData = new HeightStructuresCalculationGroupContext(group,
null,
failureMechanism,
assessmentSection);
using (var treeViewControl = new TreeViewControl())
{
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mocks.Stub());
mocks.ReplayAll();
ChangeStructure(testHeightStructure);
// Call
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// Assert
TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuUpdateStructureAllIndexRootGroup,
"&Bijwerken kunstwerken...",
"Alle berekeningen met een kunstwerk bijwerken.",
RingtoetsCommonFormsResources.UpdateItemIcon);
}
}
}
[Test]
public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructuresClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified()
{
// Given
var assessmentSection = mocks.Stub();
var structure = new TestHeightStructure();
var calculation = new StructuresCalculation
{
InputParameters =
{
Structure = structure
}
};
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(calculation);
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, null, failureMechanism, assessmentSection);
var inputObserver = mocks.StrictMock();
inputObserver.Expect(obs => obs.UpdateObserver());
calculation.InputParameters.Attach(inputObserver);
var calculationObserver = mocks.StrictMock();
calculation.Attach(calculationObserver);
using (var treeViewControl = new TreeViewControl())
{
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mainWindow);
mocks.ReplayAll();
ChangeStructure(structure);
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl))
{
// When
menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick();
// Then
Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized);
// Note: observer assertions are verified in the TearDown()
}
}
}
[Test]
public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified()
{
// Given
var assessmentSection = mocks.Stub();
var structure = new TestHeightStructure();
var calculation = new StructuresCalculation
{
InputParameters =
{
Structure = structure
},
Output = new TestStructuresOutput()
};
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(calculation);
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, null, failureMechanism, assessmentSection);
var inputObserver = mocks.StrictMock();
calculation.InputParameters.Attach(inputObserver);
var calculationObserver = mocks.StrictMock();
calculation.Attach(calculationObserver);
string textBoxMessage = null;
DialogBoxHandler = (name, wnd) =>
{
var helper = new MessageBoxTester(wnd);
textBoxMessage = helper.Text;
helper.ClickCancel();
};
using (var treeViewControl = new TreeViewControl())
{
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mainWindow);
mocks.ReplayAll();
ChangeStructure(structure);
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl))
{
// When
menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick();
// Then
Assert.IsTrue(calculation.HasOutput);
Assert.IsFalse(calculation.InputParameters.IsStructureInputSynchronized);
string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " +
$"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
Assert.AreEqual(expectedMessage, textBoxMessage);
// Note: observer assertions are verified in the TearDown()
}
}
}
[Test]
public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructuresClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified()
{
// Given
var assessmentSection = mocks.Stub();
var structure = new TestHeightStructure();
var calculation = new StructuresCalculation
{
InputParameters =
{
Structure = structure
},
Output = new TestStructuresOutput()
};
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.CalculationsGroup.Children.Add(calculation);
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup, null, failureMechanism, assessmentSection);
var inputObserver = mocks.StrictMock();
inputObserver.Expect(obs => obs.UpdateObserver());
calculation.InputParameters.Attach(inputObserver);
var calculationObserver = mocks.StrictMock();
calculationObserver.Expect(obs => obs.UpdateObserver());
calculation.Attach(calculationObserver);
string textBoxMessage = null;
DialogBoxHandler = (name, wnd) =>
{
var helper = new MessageBoxTester(wnd);
textBoxMessage = helper.Text;
helper.ClickOk();
};
using (var treeViewControl = new TreeViewControl())
{
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
gui.Stub(g => g.MainWindow).Return(mainWindow);
mocks.ReplayAll();
ChangeStructure(structure);
using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl))
{
// When
menu.Items[contextMenuUpdateStructureAllIndexRootGroup].PerformClick();
// Then
Assert.IsFalse(calculation.HasOutput);
Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized);
string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van alle bij te werken berekeningen " +
$"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
Assert.AreEqual(expectedMessage, textBoxMessage);
// Note: observer assertions are verified in the TearDown()
}
}
}
[Test]
public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenHeightStructureSelectedAndDialogClosed_ThenCalculationsAddedWithHeightStructureAssigned()
{
// Given
using (var treeViewControl = new TreeViewControl())
{
var assessmentSection = mocks.Stub();
HeightStructure structure1 = new TestHeightStructure("Structure Id", "Structure 1");
var existingCalculationGroup = new CalculationGroup();
var existingCalculation = new StructuresCalculation();
var failureMechanism = new HeightStructuresFailureMechanism
{
CalculationsGroup =
{
Children =
{
existingCalculationGroup,
existingCalculation
}
}
};
failureMechanism.HeightStructures.AddRange(new[]
{
structure1,
new TestHeightStructure()
}, "some path");
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mainWindow);
gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
mocks.ReplayAll();
DialogBoxHandler = (name, wnd) =>
{
var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject;
var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject;
grid.Rows[0].Cells[0].Value = true;
new ButtonTester("DoForSelectedButton", selectionDialog).Click();
};
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// When
contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick();
// Then
Assert.AreEqual(3, failureMechanism.CalculationsGroup.Children.Count);
Assert.AreSame(existingCalculationGroup, failureMechanism.CalculationsGroup.Children[0]);
Assert.AreSame(existingCalculation, failureMechanism.CalculationsGroup.Children[1]);
var generatedCalculation = failureMechanism.CalculationsGroup.Children[2] as StructuresCalculation;
Assert.IsNotNull(generatedCalculation);
Assert.AreSame(structure1, generatedCalculation.InputParameters.Structure);
}
}
}
[Test]
public void GivenCalculationsViewGenerateScenariosButtonClicked_WhenCancelButtonClickedAndDialogClosed_ThenCalculationsNotUpdated()
{
// Given
using (var treeViewControl = new TreeViewControl())
{
var assessmentSection = mocks.Stub();
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.HeightStructures.AddRange(
new[]
{
new TestHeightStructure("1", "Structure 1"),
new TestHeightStructure("2", "Structure 2")
}, "some path"
);
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mainWindow);
gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
mocks.ReplayAll();
DialogBoxHandler = (name, wnd) =>
{
var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject;
var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject;
grid.Rows[0].Cells[0].Value = true;
new ButtonTester("CustomCancelButton", selectionDialog).Click();
};
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
// When
contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick();
// Then
Assert.AreEqual(0, failureMechanism.Calculations.OfType>().Count());
}
}
}
[Test]
public void GivenScenariosWithExistingCalculationWithSameName_WhenOkButtonClickedAndDialogClosed_ThenCalculationWithUniqueNameAdded()
{
// Given
using (var treeViewControl = new TreeViewControl())
{
var assessmentSection = mocks.Stub();
const string existingCalculationName = "Height structure";
HeightStructure heightStructure = new TestHeightStructure("heightStructureId", existingCalculationName);
var failureMechanism = new HeightStructuresFailureMechanism
{
CalculationsGroup =
{
Children =
{
new StructuresCalculation
{
Name = existingCalculationName
}
}
}
};
failureMechanism.HeightStructures.AddRange(new[]
{
heightStructure,
new TestHeightStructure()
}, "some path");
var nodeData = new HeightStructuresCalculationGroupContext(failureMechanism.CalculationsGroup,
null,
failureMechanism,
assessmentSection);
var menuBuilder = new CustomItemsOnlyContextMenuBuilder();
var mainWindow = mocks.Stub();
gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder);
gui.Stub(g => g.MainWindow).Return(mainWindow);
gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub());
mocks.ReplayAll();
DialogBoxHandler = (name, wnd) =>
{
var selectionDialog = (StructureSelectionDialog) new FormTester(name).TheObject;
var grid = (DataGridViewControl) new ControlTester("DataGridViewControl", selectionDialog).TheObject;
grid.Rows[0].Cells[0].Value = true;
new ButtonTester("DoForSelectedButton", selectionDialog).Click();
};
using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
{
string expectedNewName = NamingHelper.GetUniqueName(failureMechanism.CalculationsGroup.Children, existingCalculationName, c => c.Name);
// When
contextMenu.Items[contextMenuGenerateCalculationsIndexRootGroup].PerformClick();
// Then
StructuresCalculation[] heightStructuresCalculations = failureMechanism.Calculations.OfType>().ToArray();
Assert.AreEqual(2, heightStructuresCalculations.Length);
Assert.AreEqual(expectedNewName, heightStructuresCalculations[1].Name);
}
}
}
[Test]
public void OnNodeRemoved_NestedCalculationGroup_RemoveGroupAndNotifyObservers()
{
// Setup
var observer = mocks.StrictMock();
var failureMechanism = new HeightStructuresFailureMechanism();
var assessmentSection = mocks.Stub();
var group = new CalculationGroup();
var parentGroup = new CalculationGroup();
var nodeData = new HeightStructuresCalculationGroupContext(group,
parentGroup,
failureMechanism,
assessmentSection);
var parentNodeData = new HeightStructuresCalculationGroupContext(parentGroup,
null,
failureMechanism,
assessmentSection);
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
parentGroup.Children.Add(group);
parentNodeData.Attach(observer);
// Precondition
Assert.IsTrue(info.CanRemove(nodeData, parentNodeData));
// Call
info.OnNodeRemoved(nodeData, parentNodeData);
// Assert
CollectionAssert.DoesNotContain(parentGroup.Children, group);
}
[Test]
public void OnNodeRemoved_CalculationInGroupAssignedToSection_CalculationDetachedFromSection()
{
// Setup
var failureMechanism = new HeightStructuresFailureMechanism();
failureMechanism.AddSection(new FailureMechanismSection("section", new[]
{
new Point2D(0, 0)
}));
var assessmentSection = mocks.Stub();
var group = new CalculationGroup();
var parentGroup = new CalculationGroup();
var nodeData = new HeightStructuresCalculationGroupContext(group,
parentGroup,
failureMechanism,
assessmentSection);
var parentNodeData = new HeightStructuresCalculationGroupContext(parentGroup,
null,
failureMechanism,
assessmentSection);
mocks.ReplayAll();
parentGroup.Children.Add(group);
var calculation = new StructuresCalculation();
group.Children.Add(calculation);
HeightStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First();
result.Calculation = calculation;
// Call
info.OnNodeRemoved(nodeData, parentNodeData);
// Assert
Assert.IsNull(result.Calculation);
}
[Test]
public void OnNodeRemoved_NestedCalculationGroupContainingCalculations_RemoveGroupAndCalculationsAndNotifyObservers()
{
// Setup
var observer = mocks.StrictMock();
var assessmentSection = mocks.Stub();
var failureMechanism = new HeightStructuresFailureMechanism();
var group = new CalculationGroup();
var parentGroup = new CalculationGroup();
var nodeData = new HeightStructuresCalculationGroupContext(group,
parentGroup,
failureMechanism,
assessmentSection);
var parentNodeData = new HeightStructuresCalculationGroupContext(parentGroup,
null,
failureMechanism,
assessmentSection);
var calculation = new StructuresCalculation();
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
group.Children.Add(calculation);
parentGroup.Children.Add(group);
parentNodeData.Attach(observer);
// Precondition
Assert.IsTrue(info.CanRemove(nodeData, parentNodeData));
// Call
info.OnNodeRemoved(nodeData, parentNodeData);
// Assert
CollectionAssert.DoesNotContain(parentGroup.Children, group);
}
private static void ChangeStructure(HeightStructure structure)
{
structure.CopyProperties(new HeightStructure(
new HeightStructure.ConstructionProperties
{
Id = structure.Id,
Name = structure.Name,
Location = structure.Location
}));
}
}
}