Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -22,15 +22,14 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using Core.Common.Gui.Attributes; using Core.Common.Util.Attributes; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.PropertyClasses; -using Ringtoets.Common.Util; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Util; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.HeightStructures.Forms.PropertyClasses @@ -127,9 +126,7 @@ protected override void AfterSettingStructure() { - StructuresHelper.UpdateCalculationToSectionResultAssignments( - data.FailureMechanism.SectionResults, - data.FailureMechanism.Calculations.Cast>()); + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(data.FailureMechanism); } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -99,6 +99,11 @@ Ringtoets.HeightStructures.Data False + + {B60FC9A2-22B5-4E4C-986E-40766B843AB5} + Ringtoets.HeightStructures.Util + False + Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Core.Common.Base.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; @@ -30,8 +29,8 @@ using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Configurations.Helpers; using Ringtoets.Common.IO.Configurations.Import; -using Ringtoets.Common.Util; using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Util; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.HeightStructures.IO.Configurations @@ -74,18 +73,22 @@ { throw new ArgumentNullException(nameof(hydraulicBoundaryLocations)); } + if (foreshoreProfiles == null) { throw new ArgumentNullException(nameof(foreshoreProfiles)); } + if (structures == null) { throw new ArgumentNullException(nameof(structures)); } + if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } + availableHydraulicBoundaryLocations = hydraulicBoundaryLocations; availableForeshoreProfiles = foreshoreProfiles; availableStructures = structures; @@ -94,9 +97,7 @@ protected override void DoPostImportUpdates() { - StructuresHelper.UpdateCalculationToSectionResultAssignments( - failureMechanism.SectionResults, - failureMechanism.Calculations.Cast>()); + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism); base.DoPostImportUpdates(); } @@ -126,6 +127,7 @@ SetShouldIllustrationPointsBeCalculated(readCalculation, calculation); return calculation; } + return null; } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -67,6 +67,11 @@ Ringtoets.HeightStructures.Data False + + {B60FC9A2-22B5-4E4C-986E-40766B843AB5} + Ringtoets.HeightStructures.Util + False + Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -ra493758b8df1196d55fc8e4552e271eafddbbefe -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision a493758b8df1196d55fc8e4552e271eafddbbefe) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -47,7 +47,6 @@ using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.Structures; using Ringtoets.Common.Service; -using Ringtoets.Common.Util; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HeightStructures.Forms.PropertyClasses; @@ -56,6 +55,7 @@ using Ringtoets.HeightStructures.IO.Configurations; using Ringtoets.HeightStructures.Plugin.FileImporters; using Ringtoets.HeightStructures.Service; +using Ringtoets.HeightStructures.Util; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; @@ -677,9 +677,7 @@ calculations.Add(calculation); } - StructuresHelper.UpdateCalculationToSectionResultAssignments( - failureMechanism.SectionResults, - failureMechanism.Calculations.Cast>()); + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism); } private static void CalculationGroupContextOnNodeRemoved(HeightStructuresCalculationGroupContext context, object parentNodeData) @@ -688,9 +686,7 @@ parentGroupContext.WrappedData.Children.Remove(context.WrappedData); - StructuresHelper.UpdateCalculationToSectionResultAssignments( - context.FailureMechanism.SectionResults, - context.FailureMechanism.Calculations.Cast>().ToArray()); + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(context.FailureMechanism); parentGroupContext.NotifyObservers(); } @@ -801,9 +797,7 @@ if (calculationGroupContext != null) { calculationGroupContext.WrappedData.Children.Remove(context.WrappedData); - StructuresHelper.UpdateCalculationToSectionResultAssignments( - context.FailureMechanism.SectionResults, - context.FailureMechanism.Calculations.Cast>()); + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(context.FailureMechanism); calculationGroupContext.NotifyObservers(); } } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj =================================================================== diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj (.../Ringtoets.HeightStructures.Plugin.csproj) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj (.../Ringtoets.HeightStructures.Plugin.csproj) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -99,6 +99,11 @@ Ringtoets.HeightStructures.Service False + + {b60fc9a2-22b5-4e4c-986e-40766b843ab5} + Ringtoets.HeightStructures.Util + False + Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/HeightStructuresHelper.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/HeightStructuresHelper.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/HeightStructuresHelper.cs (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -0,0 +1,87 @@ +// 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.Linq; +using Core.Common.Base; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Util; +using Ringtoets.HeightStructures.Data; + +namespace Ringtoets.HeightStructures.Util +{ + /// + /// Class holds helper methods to match objects + /// with objects. + /// + public class HeightStructuresHelper + { + /// + /// Updates the for each element + /// of if required due to a change. + /// + /// The failure mechanism which contains the + /// and calculations to update with. + /// All affected objects by the update. + /// Thrown when is null. + public static IEnumerable UpdateCalculationToSectionResultAssignments(HeightStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IObservableEnumerable sectionResults = failureMechanism.SectionResults2; + IEnumerable> calculations = failureMechanism.Calculations + .Cast>(); + return AssignUnassignCalculations.Update(sectionResults.Select(AsCalculationAssignment), + AsCalculationsWithLocations(calculations)) + .Cast() + .ToArray(); + } + + private static IEnumerable AsCalculationsWithLocations( + IEnumerable> calculations) + { + var calculationsWithLocation = new List(); + foreach (StructuresCalculation calculation in calculations) + { + if (calculation.InputParameters.Structure != null) + { + calculationsWithLocation.Add(new CalculationWithLocation(calculation, + calculation.InputParameters.Structure.Location)); + } + } + + return calculationsWithLocation; + } + + private static SectionResultWithCalculationAssignment AsCalculationAssignment( + HeightStructuresFailureMechanismSectionResult failureMechanismSectionResult) + { + return new SectionResultWithCalculationAssignment( + failureMechanismSectionResult, + result => ((HeightStructuresFailureMechanismSectionResult)result).Calculation, + (result, calculation) => ((HeightStructuresFailureMechanismSectionResult)result).Calculation = (StructuresCalculation)calculation); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/Ringtoets.HeightStructures.Util.csproj =================================================================== diff -u -rb148f2c61b813fd11f316acfc1a21135bb622248 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/Ringtoets.HeightStructures.Util.csproj (.../Ringtoets.HeightStructures.Util.csproj) (revision b148f2c61b813fd11f316acfc1a21135bb622248) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Util/Ringtoets.HeightStructures.Util.csproj (.../Ringtoets.HeightStructures.Util.csproj) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -11,11 +11,34 @@ + Copying.licenseheader + + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + False + + + {d4200f43-3f72-4f42-af0a-8ced416a38ec} + Ringtoets.Common.Data + False + + + {6a074d65-a81c-4c1c-8e24-f36c916e4ed7} + Ringtoets.Common.Util + False + + + {1c0017d8-35b5-4ca0-8fc7-a83f46dbdc99} + Ringtoets.HeightStructures.Data + False + + \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs =================================================================== diff -u -rd485f27eb5a6d688406882dce60c3229e22f2ac2 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision d485f27eb5a6d688406882dce60c3229e22f2ac2) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -304,18 +304,21 @@ var handler = new SetPropertyValueAfterConfirmationParameterTester(Enumerable.Empty()); var properties = new HeightStructuresInputContextProperties(inputContext, handler); - failureMechanism.AddSection(new FailureMechanismSection("Section", new List - { - new Point2D(-10.0, -10.0), - new Point2D(10.0, 10.0) - })); + FailureMechanismSection failureMechanismSection = + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(-10.0, -10.0), + new Point2D(10.0, 10.0) + }); + failureMechanism.AddSection( + failureMechanismSection); failureMechanism.CalculationsGroup.Children.Add(calculation); // Call properties.Structure = newStructure; // Assert - Assert.AreSame(calculation, failureMechanism.SectionResults.ElementAt(0).Calculation); + Assert.AreSame(calculation, failureMechanism.SectionResults2.ElementAt(0).Calculation); mockRepository.VerifyAll(); } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs =================================================================== diff -u -ref881721312166028ed88eaa21dfd1ee8a5cbba4 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs (.../HeightStructuresCalculationConfigurationImporterTest.cs) (revision ef881721312166028ed88eaa21dfd1ee8a5cbba4) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationConfigurationImporterTest.cs (.../HeightStructuresCalculationConfigurationImporterTest.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -572,11 +572,13 @@ var failureMechanism = new HeightStructuresFailureMechanism(); - failureMechanism.AddSection(new FailureMechanismSection("name", new[] - { - new Point2D(0, 0), - new Point2D(10, 10) - })); + FailureMechanismSection failureMechanismSection = + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(0, 0), + new Point2D(10, 10) + }); + failureMechanism.AddSection(failureMechanismSection); var calculation = new StructuresCalculation { @@ -597,14 +599,14 @@ failureMechanism); // Preconditions - Assert.AreEqual(1, failureMechanism.SectionResults.Count()); - Assert.IsNull(failureMechanism.SectionResults.ElementAt(0).Calculation); + Assert.AreEqual(1, failureMechanism.SectionResults2.Count()); + Assert.IsNull(failureMechanism.SectionResults2.ElementAt(0).Calculation); // Call importer.DoPostImport(); // Assert - Assert.AreSame(calculation, failureMechanism.SectionResults.ElementAt(0).Calculation); + Assert.AreSame(calculation, failureMechanism.SectionResults2.ElementAt(0).Calculation); } [TestCase("validConfigurationUnknownForeshoreProfile.xml", Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -ra23cff5445d53b381fd72f50a0d9b6c200cbcd69 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision a23cff5445d53b381fd72f50a0d9b6c200cbcd69) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -25,7 +25,6 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Base; -using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; @@ -38,11 +37,9 @@ using Ringtoets.Common.Data; 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.PresentationObjects; using Ringtoets.Common.Service.TestUtil; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Data.TestUtil; @@ -69,21 +66,6 @@ private HeightStructuresPlugin plugin; private TreeNodeInfo info; - public override void Setup() - { - mocks = new MockRepository(); - plugin = new HeightStructuresPlugin(); - info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructuresCalculationContext)); - } - - public override void TearDown() - { - plugin.Dispose(); - mocks.VerifyAll(); - - base.TearDown(); - } - [Test] public void Initialized_Always_ExpectedPropertiesSet() { @@ -207,6 +189,7 @@ // Call info.ContextMenuStrip(nodeData, null, treeViewControl); } + // Assert // Assert expectancies are called in TearDown() } @@ -1324,12 +1307,9 @@ group.Children.Add(elementToBeRemoved); - failureMechanism.AddSection(new FailureMechanismSection("section", new[] - { - new Point2D(0, 0) - })); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); - StructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First(); + HeightStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults2.First(); result.Calculation = elementToBeRemoved; // Call @@ -1339,6 +1319,21 @@ Assert.IsNull(result.Calculation); } + public override void Setup() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(HeightStructuresCalculationContext)); + } + + public override void TearDown() + { + plugin.Dispose(); + mocks.VerifyAll(); + + base.TearDown(); + } + private static void ChangeStructure(HeightStructure structure) { structure.CopyProperties(new HeightStructure( Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -ra23cff5445d53b381fd72f50a0d9b6c200cbcd69 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision a23cff5445d53b381fd72f50a0d9b6c200cbcd69) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -25,7 +25,6 @@ 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; @@ -39,7 +38,6 @@ 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; @@ -83,26 +81,6 @@ 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() { @@ -239,6 +217,7 @@ // Call info.ContextMenuStrip(groupContext, null, treeViewControl); } + // Assert // Assert expectancies called in TearDown() } @@ -405,6 +384,7 @@ // Call info.ContextMenuStrip(groupContext, parentGroupContext, treeViewControl); } + // Assert // Assert expectancies called in TearDown() } @@ -1769,10 +1749,7 @@ { // Setup var failureMechanism = new HeightStructuresFailureMechanism(); - failureMechanism.AddSection(new FailureMechanismSection("section", new[] - { - new Point2D(0, 0) - })); + failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()); var assessmentSection = mocks.Stub(); var group = new CalculationGroup(); @@ -1793,7 +1770,7 @@ var calculation = new StructuresCalculation(); group.Children.Add(calculation); - StructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First(); + HeightStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults2.First(); result.Calculation = calculation; // Call @@ -1840,6 +1817,26 @@ CollectionAssert.DoesNotContain(parentGroup.Children, group); } + 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(); + } + private static void ChangeStructure(HeightStructure structure) { structure.CopyProperties(new HeightStructure( Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/HeightStructuresHelperTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/HeightStructuresHelperTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/HeightStructuresHelperTest.cs (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -0,0 +1,114 @@ +// 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.Linq; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; + +namespace Ringtoets.HeightStructures.Util.Test +{ + [TestFixture] + public class HeightStructuresHelperTest + { + [Test] + public void UpdateCalculationToSectionResultAssignments_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void UpdateCalculationToSectionResultAssignments_SectionResultWithCalculationNoRemainingCalculations_SectionResultCalculationIsNull() + { + // Setup + var location = new Point2D(1, 1); + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.AddSection(CreateFailureMechanismSection(location)); + + HeightStructuresFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults2.First(); + sectionResult.Calculation = CreateCalculation(location); + + // Call + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism); + + // Assert + Assert.IsNull(sectionResult.Calculation); + } + + [Test] + public void UpdateCalculationToSectionResultAssignments_SectionResultWithCalculationWithRemainingCalculations_SectionResultCalculationSetToRemainingCalculation() + { + // Setup + var location = new Point2D(1, 1); + StructuresCalculation remainingCalculation = CreateCalculation(new Point2D(10, 10)); + var failureMechanism = new HeightStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + remainingCalculation + } + } + }; + failureMechanism.AddSection(CreateFailureMechanismSection(location)); + + HeightStructuresFailureMechanismSectionResult sectionResult = failureMechanism.SectionResults2.First(); + sectionResult.Calculation = CreateCalculation(location); + + // Call + HeightStructuresHelper.UpdateCalculationToSectionResultAssignments(failureMechanism); + + // Assert + Assert.AreSame(remainingCalculation, sectionResult.Calculation); + } + + private static FailureMechanismSection CreateFailureMechanismSection(Point2D endPoint) + { + return FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(0, 0), + endPoint + }); + } + + private static StructuresCalculation CreateCalculation(Point2D location) + { + return new StructuresCalculation + { + InputParameters = + { + Structure = new TestHeightStructure(location) + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/Ringtoets.HeightStructures.Util.Test.csproj =================================================================== diff -u -rb148f2c61b813fd11f316acfc1a21135bb622248 -rfd9e1dd4f143af493965eea4d564c087081fb7f7 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/Ringtoets.HeightStructures.Util.Test.csproj (.../Ringtoets.HeightStructures.Util.Test.csproj) (revision b148f2c61b813fd11f316acfc1a21135bb622248) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/Ringtoets.HeightStructures.Util.Test.csproj (.../Ringtoets.HeightStructures.Util.Test.csproj) (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -7,15 +7,46 @@ + + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + + Copying.licenseheader + + + + {3BBFD65B-B277-4E50-AE6D-BD24C3434609} + Core.Common.Base + + + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} + Ringtoets.Common.Data + + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + + + {1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99} + Ringtoets.HeightStructures.Data + + + {B60FC9A2-22B5-4E4C-986E-40766B843AB5} + Ringtoets.HeightStructures.Util + + + {F67E8AE8-1FF0-4680-9817-99E025CD9FF6} + Ringtoets.HeightStructures.Data.TestUtil + + \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/packages.config =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/packages.config (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Util.Test/packages.config (revision fd9e1dd4f143af493965eea4d564c087081fb7f7) @@ -0,0 +1,26 @@ + + + + + \ No newline at end of file