Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -re73044fe9a7ef3d834a019841d04307fa7d2ec22 -r1fa9ae637530f3c6914b83a1afa751a422ebda98 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision e73044fe9a7ef3d834a019841d04307fa7d2ec22) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 1fa9ae637530f3c6914b83a1afa751a422ebda98) @@ -389,6 +389,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationCollectionReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationCollectionReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/HydraulicLocationCalculationCollectionReadExtensions.cs (revision 1fa9ae637530f3c6914b83a1afa751a422ebda98) @@ -0,0 +1,76 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Ringtoets.Common.Data.Hydraulics; + +namespace Application.Ringtoets.Storage.Read +{ + /// + /// This class defines extension methods for read operations for an of + /// based on the . + /// + internal static class HydraulicLocationCalculationCollectionReadExtensions + { + /// + /// Reads the and use the information to construct a + /// . + /// + /// The to update the + /// . + /// The target of the read operation. + /// The object keeping track of the read operations. + /// Thrown when any parameter is null. + internal static void Read(this HydraulicLocationCalculationCollectionEntity entity, + IEnumerable calculations, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + Dictionary dictionary = + calculations.ToDictionary(calc => calc.HydraulicBoundaryLocation, calc => calc); + + foreach (HydraulicLocationCalculationEntity calculationEntity in entity.HydraulicLocationCalculationEntities) + { + HydraulicBoundaryLocation hydraulicBoundaryLocation = collector.Get(calculationEntity.HydraulicLocationEntity); + HydraulicBoundaryLocationCalculation calculation = dictionary[hydraulicBoundaryLocation]; + + calculationEntity.Read(calculation); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -re73044fe9a7ef3d834a019841d04307fa7d2ec22 -r1fa9ae637530f3c6914b83a1afa751a422ebda98 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision e73044fe9a7ef3d834a019841d04307fa7d2ec22) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 1fa9ae637530f3c6914b83a1afa751a422ebda98) @@ -107,6 +107,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/HydraulicLocationCalculationCollectionEntityReadExtensionsTest.cs (revision 1fa9ae637530f3c6914b83a1afa751a422ebda98) @@ -0,0 +1,138 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using Application.Ringtoets.Storage.TestUtil.Hydraulics; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class HydraulicLocationCalculationCollectionEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((HydraulicLocationCalculationCollectionEntity) null).Read(Enumerable.Empty(), + new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(null, new ReadConversionCollector()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Read_CollectorNull_ThrowsArgumentNullException() + { + // Setup + var entity = new HydraulicLocationCalculationCollectionEntity(); + + // Call + TestDelegate call = () => entity.Read(Enumerable.Empty(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void Read_EntityWithValidValues_SetsCalculationsWithExpectedValues() + { + // Setup + var random = new Random(21); + + HydraulicLocationEntity hydraulicLocationEntityOne = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var calculationEntityWithoutOutput = new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntityOne, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()) + }; + + HydraulicLocationEntity hydraulicLocationEntityTwo = HydraulicLocationEntityTestFactory.CreateHydraulicLocationEntity(); + var calculationEntityWithOutput = new HydraulicLocationCalculationEntity + { + HydraulicLocationEntity = hydraulicLocationEntityTwo, + ShouldIllustrationPointsBeCalculated = Convert.ToByte(random.NextBoolean()), + HydraulicLocationOutputEntities = + { + new HydraulicLocationOutputEntity() + } + }; + + var collectionEntity = new HydraulicLocationCalculationCollectionEntity + { + HydraulicLocationCalculationEntities = + { + calculationEntityWithoutOutput, + calculationEntityWithOutput + } + }; + + var hydraulicBoundaryLocationOne = new TestHydraulicBoundaryLocation("1"); + var hydraulicBoundaryLocationTwo = new TestHydraulicBoundaryLocation("2"); + var collector = new ReadConversionCollector(); + collector.Read(hydraulicLocationEntityOne, hydraulicBoundaryLocationOne); + collector.Read(hydraulicLocationEntityTwo, hydraulicBoundaryLocationTwo); + + var calculationOne = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationOne); + var calculationTwo = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocationTwo); + + // Call + collectionEntity.Read(new[] + { + calculationOne, + calculationTwo + }, collector); + + // Assert + Assert.AreEqual(Convert.ToBoolean(calculationEntityWithoutOutput.ShouldIllustrationPointsBeCalculated), + calculationOne.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNull(calculationOne.Output); + + Assert.AreEqual(Convert.ToBoolean(calculationEntityWithOutput.ShouldIllustrationPointsBeCalculated), + calculationTwo.InputParameters.ShouldIllustrationPointsBeCalculated); + Assert.IsNotNull(calculationTwo.Output); + } + } +} \ No newline at end of file