Index: Ringtoets/Common/src/Ringtoets.Common.Util/AggregatedHydraulicBoundaryLocationFactory.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Util/AggregatedHydraulicBoundaryLocationFactory.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Util/AggregatedHydraulicBoundaryLocationFactory.cs (revision 5ddc9c8c424e9a85e22bde50f7133111cbf16348)
@@ -0,0 +1,94 @@
+// 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.Data;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Data.Hydraulics;
+
+namespace Ringtoets.Common.Util
+{
+ ///
+ /// Factory for creating instances.
+ ///
+ public static class AggregatedHydraulicBoundaryLocationFactory
+ {
+ ///
+ /// Creates the aggregated hydraulic boundary locations based on the locations and calculations
+ /// from an assessment section.
+ ///
+ /// The assessment section to get the locations and calculations from.
+ /// An of .
+ /// Thrown when is null.
+ public static IEnumerable CreateAggregatedHydraulicBoundaryLocations(IAssessmentSection assessmentSection)
+ {
+ if (assessmentSection == null)
+ {
+ throw new ArgumentNullException(nameof(assessmentSection));
+ }
+
+ Dictionary waterLevelLookupForFactorizedSignalingNorm =
+ assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waterLevelLookupForSignalingNorm =
+ assessmentSection.WaterLevelCalculationsForSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waterLevelLookupForLowerLimitNorm =
+ assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waterLevelLookupForFactorizedLowerLimitNorm =
+ assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+
+ Dictionary waveHeightLookupForFactorizedSignalingNorm =
+ assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waveHeightLookupForSignalingNorm =
+ assessmentSection.WaveHeightCalculationsForSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waveHeightLookupForLowerLimitNorm =
+ assessmentSection.WaveHeightCalculationsForLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+ Dictionary waveHeightLookupForFactorizedLowerLimitNorm =
+ assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation,
+ c => c);
+
+ return assessmentSection.HydraulicBoundaryDatabase.Locations
+ .Select(location => new AggregatedHydraulicBoundaryLocation(
+ location.Id, location.Name, location.Location,
+ GetCalculationResult(waterLevelLookupForFactorizedSignalingNorm[location].Output),
+ GetCalculationResult(waterLevelLookupForSignalingNorm[location].Output),
+ GetCalculationResult(waterLevelLookupForLowerLimitNorm[location].Output),
+ GetCalculationResult(waterLevelLookupForFactorizedLowerLimitNorm[location].Output),
+ GetCalculationResult(waveHeightLookupForFactorizedSignalingNorm[location].Output),
+ GetCalculationResult(waveHeightLookupForSignalingNorm[location].Output),
+ GetCalculationResult(waveHeightLookupForLowerLimitNorm[location].Output),
+ GetCalculationResult(waveHeightLookupForFactorizedLowerLimitNorm[location].Output))).ToArray();
+ }
+
+ private static RoundedDouble GetCalculationResult(HydraulicBoundaryLocationOutput output)
+ {
+ return output?.Result ?? RoundedDouble.NaN;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Util/Ringtoets.Common.Util.csproj
===================================================================
diff -u -r174c7e1a90b17034a5d75a995037cd32f696b55d -r5ddc9c8c424e9a85e22bde50f7133111cbf16348
--- Ringtoets/Common/src/Ringtoets.Common.Util/Ringtoets.Common.Util.csproj (.../Ringtoets.Common.Util.csproj) (revision 174c7e1a90b17034a5d75a995037cd32f696b55d)
+++ Ringtoets/Common/src/Ringtoets.Common.Util/Ringtoets.Common.Util.csproj (.../Ringtoets.Common.Util.csproj) (revision 5ddc9c8c424e9a85e22bde50f7133111cbf16348)
@@ -12,6 +12,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs (revision 5ddc9c8c424e9a85e22bde50f7133111cbf16348)
@@ -0,0 +1,129 @@
+// 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.Data;
+using NUnit.Framework;
+using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.TestUtil;
+
+namespace Ringtoets.Common.Util.Test
+{
+ [TestFixture]
+ public class AggregatedHydraulicBoundaryLocationFactoryTest
+ {
+ [Test]
+ public void CreateAggregatedHydraulicBoundaryLocations_AssessmentSectionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => AggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations(null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("assessmentSection", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateAggregatedHydraulicBoundaryLocations_AssessmentSectionWithLocationsWithOutput_ReturnAggregatedHydraulicBoundaryLocations()
+ {
+ // Setup
+ var assessmentSection = new ObservableTestAssessmentSectionStub();
+ assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "location1", 1, 1), true);
+ assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(2, "location2", 2, 2), true);
+
+ // Call
+ AggregatedHydraulicBoundaryLocation[] aggregatedLocations = AggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations(assessmentSection).ToArray();
+
+ // Assert
+ HydraulicBoundaryLocation[] expectedLocations = assessmentSection.HydraulicBoundaryDatabase.Locations.ToArray();
+ Assert.AreEqual(expectedLocations.Length, aggregatedLocations.Length);
+
+ for (var i = 0; i < expectedLocations.Length; i++)
+ {
+ Assert.AreEqual(expectedLocations[i].Id, aggregatedLocations[i].Id);
+ Assert.AreEqual(expectedLocations[i].Name, aggregatedLocations[i].Name);
+ Assert.AreEqual(expectedLocations[i].Location, aggregatedLocations[i].Location);
+
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaterLevelCalculationForFactorizedSignalingNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForSignalingNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaterLevelCalculationForSignalingNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForLowerLimitNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaterLevelCalculationForLowerLimitNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaterLevelCalculationForFactorizedLowerLimitNorm);
+
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaveHeightCalculationForFactorizedSignalingNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForSignalingNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaveHeightCalculationForSignalingNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForLowerLimitNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaveHeightCalculationForLowerLimitNorm);
+ Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, expectedLocations[i]),
+ aggregatedLocations[i].WaveHeightCalculationForFactorizedLowerLimitNorm);
+ }
+ }
+
+ [Test]
+ public void CreateAggregatedHydraulicBoundaryLocations_AssessmentSectionWithLocationsWithoutOutput_ReturnAggregatedHydraulicBoundaryLocations()
+ {
+ // Setup
+ var assessmentSection = new ObservableTestAssessmentSectionStub();
+ assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "location1", 1, 1));
+ assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(2, "location2", 2, 2));
+
+ // Call
+ AggregatedHydraulicBoundaryLocation[] aggregatedLocations = AggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations(assessmentSection).ToArray();
+
+ // Assert
+ HydraulicBoundaryLocation[] expectedLocations = assessmentSection.HydraulicBoundaryDatabase.Locations.ToArray();
+ Assert.AreEqual(expectedLocations.Length, aggregatedLocations.Length);
+
+ for (var i = 0; i < expectedLocations.Length; i++)
+ {
+ Assert.AreEqual(expectedLocations[i].Id, aggregatedLocations[i].Id);
+ Assert.AreEqual(expectedLocations[i].Name, aggregatedLocations[i].Name);
+ Assert.AreEqual(expectedLocations[i].Location, aggregatedLocations[i].Location);
+
+ Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForFactorizedSignalingNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForSignalingNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForLowerLimitNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForFactorizedLowerLimitNorm);
+
+ Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForFactorizedSignalingNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForSignalingNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForLowerLimitNorm);
+ Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForFactorizedLowerLimitNorm);
+ }
+ }
+
+ private static RoundedDouble GetExpectedResult(IEnumerable calculationList,
+ HydraulicBoundaryLocation hydraulicBoundaryLocation1)
+ {
+ return calculationList
+ .Where(calculation => calculation.HydraulicBoundaryLocation.Equals(hydraulicBoundaryLocation1))
+ .Select(calculation => calculation.Output.Result)
+ .Single();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Util.Test/Ringtoets.Common.Util.Test.csproj
===================================================================
diff -u -r174c7e1a90b17034a5d75a995037cd32f696b55d -r5ddc9c8c424e9a85e22bde50f7133111cbf16348
--- Ringtoets/Common/test/Ringtoets.Common.Util.Test/Ringtoets.Common.Util.Test.csproj (.../Ringtoets.Common.Util.Test.csproj) (revision 174c7e1a90b17034a5d75a995037cd32f696b55d)
+++ Ringtoets/Common/test/Ringtoets.Common.Util.Test/Ringtoets.Common.Util.Test.csproj (.../Ringtoets.Common.Util.Test.csproj) (revision 5ddc9c8c424e9a85e22bde50f7133111cbf16348)
@@ -19,6 +19,7 @@
+