Fisheye: Tag 3cbba23100bde03baa7b08ea535b779bcb7ddf13 refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PresentationObjects/HeightStructuresCalculationContext.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PresentationObjects/HeightStructuresCalculationScenarioContext.cs =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PresentationObjects/HeightStructuresCalculationScenarioContext.cs (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PresentationObjects/HeightStructuresCalculationScenarioContext.cs (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -0,0 +1,50 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.HeightStructures.Data; + +namespace Riskeer.HeightStructures.Forms.PresentationObjects +{ + /// + /// Presentation object for all data required to configure a height structures calculation. + /// + public class HeightStructuresCalculationScenarioContext : StructuresCalculationContext + { + /// + /// Creates a new instance of . + /// + /// The calculation instance wrapped by this context object. + /// The that owns the wrapped calculation. + /// The failure mechanism which the context belongs to. + /// The assessment section which the calculation belongs to. + /// Thrown when any input argument is null. + public HeightStructuresCalculationScenarioContext(StructuresCalculation calculation, + CalculationGroup parent, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, parent, failureMechanism, assessmentSection) {} + } +} \ No newline at end of file Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rfd673124da33a65fc510d7b04acbb930de2a3b0e -r3cbba23100bde03baa7b08ea535b779bcb7ddf13 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision fd673124da33a65fc510d7b04acbb930de2a3b0e) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -151,7 +151,7 @@ context => context.WrappedData.Children.Any(), GetInquiryHelper()); - yield return RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo( + yield return RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo( (context, filePath) => new HeightStructuresCalculationConfigurationExporter(new[] { context.WrappedData @@ -211,7 +211,7 @@ CalculationGroupContextContextMenuStrip, CalculationGroupContextOnNodeRemoved); - yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( + yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( CalculationContextChildNodeObjects, CalculationContextContextMenuStrip, CalculationContextOnNodeRemoved); @@ -463,10 +463,10 @@ if (calculation != null) { - childNodeObjects.Add(new HeightStructuresCalculationContext(calculation, - context.WrappedData, - context.FailureMechanism, - context.AssessmentSection)); + childNodeObjects.Add(new HeightStructuresCalculationScenarioContext(calculation, + context.WrappedData, + context.FailureMechanism, + context.AssessmentSection)); } else if (group != null) { @@ -690,7 +690,7 @@ #region HeightStructuresCalculationContext TreeNodeInfo - private static object[] CalculationContextChildNodeObjects(HeightStructuresCalculationContext context) + private static object[] CalculationContextChildNodeObjects(HeightStructuresCalculationScenarioContext context) { StructuresCalculation calculation = context.WrappedData; @@ -705,7 +705,7 @@ }; } - private ContextMenuStrip CalculationContextContextMenuStrip(HeightStructuresCalculationContext context, + private ContextMenuStrip CalculationContextContextMenuStrip(HeightStructuresCalculationScenarioContext context, object parentData, TreeViewControl treeViewControl) { @@ -743,24 +743,24 @@ .Build(); } - private static string EnableValidateAndCalculateMenuItemForCalculation(HeightStructuresCalculationContext context) + private static string EnableValidateAndCalculateMenuItemForCalculation(HeightStructuresCalculationScenarioContext context) { return EnableValidateAndCalculateMenuItem(context.AssessmentSection); } - private static void Validate(HeightStructuresCalculationContext context) + private static void Validate(HeightStructuresCalculationScenarioContext context) { HeightStructuresCalculationService.Validate(context.WrappedData, context.AssessmentSection); } - private void Calculate(StructuresCalculation calculation, HeightStructuresCalculationContext context) + private void Calculate(StructuresCalculation calculation, HeightStructuresCalculationScenarioContext context) { ActivityProgressDialogRunner.Run( Gui.MainWindow, HeightStructuresCalculationActivityFactory.CreateCalculationActivity(calculation, context.FailureMechanism, context.AssessmentSection)); } - private static void CalculationContextOnNodeRemoved(HeightStructuresCalculationContext context, object parentData) + private static void CalculationContextOnNodeRemoved(HeightStructuresCalculationScenarioContext context, object parentData) { if (parentData is HeightStructuresCalculationGroupContext calculationGroupContext) { @@ -770,7 +770,7 @@ } } - private StrictContextMenuItem CreateUpdateStructureItem(HeightStructuresCalculationContext context) + private StrictContextMenuItem CreateUpdateStructureItem(HeightStructuresCalculationScenarioContext context) { var contextMenuEnabled = true; string toolTipMessage = RiskeerCommonFormsResources.Update_Calculation_with_Structure_ToolTip; Fisheye: Tag 3cbba23100bde03baa7b08ea535b779bcb7ddf13 refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationContextTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationScenarioContextTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationScenarioContextTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PresentationObjects/HeightStructuresCalculationScenarioContextTest.cs (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -0,0 +1,91 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Forms.PresentationObjects; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Forms.PresentationObjects; + +namespace Riskeer.HeightStructures.Forms.Test.PresentationObjects +{ + [TestFixture] + public class HeightStructuresCalculationScenarioContextTest + { + [Test] + public void ConstructorWithData_Always_ExpectedPropertiesSet() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new StructuresCalculation(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + + // Call + var context = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf>(context); + Assert.AreSame(calculation, context.WrappedData); + Assert.AreSame(parent, context.Parent); + Assert.AreSame(failureMechanism, context.FailureMechanism); + Assert.AreSame(assessmentSection, context.AssessmentSection); + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToDerivedObject_ReturnsFalse() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new StructuresCalculation(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var context = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var derivedContext = new DerivedHeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(derivedContext); + + // Assert + Assert.IsFalse(isEqual); + mocksRepository.VerifyAll(); + } + + private class DerivedHeightStructuresCalculationScenarioContext : HeightStructuresCalculationScenarioContext + { + public DerivedHeightStructuresCalculationScenarioContext(StructuresCalculation calculation, + CalculationGroup parent, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, parent, failureMechanism, assessmentSection) {} + } + } +} \ No newline at end of file Fisheye: Tag 3cbba23100bde03baa7b08ea535b779bcb7ddf13 refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationContextExportInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationScenarioContextExportInfoTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationScenarioContextExportInfoTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ExportInfos/HeightStructuresCalculationScenarioContextExportInfoTest.cs (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -0,0 +1,123 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.IO; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Data.TestUtil; +using Riskeer.HeightStructures.Forms.PresentationObjects; +using Riskeer.HeightStructures.IO.Configurations; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Riskeer.HeightStructures.Plugin.Test.ExportInfos +{ + [TestFixture] + public class HeightStructuresCalculationScenarioContextExportInfoTest + { + private HeightStructuresPlugin plugin; + private ExportInfo info; + private MockRepository mocks; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + var mainWindow = mocks.Stub(); + var gui = mocks.Stub(); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.Replay(gui); + mocks.Replay(mainWindow); + + plugin = new HeightStructuresPlugin + { + Gui = gui + }; + + info = plugin.GetExportInfos().First(ei => ei.DataType == typeof(HeightStructuresCalculationScenarioContext)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.IsNotNull(info.CreateFileExporter); + Assert.IsNotNull(info.IsEnabled); + Assert.AreEqual("Riskeer berekeningenconfiguratie", info.Name); + Assert.AreEqual("xml", info.Extension); + Assert.AreEqual("Algemeen", info.Category); + TestHelper.AssertImagesAreEqual(CoreCommonGuiResources.ExportIcon, info.Image); + Assert.IsNotNull(info.GetExportPath); + } + + [Test] + public void CreateFileExporter_Always_ReturnFileExporter() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationScenarioContext(new TestHeightStructuresCalculation(), + new CalculationGroup(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + // Call + IFileExporter fileExporter = info.CreateFileExporter(context, "test"); + + // Assert + Assert.IsInstanceOf(fileExporter); + } + + [Test] + public void IsEnabled_Always_ReturnTrue() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var context = new HeightStructuresCalculationScenarioContext(new TestHeightStructuresCalculation(), + new CalculationGroup(), + new HeightStructuresFailureMechanism(), + assessmentSection); + + // Call + bool isEnabled = info.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + } +} \ No newline at end of file Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r277b8107bf8ffad7dad7fa6dbb75cdb23a0feee2 -r3cbba23100bde03baa7b08ea535b779bcb7ddf13 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 277b8107bf8ffad7dad7fa6dbb75cdb23a0feee2) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -104,7 +104,7 @@ Assert.AreEqual(8, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresFailureMechanismContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCalculationGroupContext))); - Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCalculationContext))); + Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresCalculationScenarioContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresInputContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructuresContext))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(HeightStructure))); @@ -196,7 +196,7 @@ // Assert Assert.AreEqual(2, exportInfos.Length); Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(HeightStructuresCalculationGroupContext))); - Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(HeightStructuresCalculationContext))); + Assert.IsTrue(exportInfos.Any(tni => tni.DataType == typeof(HeightStructuresCalculationScenarioContext))); } mocks.VerifyAll(); Fisheye: Tag 3cbba23100bde03baa7b08ea535b779bcb7ddf13 refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r56d072b8342f3e54ba89124ab918bd1529e257a3 -r3cbba23100bde03baa7b08ea535b779bcb7ddf13 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 56d072b8342f3e54ba89124ab918bd1529e257a3) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -166,7 +166,7 @@ Assert.AreSame(failureMechanism, calculationGroupContext.FailureMechanism); Assert.AreSame(assessmentSection, calculationGroupContext.AssessmentSection); Assert.AreSame(calculationItem, children[1]); - var calculationContext = (HeightStructuresCalculationContext) children[2]; + var calculationContext = (HeightStructuresCalculationScenarioContext) children[2]; Assert.AreSame(childCalculation, calculationContext.WrappedData); Assert.AreSame(group, calculationContext.Parent); Assert.AreSame(assessmentSection, calculationContext.AssessmentSection); Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationScenarioContextTreeNodeInfoTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationScenarioContextTreeNodeInfoTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationScenarioContextTreeNodeInfoTest.cs (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -0,0 +1,1470 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Drawing; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.TreeView; +using Core.Common.Gui; +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 Riskeer.Common.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Data.TestUtil.IllustrationPoints; +using Riskeer.Common.Service.TestUtil; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Data.TestUtil; +using Riskeer.HeightStructures.Forms.PresentationObjects; +using Riskeer.HydraRing.Calculation.Calculator.Factory; +using Riskeer.HydraRing.Calculation.Data.Input; +using Riskeer.HydraRing.Calculation.Data.Input.Structures; +using Riskeer.HydraRing.Calculation.TestUtil.Calculator; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.HeightStructures.Plugin.Test.TreeNodeInfos +{ + [TestFixture] + public class HeightStructuresCalculationScenarioContextTreeNodeInfoTest : NUnitFormTest + { + private const int contextMenuDuplicateIndex = 2; + private const int contextMenuUpdateForeshoreProfileIndex = 5; + private const int contextMenuUpdateStructureIndex = 6; + private const int contextMenuValidateIndex = 8; + private const int contextMenuCalculateIndex = 9; + private const int contextMenuClearIndex = 11; + private const int contextMenuClearIllustrationPointsIndex = 12; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, nameof(HydraulicBoundaryDatabase)); + + private MockRepository mocks; + private HeightStructuresPlugin plugin; + private TreeNodeInfo info; + + [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.CheckedState); + Assert.IsNull(info.OnNodeChecked); + Assert.IsNotNull(info.CanDrag); + Assert.IsNull(info.CanDrop); + Assert.IsNull(info.CanInsert); + Assert.IsNull(info.OnDrop); + } + + [Test] + public void Image_Always_ReturnsCalculationIcon() + { + // Setup + mocks.ReplayAll(); + + // Call + Image image = info.Image(null); + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculationIcon, image); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ChildNodeObjects_Always_ReturnsChildrenOfData(bool hasOutput) + { + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + Output = hasOutput ? new TestStructuresOutput() : null + }; + + var calculationContext = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + object[] children = info.ChildNodeObjects(calculationContext).ToArray(); + + // Assert + Assert.AreEqual(3, children.Length); + + var comment = children[0] as Comment; + Assert.AreSame(calculationContext.WrappedData.Comments, comment); + + var heightStructuresInputContext = children[1] as HeightStructuresInputContext; + Assert.IsNotNull(heightStructuresInputContext); + Assert.AreSame(calculationContext.WrappedData.InputParameters, heightStructuresInputContext.WrappedData); + + var structuresOutputContext = children[2] as HeightStructuresOutputContext; + Assert.IsNotNull(structuresOutputContext); + Assert.AreSame(calculationContext.WrappedData, structuresOutputContext.WrappedData); + Assert.AreSame(calculationContext.FailureMechanism, structuresOutputContext.FailureMechanism); + Assert.AreSame(calculationContext.AssessmentSection, structuresOutputContext.AssessmentSection); + } + + [Test] + public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + 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.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.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()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + info.ContextMenuStrip(nodeData, null, treeViewControl); + } + + // Assert + // Assert expectancies are called in TearDown() + } + + [Test] + public void ContextMenuStrip_Always_AddCustomItems() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + Assert.AreEqual(19, menu.Items.Count); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuDuplicateIndex, + "D&upliceren", + "Dupliceer dit element.", + RiskeerCommonFormsResources.CopyHS); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Er moet een voorlandprofiel geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er moet een kunstwerk geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuValidateIndex, + "&Valideren", + "Valideer de invoer voor deze berekening.", + RiskeerCommonFormsResources.ValidateIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuCalculateIndex, + "Be&rekenen", + "Voer deze berekening uit.", + RiskeerCommonFormsResources.CalculateIcon); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIndex, + "&Wis uitvoer...", + "Deze berekening heeft geen uitvoer om te wissen.", + RiskeerCommonFormsResources.ClearIcon, + false); + + TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuClearIllustrationPointsIndex, + "Wis illustratiepunten...", + "Deze berekening heeft geen illustratiepunten om te wissen.", + RiskeerCommonFormsResources.ClearIllustrationPointsIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithoutStructure_ContextMenuItemUpdateStructureDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er moet een kunstwerk geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithStructureAndInputInSync_ContextMenuItemUpdateStructureDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestHeightStructure() + } + }; + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Er zijn geen wijzigingen om bij te werken.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithStructureAndInputOutOfSync_ContextMenuItemUpdateStructureEnabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = new TestHeightStructure() + } + }; + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + ChangeStructure(calculation.InputParameters.Structure); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(menu, + contextMenuUpdateStructureIndex, + "&Bijwerken kunstwerk...", + "Berekening bijwerken met het kunstwerk.", + RiskeerCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateStructureClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var structure = new TestHeightStructure(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + } + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, 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(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeStructure(structure); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized); + + // Note: observer assertions are verified in the TearDown() + } + } + } + + [Test] + public void GivenCalculationWithOutputAndInputOutOfSync_WhenUpdateStructureClickedAndCancelled_ThenInquiryAndCalculationNotUpdatedAndObserversNotNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var structure = new TestHeightStructure(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, 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(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeStructure(structure); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.HasOutput); + Assert.IsFalse(calculation.InputParameters.IsStructureInputSynchronized); + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"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_WhenUpdateStructureClickedAndContinued_ThenInquiryAndCalculationUpdatedAndObserversNotified() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var structure = new TestHeightStructure(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + Structure = structure + }, + Output = new TestStructuresOutput() + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, 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(); + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + mocks.ReplayAll(); + + plugin.Gui = gui; + + ChangeStructure(structure); + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuUpdateStructureIndex].PerformClick(); + + // Then + Assert.IsFalse(calculation.HasOutput); + Assert.IsTrue(calculation.InputParameters.IsStructureInputSynchronized); + + string expectedMessage = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"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 ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + "Be&rekenen", + "Er is geen hydraulische belastingendatabase geïmporteerd.", + RiskeerCommonFormsResources.CalculateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemPerformCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuCalculateIndex]; + + Assert.AreEqual("Be&rekenen", contextMenuItem.Text); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemPerformCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateIndex, + "Be&rekenen", + "Voer deze berekening uit.", + RiskeerCommonFormsResources.CalculateIcon); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + "&Valideren", + "Er is geen hydraulische belastingendatabase geïmporteerd.", + RiskeerCommonFormsResources.ValidateIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemValidateCalculationDisabledAndTooltipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateIndex]; + + Assert.AreEqual("&Valideren", contextMenuItem.Text); + StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ValidateIcon, contextMenuItem.Image); + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateCalculationEnabled() + { + // Setup + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "1.0" + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateIndex, + "&Valideren", + "Valideer de invoer voor deze berekening.", + RiskeerCommonFormsResources.ValidateIcon); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithoutForeshoreProfile_ContextMenuItemUpdateForeshoreProfileDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation(); + + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, + parent, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Er moet een voorlandprofiel geselecteerd zijn.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithForeshoreProfileAndInputInSync_ContextMenuItemUpdateForeshoreProfileDisabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile() + } + }; + + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, + parent, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Er zijn geen wijzigingen om bij te werken.", + RiskeerCommonFormsResources.UpdateItemIcon, + false); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithForeshoreProfileAndInputOutSync_ContextMenuItemUpdateForeshoreProfileEnabledAndToolTipSet() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + + var foreshoreProfileInput = new TestForeshoreProfile(); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfileInput + } + }; + TestForeshoreProfile.ChangeBreakWaterProperties(foreshoreProfileInput); + + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, + parent, + failureMechanism, + assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Assert + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Berekening bijwerken met het voorlandprofiel.", + RiskeerCommonFormsResources.UpdateItemIcon); + } + } + } + + [Test] + public void GivenCalculationWithoutOutputAndWithInputOutOfSync_WhenUpdateForeshoreProfileClicked_ThenNoInquiryAndCalculationUpdatedAndInputObserverNotified() + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + calculationInputObserver.Expect(o => o.UpdateObserver()); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var foreshoreProfileInput = new TestForeshoreProfile(true); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfileInput + } + }; + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, + parent, + failureMechanism, + assessmentSection); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + TestForeshoreProfile.ChangeBreakWaterProperties(foreshoreProfileInput); + + // Precondition + Assert.IsFalse(calculation.InputParameters.IsForeshoreProfileInputSynchronized); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateForeshoreProfileIndex].PerformClick(); + + // Then + Assert.IsTrue(calculation.InputParameters.IsForeshoreProfileInputSynchronized); + } + } + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void GivenCalculationWithOutputAndWithInputOutOfSync_WhenPerformClick_ThenInquiryAndExpectedOutputAndNotifications(bool continuation) + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + + var foreshoreProfileInput = new TestForeshoreProfile(true); + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = foreshoreProfileInput + }, + Output = new TestStructuresOutput() + }; + + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, + parent, + failureMechanism, + assessmentSection); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + if (continuation) + { + calculationObserver.Expect(o => o.UpdateObserver()); + calculationInputObserver.Expect(o => o.UpdateObserver()); + } + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + if (continuation) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + TestForeshoreProfile.ChangeBreakWaterProperties(foreshoreProfileInput); + + // Precondition + Assert.IsFalse(calculation.InputParameters.IsForeshoreProfileInputSynchronized); + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateForeshoreProfileIndex].PerformClick(); + + // Then + Assert.AreEqual(continuation, calculation.InputParameters.IsForeshoreProfileInputSynchronized); + Assert.AreEqual(!continuation, calculation.HasOutput); + } + } + + string expectedMessageBoxText = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + Assert.AreEqual(expectedMessageBoxText, messageBoxText); + } + + [Test] + public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() + { + // Given + var mainWindow = mocks.DynamicMock(); + var observer = mocks.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + + var failureMechanism = new TestHeightStructuresFailureMechanism(); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = Path.Combine(testDataPath, "complete.sqlite"), + Version = "random", + Locations = + { + hydraulicBoundaryLocation + } + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + 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(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new TestHeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + calculation.Attach(observer); + + var calculationContext = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator( + Arg.Is.NotNull)) + .WhenCalled(invocation => + { + HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( + HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), + (HydraRingCalculationSettings) invocation.Arguments[0]); + }) + .Return(new TestStructuresCalculator()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + DialogBoxHandler = (name, wnd) => + { + // Expect an activity dialog which is automatically closed + }; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // When + Action action = () => contextMenuStrip.Items[contextMenuCalculateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(7, msgs.Length); + Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gestart.", msgs[0]); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); + StringAssert.StartsWith("Hoogte kunstwerk berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[5]); + Assert.AreEqual($"Uitvoeren van berekening '{calculation.Name}' is gelukt.", msgs[6]); + }); + + Assert.IsNotNull(calculation.Output); + } + } + } + + [Test] + public void GivenCalculationWithNonExistingFilePath_WhenValidatingFromContextMenu_ThenLogMessagesAdded() + { + // Given + var observer = mocks.StrictMock(); + + string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = validFilePath, + Version = "random", + Locations = + { + hydraulicBoundaryLocation + } + }; + HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase); + + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); + + var parent = new CalculationGroup(); + var calculation = new TestHeightStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + calculation.Attach(observer); + + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var calculationContext = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(calculationContext, null, treeViewControl)) + { + // When + Action action = () => contextMenuStrip.Items[contextMenuValidateIndex].PerformClick(); + + // Then + TestHelper.AssertLogMessages(action, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); + }); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Call + ToolStripItem contextMenuItem = menu.Items[contextMenuClearIllustrationPointsIndex]; + + // Assert + Assert.IsTrue(contextMenuItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithOutputWithoutIllustrationPoints_ContextMenuItemClearIllustrationPointsDisabled() + { + // Setup + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput() + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // Call + ToolStripItem contextMenuItem = menu.Items[contextMenuClearIllustrationPointsIndex]; + + // Assert + Assert.IsFalse(contextMenuItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationWithIllustrationPoints_WhenClearIllustrationPointsClickedAndAborted_ThenInquiryAndIllustrationPointsNotCleared() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de illustratiepunten van deze berekening wilt wissen?", messageBoxText); + Assert.IsTrue(calculation.Output.HasGeneralResult); + } + } + } + + [Test] + public void GivenCalculationWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinued_ThenInquiryAndIllustrationPointsCleared() + { + // Given + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + + var parent = new CalculationGroup(); + var calculation = new StructuresCalculation + { + Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + var nodeData = new HeightStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + calculation.Attach(calculationObserver); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, assessmentSection, treeViewControl)) + { + // When + menu.Items[contextMenuClearIllustrationPointsIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de illustratiepunten van deze berekening wilt wissen?", messageBoxText); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + } + } + + [Test] + public void OnNodeRemoved_ParentIsCalculationGroupContext_RemoveCalculationFromGroup() + { + // Setup + var group = new CalculationGroup(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var elementToBeRemoved = new StructuresCalculation(); + var observer = mocks.StrictMock(); + var assessmentSection = mocks.Stub(); + var calculationContext = new HeightStructuresCalculationScenarioContext(elementToBeRemoved, + group, + failureMechanism, + assessmentSection); + var groupContext = new HeightStructuresCalculationGroupContext(group, + null, + failureMechanism, + assessmentSection); + + observer.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + group.Children.Add(elementToBeRemoved); + group.Children.Add(new StructuresCalculation()); + group.Attach(observer); + + // Precondition + Assert.IsTrue(info.CanRemove(calculationContext, groupContext)); + Assert.AreEqual(2, group.Children.Count); + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.AreEqual(1, group.Children.Count); + CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); + } + + [Test] + public void OnNodeRemoved_CalculationInGroupAssignedToSection_CalculationDetachedFromSection() + { + // Setup + var group = new CalculationGroup(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var elementToBeRemoved = new StructuresCalculation(); + var assessmentSection = mocks.Stub(); + var calculationContext = new HeightStructuresCalculationScenarioContext(elementToBeRemoved, + group, + failureMechanism, + assessmentSection); + var groupContext = new HeightStructuresCalculationGroupContext(group, + null, + failureMechanism, + assessmentSection); + + mocks.ReplayAll(); + + group.Children.Add(elementToBeRemoved); + + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }); + + HeightStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First(); + result.Calculation = elementToBeRemoved; + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.IsNull(result.Calculation); + } + + public override void Setup() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructuresCalculationScenarioContext)); + } + + public override void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + + base.TearDown(); + } + + private static void ChangeStructure(HeightStructure structure) + { + structure.CopyProperties(new HeightStructure( + new HeightStructure.ConstructionProperties + { + Id = structure.Id, + Name = structure.Name, + Location = structure.Location + })); + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/GeneralResultFaultTreeIllustrationPointViewInfoTest.cs =================================================================== diff -u -re3e3433c92e142f37d6a5ed931a70ad582c240bc -r3cbba23100bde03baa7b08ea535b779bcb7ddf13 --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/GeneralResultFaultTreeIllustrationPointViewInfoTest.cs (.../GeneralResultFaultTreeIllustrationPointViewInfoTest.cs) (revision e3e3433c92e142f37d6a5ed931a70ad582c240bc) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/GeneralResultFaultTreeIllustrationPointViewInfoTest.cs (.../GeneralResultFaultTreeIllustrationPointViewInfoTest.cs) (revision 3cbba23100bde03baa7b08ea535b779bcb7ddf13) @@ -149,7 +149,7 @@ protected override ICalculationContext GetCalculationContextWithCalculation() { - return new HeightStructuresCalculationContext( + return new HeightStructuresCalculationScenarioContext( new StructuresCalculation(), new CalculationGroup(), new HeightStructuresFailureMechanism(),