Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -r95ce9d6e938ed15b9e5d3cf9b1ae6e5183674a6d -r4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 95ce9d6e938ed15b9e5d3cf9b1ae6e5183674a6d) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -141,7 +141,7 @@ CalculationGroupContextContextMenuStrip, CalculationGroupContextOnNodeRemoved); - yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( + yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo( CalculationContextChildNodeObjects, CalculationContextContextMenuStrip, CalculationContextOnNodeRemoved); @@ -261,7 +261,7 @@ context => context.WrappedData.Children.Any(), GetInquiryHelper()); - yield return RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo( + yield return RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo( (context, filePath) => new ClosingStructuresCalculationConfigurationExporter(new[] { context.WrappedData @@ -460,7 +460,7 @@ if (calculation != null) { - childNodeObjects.Add(new ClosingStructuresCalculationContext(calculation, + childNodeObjects.Add(new ClosingStructuresCalculationScenarioContext(calculation, context.WrappedData, context.FailureMechanism, context.AssessmentSection)); @@ -687,7 +687,7 @@ #region ClosingStructuresCalculationContext TreeNodeInfo - private static object[] CalculationContextChildNodeObjects(ClosingStructuresCalculationContext context) + private static object[] CalculationContextChildNodeObjects(ClosingStructuresCalculationScenarioContext context) { StructuresCalculation calculation = context.WrappedData; @@ -702,7 +702,7 @@ }; } - private ContextMenuStrip CalculationContextContextMenuStrip(ClosingStructuresCalculationContext context, + private ContextMenuStrip CalculationContextContextMenuStrip(ClosingStructuresCalculationScenarioContext context, object parentData, TreeViewControl treeViewControl) { @@ -741,25 +741,25 @@ .Build(); } - private static string EnableValidateAndCalculateMenuItemForCalculation(ClosingStructuresCalculationContext context) + private static string EnableValidateAndCalculateMenuItemForCalculation(ClosingStructuresCalculationScenarioContext context) { return EnableValidateAndCalculateMenuItem(context.AssessmentSection); } - private static void Validate(ClosingStructuresCalculationContext context) + private static void Validate(ClosingStructuresCalculationScenarioContext context) { ClosingStructuresCalculationService.Validate(context.WrappedData, context.AssessmentSection); } - private void Calculate(StructuresCalculation calculation, ClosingStructuresCalculationContext context) + private void Calculate(StructuresCalculation calculation, ClosingStructuresCalculationScenarioContext context) { ActivityProgressDialogRunner.Run(Gui.MainWindow, ClosingStructuresCalculationActivityFactory.CreateCalculationActivity(calculation, context.FailureMechanism, context.AssessmentSection)); } - private static void CalculationContextOnNodeRemoved(ClosingStructuresCalculationContext context, object parentData) + private static void CalculationContextOnNodeRemoved(ClosingStructuresCalculationScenarioContext context, object parentData) { if (parentData is ClosingStructuresCalculationGroupContext calculationGroupContext) { @@ -769,7 +769,7 @@ } } - private StrictContextMenuItem CreateUpdateStructureItem(ClosingStructuresCalculationContext context) + private StrictContextMenuItem CreateUpdateStructureItem(ClosingStructuresCalculationScenarioContext context) { var contextMenuEnabled = true; string toolTipMessage = RiskeerCommonFormsResources.Update_Calculation_with_Structure_ToolTip; Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r56d072b8342f3e54ba89124ab918bd1529e257a3 -r4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 56d072b8342f3e54ba89124ab918bd1529e257a3) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -167,7 +167,7 @@ Assert.AreSame(failureMechanism, calculationGroupContext.FailureMechanism); Assert.AreSame(assessmentSection, calculationGroupContext.AssessmentSection); Assert.AreSame(calculationItem, children[1]); - var calculationContext = (ClosingStructuresCalculationContext) children[2]; + var calculationContext = (ClosingStructuresCalculationScenarioContext) children[2]; Assert.AreSame(childCalculation, calculationContext.WrappedData); Assert.AreSame(group, calculationContext.Parent); Assert.AreSame(assessmentSection, calculationContext.AssessmentSection); Index: Riskeer/Common/src/Riskeer.Common.Forms/PresentationObjects/StructuresCalculationScenarioContext.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Forms/PresentationObjects/StructuresCalculationScenarioContext.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Forms/PresentationObjects/StructuresCalculationScenarioContext.cs (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -0,0 +1,82 @@ +// 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 Core.Common.Controls.PresentationObjects; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Structures; + +namespace Riskeer.Common.Forms.PresentationObjects +{ + /// + /// Presentation object for all data required to configure a structures calculation. + /// + /// The type of calculation wrapped by this context. + /// The type of failure mechanism which the context belongs to. + public class StructuresCalculationScenarioContext : FailureMechanismItemContextBase, TFailureMechanism>, + ICalculationContext, TFailureMechanism> + where TInput : IStructuresCalculationInput, new() + where TFailureMechanism : IFailureMechanism + { + /// + /// Creates a new instance of . + /// + /// The 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. + protected StructuresCalculationScenarioContext(StructuresCalculationScenario calculation, + CalculationGroup parent, + TFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, failureMechanism, assessmentSection) + { + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + Parent = parent; + } + + public CalculationGroup Parent { get; } + + public override bool Equals(WrappedObjectContextBase> other) + { + return base.Equals(other) + && other is StructuresCalculationScenarioContext otherContext + && ReferenceEquals(Parent, otherContext.Parent); + } + + public override bool Equals(object obj) + { + return Equals(obj as StructuresCalculationScenarioContext); + } + + public override int GetHashCode() + { + return base.GetHashCode() ^ Parent.GetHashCode(); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.TestUtil.Test/TestStructuresCalculationScenarioTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.TestUtil.Test/TestStructuresCalculationScenarioTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.TestUtil.Test/TestStructuresCalculationScenarioTest.cs (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -0,0 +1,40 @@ +// 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 Riskeer.Common.Data.Structures; + +namespace Riskeer.Common.Data.TestUtil.Test +{ + [TestFixture] + public class TestStructuresCalculationScenarioTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var calculation = new TestStructuresCalculationScenario(); + + // Assert + Assert.IsInstanceOf>(calculation); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.TestUtil/TestStructuresCalculationScenario.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.TestUtil/TestStructuresCalculationScenario.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.TestUtil/TestStructuresCalculationScenario.cs (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -0,0 +1,30 @@ +// 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 Riskeer.Common.Data.Structures; + +namespace Riskeer.Common.Data.TestUtil +{ + /// + /// Simple structures calculation scenario that can be used in tests. + /// + public class TestStructuresCalculationScenario : StructuresCalculationScenario {} +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/PresentationObjects/StructuresCalculationScenarioContextTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Forms.Test/PresentationObjects/StructuresCalculationScenarioContextTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/PresentationObjects/StructuresCalculationScenarioContextTest.cs (revision 4c3b6a2ffc9aa9b193773b8ed818e59eb79b561b) @@ -0,0 +1,148 @@ +// 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.Collections.Generic; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.PresentationObjects; + +namespace Riskeer.Common.Forms.Test.PresentationObjects +{ + [TestFixture] + public class StructuresCalculationScenarioContextTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculationScenario(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + + // Call + var context = new TestStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf, TestFailureMechanism>>(context); + Assert.IsInstanceOf, TestFailureMechanism>>(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 Constructor_ParentNull_ThrowsArgumentNullException() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var calculation = new TestStructuresCalculationScenario(); + var failureMechanism = new TestFailureMechanism(); + + // Call + void Call() => new TestStructuresCalculationScenarioContext(calculation, null, failureMechanism, assessmentSection); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("parent", exception.ParamName); + mockRepository.VerifyAll(); + } + + [TestFixture] + private class StructuresCalculationContextEqualsTest : EqualsTestFixture + { + private static readonly MockRepository mocks = new MockRepository(); + + private static readonly IAssessmentSection assessmentSection = mocks.Stub(); + private static readonly TestStructuresCalculationScenario calculation = new TestStructuresCalculationScenario(); + private static readonly TestFailureMechanism failureMechanism = new TestFailureMechanism(); + private static readonly CalculationGroup parent = new CalculationGroup(); + + [SetUp] + public void SetUp() + { + mocks.ReplayAll(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + + protected override TestStructuresCalculationScenarioContext CreateObject() + { + return new TestStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + } + + protected override DerivedTestStructuresCalculationScenarioContext CreateDerivedObject() + { + return new DerivedTestStructuresCalculationScenarioContext(calculation, parent, failureMechanism, assessmentSection); + } + + private static IEnumerable GetUnequalTestCases() + { + yield return new TestCaseData(new TestStructuresCalculationScenarioContext(new TestStructuresCalculationScenario(), + parent, + failureMechanism, + assessmentSection)) + .SetName("Calculation"); + yield return new TestCaseData(new TestStructuresCalculationScenarioContext(calculation, + new CalculationGroup(), + failureMechanism, + assessmentSection)) + .SetName("Parent"); + } + } + + private class TestStructuresCalculationScenarioContext : StructuresCalculationScenarioContext + { + public TestStructuresCalculationScenarioContext(StructuresCalculationScenario calculation, + CalculationGroup parent, + TestFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, parent, failureMechanism, assessmentSection) {} + } + + private class DerivedTestStructuresCalculationScenarioContext : TestStructuresCalculationScenarioContext + { + public DerivedTestStructuresCalculationScenarioContext(StructuresCalculationScenario calculation, + CalculationGroup parent, + TestFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, parent, failureMechanism, assessmentSection) {} + } + } +} \ No newline at end of file