Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r24abd892006b14b66532bf51acf9c1e987aa404e -r993abad2c25b543f2fce10da1646f98da880a54b --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 24abd892006b14b66532bf51acf9c1e987aa404e) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 993abad2c25b543f2fce10da1646f98da880a54b) @@ -376,6 +376,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensions.cs (revision 993abad2c25b543f2fce10da1646f98da880a54b) @@ -0,0 +1,66 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Ringtoets.DuneErosion.Data; + +namespace Application.Ringtoets.Storage.Create.DuneErosion +{ + /// + /// Extension methods for collections of related to creating a + /// . + /// + internal static class DuneLocationCalculationCollectionCreateExtensions + { + /// + /// Creates a based on the information + /// of the . + /// + /// The collection of + /// to create a database entity for. + /// The object keeping track of create operations. + /// A new . + /// Thrown when any parameter is null. + internal static DuneLocationCalculationCollectionEntity Create(this IEnumerable calculations, + PersistenceRegistry registry) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + var collectionEntity = new DuneLocationCalculationCollectionEntity(); + foreach (DuneLocationCalculation calculation in calculations) + { + collectionEntity.DuneLocationCalculationEntities.Add(calculation.Create(registry)); + } + + return collectionEntity; + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r24abd892006b14b66532bf51acf9c1e987aa404e -r993abad2c25b543f2fce10da1646f98da880a54b --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 24abd892006b14b66532bf51acf9c1e987aa404e) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 993abad2c25b543f2fce10da1646f98da880a54b) @@ -47,6 +47,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/DuneErosion/DuneLocationCalculationCollectionCreateExtensionsTest.cs (revision 993abad2c25b543f2fce10da1646f98da880a54b) @@ -0,0 +1,90 @@ +// 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.Create; +using Application.Ringtoets.Storage.Create.DuneErosion; +using Application.Ringtoets.Storage.DbContext; +using NUnit.Framework; +using Ringtoets.DuneErosion.Data; +using Ringtoets.DuneErosion.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Create.DuneErosion +{ + [TestFixture] + public class DuneLocationCalculationCollectionCreateExtensionsTest + { + [Test] + public void Create_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => + ((IEnumerable)null).Create(new PersistenceRegistry()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Create_RegistryNull_ThrowsArgumentNullException() + { + // Setup + IEnumerable calculations = + Enumerable.Empty(); + + // Call + TestDelegate call = () => calculations.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void Create_WithValidCollectionAndArguments_ReturnsEntity() + { + // Setup + var duneLocation = new TestDuneLocation(); + var calculation = new DuneLocationCalculation(duneLocation); + var calculations = new[] + { + calculation + }; + + var duneLocationEntity = new DuneLocationEntity(); + var registry = new PersistenceRegistry(); + registry.Register(duneLocationEntity, duneLocation); + + // Call + DuneLocationCalculationCollectionEntity entity = calculations.Create(registry); + + // Assert + Assert.IsNotNull(entity); + + DuneLocationCalculationEntity calculationEntity = entity.DuneLocationCalculationEntities.Single(); + Assert.AreSame(duneLocationEntity, calculationEntity.DuneLocationEntity); + CollectionAssert.IsEmpty(calculationEntity.DuneLocationOutputEntities); + } + } +} \ No newline at end of file