Index: Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs (.../IFailureMechanism.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs (.../IFailureMechanism.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -54,7 +54,8 @@
bool IsRelevant { get; set; }
///
- /// Gets a of .
+ /// Gets a of all the instances added to
+ /// the failure mechanism.
///
IEnumerable Calculations { get; }
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/AssignUnassignCalculations.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Utils/AssignUnassignCalculations.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/AssignUnassignCalculations.cs (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -0,0 +1,266 @@
+// Copyright (C) Stichting Deltares 2016. 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.Geometry;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.FailureMechanism;
+
+namespace Ringtoets.Common.Utils
+{
+ ///
+ /// Utility class for data synchronization of the
+ /// of objects.
+ ///
+ public static class AssignUnassignCalculations
+ {
+ ///
+ /// Update objects which used or can use the .
+ ///
+ /// The objects which contain the
+ /// information about assigning calculations to sections.
+ /// The which's location is used to match with the
+ /// location of the section.
+ /// When any input parameter is null.
+ /// When contains a null element.
+ public static void Update(IEnumerable sectionResults, CalculationWithLocation calculation)
+ {
+ ValidateSectionResults(sectionResults);
+ ValidateCalculationWithLocation(calculation);
+
+ var sectionResultsArray = sectionResults.ToArray();
+
+ FailureMechanismSection failureMechanismSectionContainingCalculation =
+ FailureMechanismSectionForCalculation(sectionResultsArray.Select(sr => sr.Result.Section), calculation);
+
+ UnassignCalculationInSectionResultsNotContainingCalculation(calculation, sectionResultsArray, failureMechanismSectionContainingCalculation);
+
+ AssignCalculationIfContainingSectionResultHasNoCalculationAssigned(calculation, sectionResultsArray, failureMechanismSectionContainingCalculation);
+ }
+
+ ///
+ /// Update objects which use the deleted .
+ ///
+ /// The objects which contain the
+ /// information about assigning calculations to sections.
+ /// The that was removed.
+ /// All the remaining calculations after deletion of the .
+ /// When any input parameter is null.
+ /// When or
+ /// contains a null element.
+ public static void Delete(
+ IEnumerable sectionResults,
+ ICalculation calculation,
+ IEnumerable calculations)
+ {
+ ValidateSectionResults(sectionResults);
+ ValidateCalculations(calculations);
+ ValidateCalculation(calculation);
+
+ var sectionResultsArray = sectionResults.ToArray();
+
+ Dictionary> calculationsPerSegmentName =
+ CollectCalculationsPerSection(sectionResultsArray.Select(sr => sr.Result.Section), calculations);
+
+ UnassignCalculationInAllSectionResultsAndAssignSingleRemainingCalculation(sectionResultsArray, calculation, calculationsPerSegmentName);
+ }
+
+ ///
+ /// Determine which objects are available for a
+ /// .
+ ///
+ /// The objects.
+ /// The objects.
+ /// A containing a
+ /// of objects
+ /// for each section name which has calculations.
+ /// When any input parameter is null.
+ /// When or
+ /// contains a null element.
+ public static Dictionary> CollectCalculationsPerSection(
+ IEnumerable sections,
+ IEnumerable calculations)
+ {
+ ValidateSections(sections);
+ ValidateCalculations(calculations);
+
+ SectionSegments[] sectionSegments = SectionSegmentsHelper.MakeSectionSegments(sections);
+
+ var calculationsPerSegment = new Dictionary>();
+
+ foreach (var calculationWithLocation in calculations)
+ {
+ FailureMechanismSection section = FindSectionAtLocation(sectionSegments, calculationWithLocation.Location);
+ if (section == null)
+ {
+ continue;
+ }
+
+ UpdateCalculationsOfSegment(calculationsPerSegment, section.Name, calculationWithLocation.Calculation);
+ }
+ return calculationsPerSegment;
+ }
+
+ ///
+ /// Determine which geometrically contains the .
+ ///
+ /// The objects
+ /// whose are considered.
+ /// The .
+ /// The containing , or null.
+ /// When any input parameter is null or when
+ /// an element in is null.
+ public static FailureMechanismSection FailureMechanismSectionForCalculation(
+ IEnumerable sections,
+ CalculationWithLocation calculation)
+ {
+ ValidateSections(sections);
+ ValidateCalculationWithLocation(calculation);
+
+ SectionSegments[] sectionSegments = SectionSegmentsHelper.MakeSectionSegments(sections);
+
+ return FindSectionAtLocation(sectionSegments, calculation.Location);
+ }
+
+ private static void UnassignCalculationInAllSectionResultsAndAssignSingleRemainingCalculation(
+ IEnumerable sectionResults,
+ ICalculation calculation, Dictionary> calculationsPerSegmentName)
+ {
+ IEnumerable sectionResultsUsingCalculation =
+ sectionResults.Where(sr => sr.Calculation != null && ReferenceEquals(sr.Calculation, calculation));
+
+ foreach (var sectionResult in sectionResultsUsingCalculation)
+ {
+ string sectionName = sectionResult.Result.Section.Name;
+ if (calculationsPerSegmentName.ContainsKey(sectionName) && calculationsPerSegmentName[sectionName].Count == 1)
+ {
+ sectionResult.Calculation = calculationsPerSegmentName[sectionName].Single();
+ continue;
+ }
+ sectionResult.Calculation = null;
+ }
+ }
+
+ private static void AssignCalculationIfContainingSectionResultHasNoCalculationAssigned(
+ CalculationWithLocation calculationWithLocation,
+ IEnumerable sectionResults,
+ FailureMechanismSection failureMechanismSection)
+ {
+ foreach (var sectionResult in sectionResults)
+ {
+ if (ReferenceEquals(sectionResult.Result.Section, failureMechanismSection) && sectionResult.Calculation == null)
+ {
+ sectionResult.Calculation = calculationWithLocation.Calculation;
+ }
+ }
+ }
+
+ private static void UnassignCalculationInSectionResultsNotContainingCalculation(
+ CalculationWithLocation calculationWithLocation,
+ IEnumerable sectionResults,
+ FailureMechanismSection failureMechanismSection)
+ {
+ IEnumerable sectionResultsUsingCalculation =
+ sectionResults.Where(sr => sr.Calculation != null && ReferenceEquals(sr.Calculation, calculationWithLocation.Calculation));
+ foreach (var sectionResult in sectionResultsUsingCalculation)
+ {
+ if (!ReferenceEquals(sectionResult.Result.Section, failureMechanismSection))
+ {
+ sectionResult.Calculation = null;
+ }
+ }
+ }
+
+ private static FailureMechanismSection FindSectionAtLocation(IEnumerable sectionSegmentsCollection,
+ Point2D location)
+ {
+ return SectionSegmentsHelper.GetSectionForPoint(sectionSegmentsCollection, location);
+ }
+
+ private static void UpdateCalculationsOfSegment(Dictionary> calculationsPerSegment,
+ string sectionName, ICalculation calculation)
+ {
+ if (!calculationsPerSegment.ContainsKey(sectionName))
+ {
+ calculationsPerSegment.Add(sectionName, new List());
+ }
+ calculationsPerSegment[sectionName].Add(calculation);
+ }
+
+ #region Validate inputs
+
+ private static void ValidateSections(IEnumerable sections)
+ {
+ if (sections == null)
+ {
+ throw new ArgumentNullException("sections");
+ }
+ if (sections.Any(s => s == null))
+ {
+ throw new ArgumentException("Sections contains an entry without value.", "sections");
+ }
+ }
+
+ private static void ValidateCalculation(ICalculation calculation)
+ {
+ if (calculation == null)
+ {
+ throw new ArgumentNullException("calculation");
+ }
+ }
+
+ private static void ValidateCalculationWithLocation(CalculationWithLocation calculation)
+ {
+ if (calculation == null)
+ {
+ throw new ArgumentNullException("calculation");
+ }
+ }
+
+ private static void ValidateCalculations(IEnumerable calculations)
+ {
+ if (calculations == null)
+ {
+ throw new ArgumentNullException("calculations");
+ }
+ if (calculations.Any(s => s == null))
+ {
+ throw new ArgumentException("Calculations contains an entry without value.", "calculations");
+ }
+ }
+
+ private static void ValidateSectionResults(IEnumerable sectionResults)
+ {
+ if (sectionResults == null)
+ {
+ throw new ArgumentNullException("sectionResults");
+ }
+ if (sectionResults.Any(s => s == null))
+ {
+ throw new ArgumentException("SectionResults contains an entry without value.", "sectionResults");
+ }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/CalculationWithLocation.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Utils/CalculationWithLocation.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/CalculationWithLocation.cs (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -0,0 +1,66 @@
+// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry;
+using Ringtoets.Common.Data.Calculation;
+
+namespace Ringtoets.Common.Utils
+{
+ ///
+ /// This class contains a calculation and the location for that calculation as a 2D point.
+ ///
+ public class CalculationWithLocation
+ {
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The which has an
+ /// input element which represents a location.
+ /// The which represents
+ /// the location of the .
+ /// Thrown when either
+ /// calculation or location is null.
+ public CalculationWithLocation(ICalculation calculation, Point2D location)
+ {
+ if (calculation == null)
+ {
+ throw new ArgumentNullException("calculation");
+ }
+ if (location == null)
+ {
+ throw new ArgumentNullException("location");
+ }
+ Calculation = calculation;
+ Location = location;
+ }
+
+ ///
+ /// Gets the calculation which has a location assigned.
+ ///
+ public ICalculation Calculation { get; private set; }
+
+ ///
+ /// Gets the location of the calculation.
+ ///
+ public Point2D Location { get; private set; }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj
===================================================================
diff -u -r721d6f7ac6513e2219ff9bc652f3d6059061a009 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj (.../Ringtoets.Common.Utils.csproj) (revision 721d6f7ac6513e2219ff9bc652f3d6059061a009)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj (.../Ringtoets.Common.Utils.csproj) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -39,6 +39,9 @@
Properties\GlobalAssembly.cs
+
+
+
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/SectionResultWithCalculationAssignment.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Utils/SectionResultWithCalculationAssignment.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/SectionResultWithCalculationAssignment.cs (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -0,0 +1,89 @@
+// Copyright (C) Stichting Deltares 2016. 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 Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.FailureMechanism;
+
+namespace Ringtoets.Common.Utils
+{
+ ///
+ /// This class is used to be able to assign calculations to failure mechanism section results without having
+ /// to keep in mind the underlying types for either calculations or section results.
+ ///
+ public class SectionResultWithCalculationAssignment
+ {
+ private readonly Action setCalculationAction;
+ private readonly Func getCalculationAction;
+
+ ///
+ /// Creates new instance of .
+ ///
+ /// The result which can have a calculation assigned.
+ /// The to get an
+ /// from the .
+ /// The to set an
+ /// to the .
+ /// Thrown when any of the parameters is null.
+ public SectionResultWithCalculationAssignment(
+ FailureMechanismSectionResult result,
+ Func getCalculationAction,
+ Action setCalculationAction)
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException("result");
+ }
+ if (getCalculationAction == null)
+ {
+ throw new ArgumentNullException("getCalculationAction");
+ }
+ if (setCalculationAction == null)
+ {
+ throw new ArgumentNullException("setCalculationAction");
+ }
+ Result = result;
+ this.getCalculationAction = getCalculationAction;
+ this.setCalculationAction = setCalculationAction;
+ }
+
+ ///
+ /// Gets the for which the assignment object is defined.
+ ///
+ public FailureMechanismSectionResult Result { get; private set; }
+
+ ///
+ /// Gets or sets the from the using the actions passed
+ /// to the constructor.
+ ///
+ internal ICalculation Calculation
+ {
+ get
+ {
+ return getCalculationAction(Result);
+ }
+ set
+ {
+ setCalculationAction(Result, value);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegments.cs
===================================================================
diff -u -r721d6f7ac6513e2219ff9bc652f3d6059061a009 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegments.cs (.../SectionSegments.cs) (revision 721d6f7ac6513e2219ff9bc652f3d6059061a009)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegments.cs (.../SectionSegments.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -19,6 +19,7 @@
// 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.Geometry;
@@ -38,8 +39,13 @@
///
/// The whose
/// this class represents as a collection of objects.
+ /// Thrown when is null.
public SectionSegments(FailureMechanismSection section)
{
+ if (section == null)
+ {
+ throw new ArgumentNullException("section");
+ }
Section = section;
segments = Math2D.ConvertLinePointsToLineSegments(section.Points);
}
Index: Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegmentsHelper.cs
===================================================================
diff -u -rb2f617ad0d8d6457422a569685763b9718740560 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegmentsHelper.cs (.../SectionSegmentsHelper.cs) (revision b2f617ad0d8d6457422a569685763b9718740560)
+++ Ringtoets/Common/src/Ringtoets.Common.Utils/SectionSegmentsHelper.cs (.../SectionSegmentsHelper.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -33,19 +33,20 @@
public static class SectionSegmentsHelper
{
///
- /// Creates from an of .
+ /// Creates from an of .
///
- /// The of
+ /// The of
/// to create for.
/// An array of .
- /// Thrown when is null.
- public static SectionSegments[] MakeSectionSegments(IEnumerable sectionResults)
+ /// Thrown when is null or when
+ /// an element in is null.
+ public static SectionSegments[] MakeSectionSegments(IEnumerable sections)
{
- if (sectionResults == null)
+ if (sections == null)
{
- throw new ArgumentNullException("sectionResults");
+ throw new ArgumentNullException("sections");
}
- return sectionResults.Select(s => new SectionSegments(s)).ToArray();
+ return sections.Select(s => new SectionSegments(s)).ToArray();
}
///
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/AssignUnassignCalculationsTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/AssignUnassignCalculationsTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/AssignUnassignCalculationsTest.cs (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -0,0 +1,608 @@
+// Copyright (C) Stichting Deltares 2016. 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.Geometry;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.FailureMechanism;
+
+namespace Ringtoets.Common.Utils.Test
+{
+ [TestFixture]
+ public class AssignUnassignCalculationsTest
+ {
+ private const string firstSectionName = "firstSection";
+ private const string secondSectionName = "secondSection";
+
+ private readonly FailureMechanismSection[] oneSection =
+ {
+ new FailureMechanismSection("testFailureMechanismSection", new List
+ {
+ new Point2D(0.0, 0.0)
+ })
+ };
+
+ private readonly FailureMechanismSection[] twoSections =
+ {
+ new FailureMechanismSection(firstSectionName, new List
+ {
+ new Point2D(0.0, 0.0),
+ new Point2D(10.0, 10.0),
+ }),
+ new FailureMechanismSection(secondSectionName, new List
+ {
+ new Point2D(11.0, 11.0),
+ new Point2D(100.0, 100.0),
+ })
+ };
+
+ [Test]
+ public void Update_NullSectionResultsElement_ThrowsArgumentException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var calculationWithLocation = new CalculationWithLocation(calculation, new Point2D(0, 0));
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Update(
+ new SectionResultWithCalculationAssignment[]
+ {
+ null
+ },
+ calculationWithLocation);
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "SectionResults contains an entry without value.");
+ Assert.AreEqual("sectionResults", exception.ParamName);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Update_NullCalculation_ThrowsArgumentNullException()
+ {
+ // Setup
+ var sectionResults = Enumerable.Empty();
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Update(sectionResults, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculation", paramName);
+ }
+
+ [Test]
+ public void Update_NullSectionResults_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var calculationWithLocation = new CalculationWithLocation(calculation, new Point2D(0, 0));
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Update(null, calculationWithLocation);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sectionResults", paramName);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Update_CalculationDikeProfileChangedToMatchOtherSection_FirstSectionResultCalculationNullSecondSectionResultCalculationSet()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var calculationLocation = new Point2D(1.51, 1.51);
+
+ var sectionA = new FailureMechanismSection("firstSection", new List
+ {
+ new Point2D(0.0, 0.0), new Point2D(1.1, 1.1)
+ });
+ var sectionB = new FailureMechanismSection("secondSection", new List
+ {
+ new Point2D(1.1, 1.1), new Point2D(2.2, 2.2)
+ });
+
+ var sectionResultA = new FailureMechanismSectionResultWithCalculation(sectionA);
+ var sectionResultB = new FailureMechanismSectionResultWithCalculation(sectionB);
+
+ var sectionResults = new List
+ {
+ new SectionResultWithCalculationAssignment(sectionResultA,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c),
+ new SectionResultWithCalculationAssignment(sectionResultB,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c)
+ };
+ sectionResultA.Calculation = calculation;
+
+ // Call
+ AssignUnassignCalculations.Update(sectionResults, new CalculationWithLocation(calculation, calculationLocation));
+
+ // Assert
+ Assert.IsNull(sectionResultA.Calculation);
+ Assert.AreSame(calculation, sectionResultB.Calculation);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Update_CalculationDikeProfileChangedToMatchOtherSection_FirstSectionResultCalculationNullSecondSectionResultCalculationUnchanged()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculationA = mockRepository.Stub();
+ var calculationB = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var locationB = new Point2D(1.51, 1.51);
+
+ var sectionA = new FailureMechanismSection("firstSection", new List
+ {
+ new Point2D(0.0, 0.0), new Point2D(1.1, 1.1)
+ });
+ var sectionB = new FailureMechanismSection("secondSection", new List
+ {
+ new Point2D(1.1, 1.1), new Point2D(2.2, 2.2)
+ });
+
+ var sectionResultA = new FailureMechanismSectionResultWithCalculation(sectionA);
+ var sectionResultB = new FailureMechanismSectionResultWithCalculation(sectionB);
+
+ var sectionResults = new List
+ {
+ new SectionResultWithCalculationAssignment(sectionResultA,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c),
+ new SectionResultWithCalculationAssignment(sectionResultB,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c)
+ };
+ sectionResultA.Calculation = calculationA;
+ sectionResultB.Calculation = calculationB;
+
+ // Call
+ AssignUnassignCalculations.Update(sectionResults, new CalculationWithLocation(calculationA, locationB));
+
+ // Assert
+ Assert.IsNull(sectionResultA.Calculation);
+ Assert.AreSame(calculationB, sectionResultB.Calculation);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Delete_NullSectionResults_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Delete(
+ null,
+ calculation,
+ Enumerable.Empty());
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sectionResults", paramName);
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Delete_NullSectionResultsElement_ThrowsArgumentException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Delete(
+ new SectionResultWithCalculationAssignment[]
+ {
+ null
+ },
+ calculation,
+ Enumerable.Empty());
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "SectionResults contains an entry without value.");
+ Assert.AreEqual("sectionResults", exception.ParamName);
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Delete_NullCalculation_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Delete(
+ Enumerable.Empty(),
+ null,
+ Enumerable.Empty());
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculation", paramName);
+ }
+
+ [Test]
+ public void Delete_NullCalculations_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Delete(
+ Enumerable.Empty(),
+ calculation,
+ null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculations", paramName);
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Delete_NullCalculationsElement_ThrowsArgumentException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.Delete(
+ Enumerable.Empty(),
+ calculation,
+ new CalculationWithLocation[]
+ {
+ null
+ });
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Calculations contains an entry without value.");
+ Assert.AreEqual("calculations", exception.ParamName);
+
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Delete_RemoveCalculationAssignedToSectionResult_SectionResultCalculationNull()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var section = new FailureMechanismSection("firstSection", new List
+ {
+ new Point2D(0.0, 0.0), new Point2D(1.1, 1.1)
+ });
+
+ var sectionResult = new FailureMechanismSectionResultWithCalculation(section);
+
+ var sectionResults = new List
+ {
+ new SectionResultWithCalculationAssignment(sectionResult,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c)
+ };
+ sectionResult.Calculation = calculation;
+
+ // Setup
+ // Call
+ AssignUnassignCalculations.Delete(sectionResults, calculation, Enumerable.Empty());
+
+ // Assert
+ Assert.IsNull(sectionResult.Calculation);
+ }
+
+ [Test]
+ public void Delete_RemoveCalculationAssignedToSectionResult_SingleRemainingCalculationAssignedToSectionResult()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculationA = mockRepository.Stub();
+ var calculationB = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var location = new Point2D(0.51, 0.51);
+
+ var sectionA = new FailureMechanismSection("firstSection", new List
+ {
+ new Point2D(0.0, 0.0), new Point2D(1.1, 1.1)
+ });
+
+ var sectionResult = new FailureMechanismSectionResultWithCalculation(sectionA);
+
+ var sectionResults = new List
+ {
+ new SectionResultWithCalculationAssignment(sectionResult,
+ r => ((FailureMechanismSectionResultWithCalculation) r).Calculation,
+ (r, c) => ((FailureMechanismSectionResultWithCalculation) r).Calculation = c)
+ };
+ sectionResult.Calculation = calculationA;
+
+ // Call
+ AssignUnassignCalculations.Delete(sectionResults, calculationA, new[]
+ {
+ new CalculationWithLocation(calculationB, location),
+ });
+
+ // Assert
+ Assert.AreSame(calculationB, sectionResult.Calculation);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_NullSections_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.CollectCalculationsPerSection(null, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sections", paramName);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_NullSectionsElement_ThrowsArgumentException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.CollectCalculationsPerSection(new FailureMechanismSection[]
+ {
+ null
+ }, Enumerable.Empty());
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Sections contains an entry without value.");
+ Assert.AreEqual("sections", exception.ParamName);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_NullCalculations_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.CollectCalculationsPerSection(Enumerable.Empty(), null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculations", paramName);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_NullCalculationsElement_ThrowsArgumentException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.CollectCalculationsPerSection(Enumerable.Empty(), new CalculationWithLocation[]
+ {
+ null
+ });
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Calculations contains an entry without value.");
+ Assert.AreEqual("calculations", exception.ParamName);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_ValidEmptySectionResults_EmptyDictionary()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ IEnumerable twoCalculationsInFirstSection = CreateTwoCalculationsInFirstSection(mockRepository);
+ mockRepository.ReplayAll();
+
+ // Call
+ Dictionary> collectCalculationsPerSegment =
+ AssignUnassignCalculations.CollectCalculationsPerSection(Enumerable.Empty(), twoCalculationsInFirstSection);
+
+ // Assert
+ Assert.AreEqual(0, collectCalculationsPerSegment.Count);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_ValidEmptyCalculations_EmptyDictionary()
+ {
+ // Call
+ Dictionary> collectCalculationsPerSegment =
+ AssignUnassignCalculations.CollectCalculationsPerSection(oneSection, Enumerable.Empty());
+
+ // Assert
+ Assert.AreEqual(0, collectCalculationsPerSegment.Count);
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_MultipleCalculationsInSegment_OneSegmentHasAllCalculations()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ IEnumerable twoCalculationsInFirstSection = CreateTwoCalculationsInFirstSection(mockRepository);
+ mockRepository.ReplayAll();
+
+ // Call
+ Dictionary> collectCalculationsPerSegment =
+ AssignUnassignCalculations.CollectCalculationsPerSection(twoSections, twoCalculationsInFirstSection);
+
+ // Assert
+ Assert.AreEqual(1, collectCalculationsPerSegment.Count);
+ Assert.IsTrue(collectCalculationsPerSegment.ContainsKey(firstSectionName));
+ CollectionAssert.AreEqual(twoCalculationsInFirstSection.Select(cwl => cwl.Calculation), collectCalculationsPerSegment[firstSectionName]);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void CollectCalculationsPerSegment_SingleCalculationPerSegment_OneCalculationPerSegment()
+ {
+ var mockRepository = new MockRepository();
+ CalculationWithLocation[] oneCalculationInEachSection = CreateOneCalculationInEachSection(mockRepository);
+ mockRepository.ReplayAll();
+
+ // Call
+ Dictionary> collectCalculationsPerSegment =
+ AssignUnassignCalculations.CollectCalculationsPerSection(twoSections, oneCalculationInEachSection);
+
+ // Assert
+ Assert.AreEqual(2, collectCalculationsPerSegment.Count);
+ Assert.AreEqual(1, collectCalculationsPerSegment[firstSectionName].Count);
+ Assert.AreSame(oneCalculationInEachSection[0].Calculation, collectCalculationsPerSegment[firstSectionName][0]);
+ Assert.AreEqual(1, collectCalculationsPerSegment[secondSectionName].Count);
+ Assert.AreSame(oneCalculationInEachSection[1].Calculation, collectCalculationsPerSegment[secondSectionName][0]);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_NullSections_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.FailureMechanismSectionForCalculation(null, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sections", paramName);
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_NullSectionsElement_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.FailureMechanismSectionForCalculation(
+ new FailureMechanismSection[]
+ {
+ null
+ },
+ null);
+
+ // Assert
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(
+ call,
+ "Sections contains an entry without value.");
+ Assert.AreEqual("sections", exception.ParamName);
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_CalculationNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AssignUnassignCalculations.FailureMechanismSectionForCalculation(Enumerable.Empty(), null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("calculation", paramName);
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_ValidEmptySectionResults_ReturnsNull()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ FailureMechanismSection failureMechanismSection =
+ AssignUnassignCalculations.FailureMechanismSectionForCalculation(Enumerable.Empty(), new CalculationWithLocation(calculation, new Point2D(0, 0)));
+
+ // Assert
+ Assert.IsNull(failureMechanismSection);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_FirstSectionResultContainsCalculation_FailureMechanismSectionOfFirstSectionResult()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ FailureMechanismSection failureMechanismSection =
+ AssignUnassignCalculations.FailureMechanismSectionForCalculation(twoSections, new CalculationWithLocation(calculation, new Point2D(1.1, 2.2)));
+
+ // Assert
+ Assert.AreSame(twoSections[0], failureMechanismSection);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_SecondSectionResultContainsCalculation_FailureMechanismSectionOfSecondSectionResult()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var calculation = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ // Call
+ FailureMechanismSection failureMechanismSection =
+ AssignUnassignCalculations.FailureMechanismSectionForCalculation(twoSections, new CalculationWithLocation(calculation, new Point2D(50.0, 66.0)));
+
+ // Assert
+ Assert.AreSame(twoSections[1], failureMechanismSection);
+ mockRepository.VerifyAll();
+ }
+
+ private static CalculationWithLocation[] CreateTwoCalculationsInFirstSection(MockRepository mockRepository)
+ {
+ return new[]
+ {
+ new CalculationWithLocation(mockRepository.Stub(), new Point2D(1.1, 2.2)),
+ new CalculationWithLocation(mockRepository.Stub(), new Point2D(3.3, 4.4))
+ };
+ }
+
+ private static CalculationWithLocation[] CreateOneCalculationInEachSection(MockRepository mockRepository)
+ {
+ return new[]
+ {
+ new CalculationWithLocation(mockRepository.Stub(), new Point2D(1.1, 2.2)),
+ new CalculationWithLocation(mockRepository.Stub(), new Point2D(50.0, 66.0))
+ };
+ }
+ }
+
+ public class FailureMechanismSectionResultWithCalculation : FailureMechanismSectionResult
+ {
+ public FailureMechanismSectionResultWithCalculation(FailureMechanismSection section) : base(section) {}
+ public ICalculation Calculation { get; set; }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj
===================================================================
diff -u -rb2f617ad0d8d6457422a569685763b9718740560 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj (.../Ringtoets.Common.Utils.Test.csproj) (revision b2f617ad0d8d6457422a569685763b9718740560)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj (.../Ringtoets.Common.Utils.Test.csproj) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -43,13 +43,18 @@
..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll
True
+
+ ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+ True
+
Properties\GlobalAssembly.cs
+
@@ -65,6 +70,10 @@
{3BBFD65B-B277-4E50-AE6D-BD24C3434609}
Core.Common.Base
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+
{D4200F43-3F72-4F42-AF0A-8CED416A38EC}
Ringtoets.Common.Data
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsHelperTest.cs
===================================================================
diff -u -rb2f617ad0d8d6457422a569685763b9718740560 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsHelperTest.cs (.../SectionSegmentsHelperTest.cs) (revision b2f617ad0d8d6457422a569685763b9718740560)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsHelperTest.cs (.../SectionSegmentsHelperTest.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -31,16 +31,29 @@
public class SectionSegmentsHelperTest
{
[Test]
- public void MakeSectionSegments_SectionResultsNull_ThrowsArgumentNullException()
+ public void MakeSectionSegments_SectionsNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => SectionSegmentsHelper.MakeSectionSegments(null);
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("sectionResults", exception.ParamName);
+ Assert.AreEqual("sections", exception.ParamName);
}
+ [Test]
+ public void MakeSectionSegments_SectionsElementNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => SectionSegmentsHelper.MakeSectionSegments(new FailureMechanismSection[]
+ {
+ null
+ });
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("section", exception.ParamName);
+ }
+
[Test]
public void MakeSectionSegments_ValidFailureMechanismSections_ReturnSectionSegmentsFromFailureMechanismSection()
{
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsTest.cs
===================================================================
diff -u -rb2f617ad0d8d6457422a569685763b9718740560 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsTest.cs (.../SectionSegmentsTest.cs) (revision b2f617ad0d8d6457422a569685763b9718740560)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/SectionSegmentsTest.cs (.../SectionSegmentsTest.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using Core.Common.Base.Geometry;
using NUnit.Framework;
@@ -30,8 +31,19 @@
public class SectionSegmentsTest
{
[Test]
- public void Constructor_ExpectedValues()
+ public void Constructor_WithoutFailureMechanismSection_ThrowsArgumentNullException()
{
+ // Call
+ TestDelegate test = () => new SectionSegments(null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("section", exception.ParamName);
+ }
+
+ [Test]
+ public void Constructor_WithFailureMechanismSection_ExpectedValues()
+ {
// Setup
var failureMechanismSection = new FailureMechanismSection(string.Empty, new[]
{
Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/packages.config
===================================================================
diff -u -r721d6f7ac6513e2219ff9bc652f3d6059061a009 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/packages.config (.../packages.config) (revision 721d6f7ac6513e2219ff9bc652f3d6059061a009)
+++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/packages.config (.../packages.config) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -24,4 +24,5 @@
+
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResult.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResult.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -67,7 +67,8 @@
public bool AssessmentLayerOne { get; set; }
///
- /// Gets or sets the single relevant .
+ /// Gets or sets the , which is chosen
+ /// to be representative for the whole section.
///
public GrassCoverErosionInwardsCalculation Calculation { get; set; }
}
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs
===================================================================
diff -u -rccf22c570f610fc47e18f8e92afc6aab2ee6c896 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision ccf22c570f610fc47e18f8e92afc6aab2ee6c896)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/PropertyClasses/GrassCoverErosionInwardsInputContextProperties.cs (.../GrassCoverErosionInwardsInputContextProperties.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -68,7 +68,7 @@
set
{
data.WrappedData.DikeProfile = value;
- AssignUnassignCalculations.Update(data.FailureMechanism.SectionResults, data.Calculation);
+ GrassCoverErosionInwardsHelper.Update(data.FailureMechanism.SectionResults, data.Calculation);
data.WrappedData.NotifyObservers();
}
}
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsScenariosView.cs
===================================================================
diff -u -rd39f2e1a0a36628bbd7751d426425d8f99b2b5af -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsScenariosView.cs (.../GrassCoverErosionInwardsScenariosView.cs) (revision d39f2e1a0a36628bbd7751d426425d8f99b2b5af)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsScenariosView.cs (.../GrassCoverErosionInwardsScenariosView.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -128,7 +128,7 @@
var calculations = data.GetCalculations();
Dictionary> caculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(failureMechanism.Sections, calculations.OfType());
+ GrassCoverErosionInwardsHelper.CollectCalculationsPerSection(failureMechanism.Sections, calculations.OfType());
List scenarioRows =
FailureMechanism.SectionResults.Select(sectionResult => new GrassCoverErosionInwardsScenarioRow(sectionResult)).ToList();
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs
===================================================================
diff -u -r98929f84fbf311bd19d8e61cc8499cdb40b22ea0 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 98929f84fbf311bd19d8e61cc8499cdb40b22ea0)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -517,7 +517,7 @@
}
};
target.Children.Add(calculation);
- AssignUnassignCalculations.Update(failureMechanism.SectionResults, calculation);
+ GrassCoverErosionInwardsHelper.Update(failureMechanism.SectionResults, calculation);
}
}
@@ -618,7 +618,7 @@
if (calculationGroupContext != null)
{
calculationGroupContext.WrappedData.Children.Remove(context.WrappedData);
- AssignUnassignCalculations.Delete(context.FailureMechanism.SectionResults, context.WrappedData, context.FailureMechanism.Calculations.OfType());
+ GrassCoverErosionInwardsHelper.Delete(context.FailureMechanism.SectionResults, context.WrappedData, context.FailureMechanism.Calculations.OfType());
calculationGroupContext.NotifyObservers();
}
}
Fisheye: Tag 38600213ce6ca43c1819c81dd95c8ce786650ac3 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/AssignUnassignCalculations.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/GrassCoverErosionInwardsHelper.cs
===================================================================
diff -u -r277b68e1c58f97f527567f5500be6bc39efacd97 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/GrassCoverErosionInwardsHelper.cs (.../GrassCoverErosionInwardsHelper.cs) (revision 277b68e1c58f97f527567f5500be6bc39efacd97)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/GrassCoverErosionInwardsHelper.cs (.../GrassCoverErosionInwardsHelper.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Utils;
@@ -29,96 +30,150 @@
namespace Ringtoets.GrassCoverErosionInwards.Utils
{
///
- /// Class holds helper methods to match objects
+ /// Class which defines helper methods to match objects
/// with objects.
///
public static class GrassCoverErosionInwardsHelper
{
///
/// Determine which objects are available for a
- /// .
+ /// .
///
- /// The objects.
- /// The objects.
+ /// The objects.
+ /// The objects.
/// A containing a
- /// of objects
+ /// of objects
/// for each section name which has calculations.
- /// When any input parameter is null.
- public static Dictionary> CollectCalculationsPerSegment(
- IEnumerable sections,
- IEnumerable calculations)
+ /// Thrown when any input parameter is null
+ /// or when an element in is null
+ /// Thrown when an element in is
+ /// null.
+ public static Dictionary> CollectCalculationsPerSection(IEnumerable sections, IEnumerable calculations)
{
- if (sections == null)
- {
- throw new ArgumentNullException("sections");
- }
+ return AssignUnassignCalculations.CollectCalculationsPerSection(sections, CalculationsToCalculationsWithLocations(calculations));
+ }
- if (calculations == null)
+ ///
+ /// Obtains the which intersects with the defined on
+ /// .
+ ///
+ /// The of to iterate over when trying to find a match
+ /// with the location of .
+ /// The which's location is used to match to the location of the
+ /// .
+ /// Returns the closest to or null if the
+ /// has no location.
+ /// Thrown when is null
+ /// Thrown when an element in is null.
+ ///
+ public static FailureMechanismSection FailureMechanismSectionForCalculation(IEnumerable sections, GrassCoverErosionInwardsCalculation calculation)
+ {
+ var asCalculationWithLocation = AsCalculationWithLocation(calculation);
+ if (asCalculationWithLocation != null)
{
- throw new ArgumentNullException("calculations");
+ return AssignUnassignCalculations.FailureMechanismSectionForCalculation(sections, asCalculationWithLocation);
}
+ return null;
+ }
- SectionSegments[] sectionSegments = SectionSegmentsHelper.MakeSectionSegments(sections);
+ ///
+ /// Updates the for each element of that have the
+ /// assigned, or should have the assigned.
+ ///
+ /// The of to iterate while
+ /// possibly updating the assigned to it.
+ /// The which has a location that has been updated.
+ /// When is null
+ /// Thrown when element in is
+ /// null.
+ public static void Update(IEnumerable sectionResults, GrassCoverErosionInwardsCalculation calculation)
+ {
+ ValidateSectionResults(sectionResults);
- var calculationsPerSegment = new Dictionary>();
-
- foreach (var calculation in calculations)
+ var asCalculationWithLocation = AsCalculationWithLocation(calculation);
+ if (asCalculationWithLocation != null)
{
- FailureMechanismSection section = FindSectionForCalculation(sectionSegments, calculation);
- if (section == null)
- {
- continue;
- }
-
- UpdateCalculationsOfSegment(calculationsPerSegment, section.Name, calculation);
+ AssignUnassignCalculations.Update(sectionResults.Select(AsCalculationAssignment), asCalculationWithLocation);
}
- return calculationsPerSegment;
}
///
- /// Determine which geometrically contains the .
+ /// Removed the for each
+ /// element of that have the assigned.
///
- /// The objects
- /// whose are considered.
- /// The .
- /// The containing , or null.
- /// When any input parameter is null.
- public static FailureMechanismSection FailureMechanismSectionForCalculation(
- IEnumerable sections,
- GrassCoverErosionInwardsCalculation calculation)
+ /// The of to iterate while
+ /// removing the reference to the if present.
+ /// The which has a location that has been updated.
+ /// The of that were left after removing
+ /// .
+ /// When any input parameter is null or when an element
+ /// in is null.
+ /// Thrown when element in is
+ /// null.
+ public static void Delete(IEnumerable sectionResults, GrassCoverErosionInwardsCalculation calculation, IEnumerable calculations)
{
- if (sections == null)
+ ValidateSectionResults(sectionResults);
+
+ AssignUnassignCalculations.Delete(
+ sectionResults.Select(AsCalculationAssignment),
+ calculation,
+ CalculationsToCalculationsWithLocations(calculations));
+ }
+
+ ///
+ /// Transforms the into and filter out the calculations
+ /// for which a could not be made.
+ ///
+ /// The collection to transform.
+ /// A collection of .
+ /// Thrown when is null or when
+ /// an element in is null.
+ private static IEnumerable CalculationsToCalculationsWithLocations(IEnumerable calculations)
+ {
+ if (calculations == null)
{
- throw new ArgumentNullException("sections");
+ throw new ArgumentNullException("calculations");
}
+ return calculations.Select(AsCalculationWithLocation).Where(c => c != null);
+ }
+ ///
+ /// Transforms the into a .
+ ///
+ /// The to transform.
+ /// A new or null if the calculation had no value
+ /// or had no dike profile assigned.
+ /// Thrown when is null.
+ private static CalculationWithLocation AsCalculationWithLocation(GrassCoverErosionInwardsCalculation calculation)
+ {
if (calculation == null)
{
throw new ArgumentNullException("calculation");
}
-
- SectionSegments[] sectionSegments = SectionSegmentsHelper.MakeSectionSegments(sections);
-
- return FindSectionForCalculation(sectionSegments, calculation);
+ if (calculation.InputParameters.DikeProfile == null)
+ {
+ return null;
+ }
+ return new CalculationWithLocation(calculation, calculation.InputParameters.DikeProfile.WorldReferencePoint);
}
- private static FailureMechanismSection FindSectionForCalculation(SectionSegments[] sectionSegmentsCollection,
- GrassCoverErosionInwardsCalculation calculation)
+ private static void ValidateSectionResults(IEnumerable sectionResults)
{
- var dikeProfile = calculation.InputParameters.DikeProfile;
- return dikeProfile != null
- ? SectionSegmentsHelper.GetSectionForPoint(sectionSegmentsCollection, dikeProfile.WorldReferencePoint)
- : null;
+ if (sectionResults == null)
+ {
+ throw new ArgumentNullException("sectionResults");
+ }
+ if (sectionResults.Any(sr => sr == null))
+ {
+ throw new ArgumentException("SectionResults contains an entry without value.", "sectionResults");
+ }
}
- private static void UpdateCalculationsOfSegment(Dictionary> calculationsPerSegment,
- string sectionName, GrassCoverErosionInwardsCalculation calculation)
+ private static SectionResultWithCalculationAssignment AsCalculationAssignment(GrassCoverErosionInwardsFailureMechanismSectionResult failureMechanismSectionResult)
{
- if (!calculationsPerSegment.ContainsKey(sectionName))
- {
- calculationsPerSegment.Add(sectionName, new List());
- }
- calculationsPerSegment[sectionName].Add(calculation);
+ return new SectionResultWithCalculationAssignment(failureMechanismSectionResult,
+ result => ((GrassCoverErosionInwardsFailureMechanismSectionResult) result).Calculation,
+ (result, calculation) => ((GrassCoverErosionInwardsFailureMechanismSectionResult) result).Calculation = (GrassCoverErosionInwardsCalculation) calculation);
}
}
}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/Ringtoets.GrassCoverErosionInwards.Utils.csproj
===================================================================
diff -u -r721d6f7ac6513e2219ff9bc652f3d6059061a009 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/Ringtoets.GrassCoverErosionInwards.Utils.csproj (.../Ringtoets.GrassCoverErosionInwards.Utils.csproj) (revision 721d6f7ac6513e2219ff9bc652f3d6059061a009)
+++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Utils/Ringtoets.GrassCoverErosionInwards.Utils.csproj (.../Ringtoets.GrassCoverErosionInwards.Utils.csproj) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -39,7 +39,6 @@
Properties\GlobalAssembly.cs
-
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsScenariosViewTest.cs
===================================================================
diff -u -rd39f2e1a0a36628bbd7751d426425d8f99b2b5af -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsScenariosViewTest.cs (.../GrassCoverErosionInwardsScenariosViewTest.cs) (revision d39f2e1a0a36628bbd7751d426425d8f99b2b5af)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsScenariosViewTest.cs (.../GrassCoverErosionInwardsScenariosViewTest.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -290,7 +290,7 @@
var dataGridViewColumn = (DataGridViewComboBoxColumn) dataGridView.Columns[1];
Assert.AreEqual(failureMechanism.SectionResults.Count(), rowCount);
- Assert.AreEqual(failureMechanism.CalculationsGroup.GetCalculations().Count(), dataGridViewColumn.Items.Count);
+ Assert.AreEqual(failureMechanism.Calculations.Count(), dataGridViewColumn.Items.Count);
for (int i = 0; i < rowCount; i++)
{
Fisheye: Tag 38600213ce6ca43c1819c81dd95c8ce786650ac3 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/AssignUnassignCalculationsTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsHelperTest.cs
===================================================================
diff -u -r277b68e1c58f97f527567f5500be6bc39efacd97 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsHelperTest.cs (.../GrassCoverErosionInwardsHelperTest.cs) (revision 277b68e1c58f97f527567f5500be6bc39efacd97)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/GrassCoverErosionInwardsHelperTest.cs (.../GrassCoverErosionInwardsHelperTest.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -21,9 +21,10 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Core.Common.Base.Geometry;
+using Core.Common.TestUtil;
using NUnit.Framework;
-using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.GrassCoverErosionInwards.Data;
@@ -36,286 +37,337 @@
private const string firstSectionName = "firstSection";
private const string secondSectionName = "secondSection";
+ #region Prepared data
+
+ private static readonly FailureMechanismSection failureMechanismSectionA = new FailureMechanismSection(firstSectionName, new List
+ {
+ new Point2D(0.0, 0.0),
+ new Point2D(10.0, 10.0),
+ });
+
+ private static readonly FailureMechanismSection failureMechanismSectionB = new FailureMechanismSection(secondSectionName, new List
+ {
+ new Point2D(11.0, 11.0),
+ new Point2D(100.0, 100.0),
+ });
+
+ private static readonly GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(
+ failureMechanismSectionA);
+
private readonly FailureMechanismSection[] oneSection =
{
- new FailureMechanismSection("testFailureMechanismSection", new List
- {
- new Point2D(0.0, 0.0)
- })
+ failureMechanismSectionA
};
private readonly FailureMechanismSection[] twoSections =
{
- new FailureMechanismSection(firstSectionName, new List
+ failureMechanismSectionA,
+ failureMechanismSectionB
+ };
+
+ private readonly GrassCoverErosionInwardsCalculation calculationInSectionA = new GrassCoverErosionInwardsCalculation
+ {
+ InputParameters =
{
- new Point2D(0.0, 0.0),
- new Point2D(10.0, 10.0),
- }),
- new FailureMechanismSection(secondSectionName, new List
- {
- new Point2D(11.0, 11.0),
- new Point2D(100.0, 100.0),
- })
+ DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0], null,
+ new DikeProfile.ConstructionProperties())
+ }
};
- private readonly GrassCoverErosionInwardsCalculation[] twoCalculations =
+ private readonly GrassCoverErosionInwardsCalculation calculationInSectionB = new GrassCoverErosionInwardsCalculation
{
- new GrassCoverErosionInwardsCalculation
+ InputParameters =
{
- InputParameters =
- {
- DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
- },
- new GrassCoverErosionInwardsCalculation
- {
- InputParameters =
- {
- DikeProfile = new DikeProfile(new Point2D(3.3, 4.4), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
+ DikeProfile = new DikeProfile(new Point2D(50.0, 66.0), new RoughnessPoint[0], new Point2D[0],
+ null, new DikeProfile.ConstructionProperties())
}
};
+ #endregion
+
+
[Test]
- public void CollectCalculationsPerSegment_SectionResultsNull_ThrowsArgumentNullException()
+ public void CollectCalculationsPerSection_SectionsAreNull_ThrowsArgumentNullException()
{
- // Setup
- var calculations = new GrassCoverErosionInwardsCalculation[0];
-
// Call
- TestDelegate call = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(null, calculations);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSection(
+ null,
+ new GrassCoverErosionInwardsCalculation[]
+ {
+ null
+ });
// Assert
- string paramName = Assert.Throws(call).ParamName;
- Assert.AreEqual("sections", paramName);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sections", exception.ParamName);
}
[Test]
- public void CollectCalculationsPerSegment_CalculationsNull_ThrowsArgumentNullException()
+ public void CollectCalculationsPerSection_SectionElementsAreNull_ThrowsArgumentException()
{
// Call
- TestDelegate call = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, null);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSection(
+ new FailureMechanismSection[]
+ {
+ null,
+ null
+ },
+ new[]
+ {
+ calculationInSectionA
+ });
// Assert
- string paramName = Assert.Throws(call).ParamName;
- Assert.AreEqual("calculations", paramName);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sections", exception.ParamName);
}
[Test]
- public void CollectCalculationsPerSegment_ValidEmptySectionResults_EmptyDictionary()
+ public void CollectCalculationsPerSection_CalculationsAreNull_ThrowsArgumentNullException()
{
- // Setup
- var emptySections = new FailureMechanismSection[0];
-
// Call
- Dictionary> collectCalculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(emptySections, twoCalculations);
-
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSection(
+ twoSections,
+ null);
+
// Assert
- Assert.AreEqual(0, collectCalculationsPerSegment.Count);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculations", exception.ParamName);
}
[Test]
- public void CollectCalculationsPerSegment_ValidEmptyCalculations_EmptyDictionary()
+ public void CollectCalculationsPerSection_CalculationElementsAreNull_ThrowsArgumentNullException()
{
- // Setup
- var calculations = new GrassCoverErosionInwardsCalculation[0];
+ // Call
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSection(
+ twoSections,
+ new GrassCoverErosionInwardsCalculation[]
+ {
+ null
+ });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculation", exception.ParamName);
+ }
+ [Test]
+ public void FailureMechanismSectionForCalculation_CalculationNull_ThrowsArgumentNullException()
+ {
// Call
- Dictionary> collectCalculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, calculations);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(
+ twoSections,
+ null);
// Assert
- Assert.AreEqual(0, collectCalculationsPerSegment.Count);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculation", exception.ParamName);
}
[Test]
- public void CollectCalculationsPerSegment_CalculationsWithoutDikeProfiles_EmptyDictionary()
+ public void FailureMechanismSectionForCalculation_SectionsNull_ThrowsArgumentNullException()
{
- // Setup
- GrassCoverErosionInwardsCalculation[] calculations =
- {
- new GrassCoverErosionInwardsCalculation(),
- new GrassCoverErosionInwardsCalculation()
- };
+ // Call
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(
+ null,
+ calculationInSectionA);
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sections", exception.ParamName);
+ }
+
+ [Test]
+ public void FailureMechanismSectionForCalculation_SectionElementsNull_ThrowsArgumentException()
+ {
// Call
- Dictionary> collectCalculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, calculations);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(
+ new FailureMechanismSection[]
+ {
+ null,
+ null
+ },
+ calculationInSectionA);
// Assert
- Assert.AreEqual(0, collectCalculationsPerSegment.Count);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sections", exception.ParamName);
}
[Test]
- public void CollectCalculationsPerSegment_MultipleCalculationsInSegment_OneSegmentHasAllCalculations()
+ public void FailureMechanismSectionForCalculation_CalculationWithoutDikeProfile_ReturnsNull()
{
+ // Setup
+ var calculation = new GrassCoverErosionInwardsCalculation();
+
// Call
- Dictionary> collectCalculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(twoSections, twoCalculations);
+ FailureMechanismSection failureMechanismSection =
+ GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, calculation);
// Assert
- Assert.AreEqual(1, collectCalculationsPerSegment.Count);
- Assert.IsTrue(collectCalculationsPerSegment.ContainsKey(firstSectionName));
- CollectionAssert.AreEqual(twoCalculations, collectCalculationsPerSegment[firstSectionName]);
+ Assert.IsNull(failureMechanismSection);
}
[Test]
- public void CollectCalculationsPerSegment_SingleCalculationPerSegment_OneCalculationPerSegment()
+ public void FailureMechanismSectionForCalculation_ValidEmptySectionResults_ReturnsNull()
{
// Setup
- GrassCoverErosionInwardsCalculation[] calculations =
+ var emptySections = new FailureMechanismSection[0];
+ var calculation = new GrassCoverErosionInwardsCalculation
{
- new GrassCoverErosionInwardsCalculation
+ InputParameters =
{
- InputParameters =
- {
- DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
- },
- new GrassCoverErosionInwardsCalculation
- {
- InputParameters =
- {
- DikeProfile = new DikeProfile(new Point2D(50.0, 66.0), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
+ DikeProfile = new DikeProfile(new Point2D(0, 0),
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ null,
+ new DikeProfile.ConstructionProperties())
}
};
// Call
- Dictionary> collectCalculationsPerSegment =
- GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(twoSections, calculations);
+ FailureMechanismSection failureMechanismSection =
+ GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(emptySections, calculation);
// Assert
- Assert.AreEqual(2, collectCalculationsPerSegment.Count);
- Assert.AreEqual(1, collectCalculationsPerSegment[firstSectionName].Count);
- Assert.AreSame(calculations[0], collectCalculationsPerSegment[firstSectionName][0]);
- Assert.AreEqual(1, collectCalculationsPerSegment[secondSectionName].Count);
- Assert.AreSame(calculations[1], collectCalculationsPerSegment[secondSectionName][0]);
+ Assert.IsNull(failureMechanismSection);
}
[Test]
- public void FailureMechanismSectionForCalculation_SectionResultAndCalculationNull_ThrowsArgumentNullException()
+ public void FailureMechanismSectionForCalculation_FirstSectionResultContainsCalculation_FailureMechanismSectionOfFirstSectionResult()
{
// Call
- TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(null, null);
+ FailureMechanismSection failureMechanismSection =
+ GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculationInSectionA);
// Assert
- Assert.Throws(call);
+ Assert.AreSame(twoSections[0], failureMechanismSection);
}
[Test]
- public void FailureMechanismSectionForCalculation_SectionResultsNull_ThrowsArgumentNullException()
+ public void FailureMechanismSectionForCalculation_SecondSectionResultContainsCalculation_FailureMechanismSectionOfSecondSectionResult()
{
- // Setup
- var calculation = new GrassCoverErosionInwardsCalculation();
-
// Call
- TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(null, calculation);
+ FailureMechanismSection failureMechanismSection =
+ GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculationInSectionB);
// Assert
- string paramName = Assert.Throws(call).ParamName;
- Assert.AreEqual("sections", paramName);
+ Assert.AreSame(twoSections[1], failureMechanismSection);
}
[Test]
- public void FailureMechanismSectionForCalculation_CalculationNull_ThrowsArgumentNullException()
+ public void Update_SectionResultsNull_ThrowsArgumentNullException()
{
// Call
- TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, null);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Update(
+ null,
+ calculationInSectionA);
// Assert
- string paramName = Assert.Throws(call).ParamName;
- Assert.AreEqual("calculation", paramName);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sectionResults", exception.ParamName);
}
[Test]
- public void FailureMechanismSectionForCalculation_CalculationWithoutDikeProfile_ReturnsNull()
+ public void Update_SectionResultElementsNull_ThrowsArgumentException()
{
- // Setup
- var calculation = new GrassCoverErosionInwardsCalculation();
-
// Call
- FailureMechanismSection failureMechanismSection =
- GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, calculation);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Update(
+ new GrassCoverErosionInwardsFailureMechanismSectionResult[]
+ {
+ null,
+ null
+ },
+ calculationInSectionA);
// Assert
- Assert.IsNull(failureMechanismSection);
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(
+ test, "SectionResults contains an entry without value.");
+ Assert.AreEqual("sectionResults", exception.ParamName);
}
[Test]
- public void FailureMechanismSectionForCalculation_SectionResultsEmpty_ReturnsNull()
+ public void Delete_SectionResultsNull_ThrowsArgumentNullException()
{
- // Setup
- var calculation = new GrassCoverErosionInwardsCalculation();
-
// Call
- FailureMechanismSection failureMechanismSection =
- GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, calculation);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Delete(
+ null,
+ calculationInSectionA,
+ new [] { calculationInSectionB });
// Assert
- Assert.IsNull(failureMechanismSection);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("sectionResults", exception.ParamName);
}
[Test]
- public void FailureMechanismSectionForCalculation_ValidEmptySectionResults_ReturnsNull()
+ public void Delete_SectionResultElementsNull_ThrowsArgumentException()
{
- // Setup
- var emptySections = new FailureMechanismSection[0];
- var calculation = new GrassCoverErosionInwardsCalculation();
-
// Call
- FailureMechanismSection failureMechanismSection =
- GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(emptySections, calculation);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Delete(
+ new GrassCoverErosionInwardsFailureMechanismSectionResult[]
+ {
+ null,
+ null
+ },
+ calculationInSectionA,
+ new [] { calculationInSectionB });
// Assert
- Assert.IsNull(failureMechanismSection);
+ ArgumentException exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(
+ test, "SectionResults contains an entry without value.");
+ Assert.AreEqual("sectionResults", exception.ParamName);
}
[Test]
- public void FailureMechanismSectionForCalculation_FirstSectionResultContainsCalculation_FailureMechanismSectionOfFirstSectionResult()
+ public void Delete_CalculationNull_ThrowsArgumentNullException()
{
- // Setup
- var calculation = new GrassCoverErosionInwardsCalculation
- {
- InputParameters =
+ // Call
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Delete(
+ new[]
{
- DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
- };
+ sectionResult
+ },
+ null,
+ new[] { calculationInSectionA });
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculation", exception.ParamName);
+ }
+
+ [Test]
+ public void Delete_CalculationsNull_ThrowsArgumentNullException()
+ {
// Call
- FailureMechanismSection failureMechanismSection =
- GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculation);
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Delete(
+ new[]
+ {
+ sectionResult
+ },
+ calculationInSectionA,
+ null);
// Assert
- Assert.AreSame(twoSections[0], failureMechanismSection);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculations", exception.ParamName);
}
[Test]
- public void FailureMechanismSectionForCalculation_SecondSectionResultContainsCalculation_FailureMechanismSectionOfSecondSectionResult()
+ public void Delete_CalculationsElementNull_ThrowsArgumentNullException()
{
- // Setup
- var calculation = new GrassCoverErosionInwardsCalculation
- {
- InputParameters =
+ // Call
+ TestDelegate test = () => GrassCoverErosionInwardsHelper.Delete(
+ new[]
{
- DikeProfile = new DikeProfile(new Point2D(50.0, 66.0), new RoughnessPoint[0], new Point2D[0],
- null, new DikeProfile.ConstructionProperties())
- }
- };
+ sectionResult
+ },
+ calculationInSectionA,
+ new GrassCoverErosionInwardsCalculation[] { null });
- // Call
- FailureMechanismSection failureMechanismSection =
- GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculation);
-
// Assert
- Assert.AreSame(twoSections[1], failureMechanismSection);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("calculation", exception.ParamName);
}
}
}
\ No newline at end of file
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/Ringtoets.GrassCoverErosionInwards.Utils.Test.csproj
===================================================================
diff -u -r3d84064b23186da3fb11f19ff0d07f41e1209bbb -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/Ringtoets.GrassCoverErosionInwards.Utils.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Utils.Test.csproj) (revision 3d84064b23186da3fb11f19ff0d07f41e1209bbb)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/Ringtoets.GrassCoverErosionInwards.Utils.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Utils.Test.csproj) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -42,14 +42,17 @@
..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll
True
+
+ ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
+ True
+
Properties\GlobalAssembly.cs
-
@@ -65,6 +68,10 @@
{3BBFD65B-B277-4E50-AE6D-BD24C3434609}
Core.Common.Base
+
+ {D749EE4C-CE50-4C17-BF01-9A953028C126}
+ Core.Common.TestUtil
+
{D4200F43-3F72-4F42-AF0A-8CED416A38EC}
Ringtoets.Common.Data
Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/packages.config
===================================================================
diff -u -r66c3a121906a47ea4164e2a657e0b43d86e2f269 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/packages.config (.../packages.config) (revision 66c3a121906a47ea4164e2a657e0b43d86e2f269)
+++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Utils.Test/packages.config (.../packages.config) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -23,4 +23,5 @@
-->
+
\ No newline at end of file
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResult.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResult.cs (.../HeightStructuresFailureMechanismSectionResult.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResult.cs (.../HeightStructuresFailureMechanismSectionResult.cs) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -64,5 +64,11 @@
/// Gets or sets the state of the assessment layer one.
///
public bool AssessmentLayerOne { get; set; }
+
+ ///
+ /// Gets or sets the , which is chosen
+ /// to be representative for the whole section.
+ ///
+ public HeightStructuresCalculation Calculation { get; set; }
}
}
\ No newline at end of file
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj
===================================================================
diff -u -r2f94a4a9a4058aa718129ba8d399e5944a994070 -r38600213ce6ca43c1819c81dd95c8ce786650ac3
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision 2f94a4a9a4058aa718129ba8d399e5944a994070)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision 38600213ce6ca43c1819c81dd95c8ce786650ac3)
@@ -63,6 +63,13 @@
+
+
+ UserControl
+
+
+ HeightStructuresScenariosView.cs
+
UserControl
@@ -121,6 +128,9 @@
Resources.Designer.cs
Designer
+
+ HeightStructuresScenariosView.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file