Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r2e520a68a32290ef4d8c89a5520227c3084612db -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 2e520a68a32290ef4d8c89a5520227c3084612db) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -54,6 +54,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/DikeAssessmentSectionEntityConverter.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/DikeAssessmentSectionEntityConverter.cs (.../DikeAssessmentSectionEntityConverter.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/DikeAssessmentSectionEntityConverter.cs (.../DikeAssessmentSectionEntityConverter.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -46,8 +46,15 @@ throw new ArgumentNullException("entity"); } - if (model() == null) + try { + if (model() == null) + { + throw new ArgumentNullException("model"); + } + } + catch (NullReferenceException) + { throw new ArgumentNullException("model"); } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/FailureMechanismEntityConverter.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/FailureMechanismEntityConverter.cs (.../FailureMechanismEntityConverter.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/FailureMechanismEntityConverter.cs (.../FailureMechanismEntityConverter.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -39,8 +39,15 @@ throw new ArgumentNullException("entity"); } - if (model() == null) + try { + if (model() == null) + { + throw new ArgumentNullException("model"); + } + } + catch (NullReferenceException) + { throw new ArgumentNullException("model"); } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -0,0 +1,71 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Geometry; +using Ringtoets.HydraRing.Data; + +namespace Application.Ringtoets.Storage.Converters +{ + /// + /// Converter for to + /// and to . + /// + public class HydraulicLocationConverter : IEntityConverter + { + public HydraulicBoundaryLocation ConvertEntityToModel(HydraulicLocationEntity entity, Func model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + + try + { + if (model() == null) + { + throw new ArgumentNullException("model"); + } + } + catch (NullReferenceException) + { + throw new ArgumentNullException("model"); + } + + HydraulicBoundaryLocation hydraulicBoundaryLocation = model(); + hydraulicBoundaryLocation.StorageId = entity.HydraulicLocationEntityId; + hydraulicBoundaryLocation.Name = entity.Name; + hydraulicBoundaryLocation.Location = new Point2D(Convert.ToDouble(entity.LocationX), Convert.ToDouble(entity.LocationY)); + + if (entity.DesignWaterLevel.HasValue) + { + hydraulicBoundaryLocation.DesignWaterLevel = (double)entity.DesignWaterLevel; + } + + return hydraulicBoundaryLocation; + } + + public void ConvertModelToEntity(HydraulicBoundaryLocation modelObject, HydraulicLocationEntity entity) + { + } + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs (.../ProjectEntityConverter.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs (.../ProjectEntityConverter.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -45,8 +45,15 @@ throw new ArgumentNullException("entity"); } - if (model() == null) + try { + if (model() == null) + { + throw new ArgumentNullException("model"); + } + } + catch (NullReferenceException) + { throw new ArgumentNullException("model"); } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs (.../DikeAssessmentSectionEntityPersistor.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs (.../DikeAssessmentSectionEntityPersistor.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -28,6 +28,7 @@ using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.Properties; +using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; namespace Application.Ringtoets.Storage.Persistors @@ -68,11 +69,17 @@ /// Loads the as . /// /// The to load. + /// The to obtain the model. /// A new instance of , based on the properties of . public DikeAssessmentSection LoadModel(DikeAssessmentSectionEntity entity, Func model) { var dikeAssessmentSection = converter.ConvertEntityToModel(entity, model); + foreach (var hydraulicLocationEntity in entity.HydraulicLocationEntities) + { + dikeAssessmentSection.HydraulicBoundaryDatabase.Locations.Add(hydraulicLocationEntityPersistor.LoadModel(hydraulicLocationEntity, () => new HydraulicBoundaryLocation())); + } + foreach (var failureMechanismEntity in entity.FailureMechanismEntities) { if (failureMechanismEntity.FailureMechanismType == (int) FailureMechanismType.DikesPipingFailureMechanism) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs =================================================================== diff -u -r2e520a68a32290ef4d8c89a5520227c3084612db -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs (.../HydraulicLocationEntityPersistor.cs) (revision 2e520a68a32290ef4d8c89a5520227c3084612db) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs (.../HydraulicLocationEntityPersistor.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -19,17 +19,80 @@ // 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.Converters; using Application.Ringtoets.Storage.DbContext; +using Ringtoets.HydraRing.Data; namespace Application.Ringtoets.Storage.Persistors { - public class HydraulicLocationEntityPersistor + public class HydraulicLocationEntityPersistor : IPersistor { private readonly IRingtoetsEntities ringtoetsContext; + private readonly HydraulicLocationConverter converter; + /// + /// Creates a new instance of . + /// + /// The storage context. + /// Thrown when is null. public HydraulicLocationEntityPersistor(IRingtoetsEntities ringtoetsContext) { + if (ringtoetsContext == null) + { + throw new ArgumentNullException("ringtoetsContext"); + } + this.ringtoetsContext = ringtoetsContext; + + converter = new HydraulicLocationConverter(); } + + public void UpdateModel(ICollection parentNavigationProperty, HydraulicBoundaryLocation model, int order) + { + } + + public void InsertModel(ICollection parentNavigationProperty, HydraulicBoundaryLocation model, int order) + { + } + + public void RemoveUnModifiedEntries(ICollection parentNavigationProperty) + { + } + + public void PerformPostSaveActions() + { + } + + public HydraulicBoundaryLocation LoadModel(HydraulicLocationEntity entity, Func model) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + + try + { + if (model() == null) + { + throw new ArgumentNullException("model"); + } + } + catch (NullReferenceException) + { + throw new ArgumentNullException("model"); + } + + return converter.ConvertEntityToModel(entity, model); + } + + public void UpdateChildren(HydraulicBoundaryLocation model, HydraulicLocationEntity entity) + { + } + + public void InsertChildren(HydraulicBoundaryLocation model, HydraulicLocationEntity entity) + { + } } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r764e7166b2f90c4abcbee28408fc77cbf6312afc -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 764e7166b2f90c4abcbee28408fc77cbf6312afc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -82,12 +82,14 @@ + + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/DikeAssessmentSectionEntityConverterTest.cs =================================================================== diff -u -r764e7166b2f90c4abcbee28408fc77cbf6312afc -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/DikeAssessmentSectionEntityConverterTest.cs (.../DikeAssessmentSectionEntityConverterTest.cs) (revision 764e7166b2f90c4abcbee28408fc77cbf6312afc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/DikeAssessmentSectionEntityConverterTest.cs (.../DikeAssessmentSectionEntityConverterTest.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Application.Ringtoets.Storage.Converters; using Application.Ringtoets.Storage.DbContext; using NUnit.Framework; @@ -10,6 +11,15 @@ [TestFixture] public class DikeAssessmentSectionEntityConverterTest { + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + [Test] public void DefaultConstructor_Always_NewDikeAssessmentSectionEntityConverter() { @@ -34,7 +44,8 @@ } [Test] - public void ConvertEntityToModel_ValidDikeAssessmentSectionEntityNullModel_ThrowsArgumentNullException() + [TestCaseSource("TestCases")] + public void ConvertEntityToModel_ValidDikeAssessmentSectionEntityNullModel_ThrowsArgumentNullException(Func func) { // Setup const long storageId = 1234L; @@ -52,7 +63,7 @@ DikeAssessmentSectionEntityConverter converter = new DikeAssessmentSectionEntityConverter(); // Call - TestDelegate test = () => converter.ConvertEntityToModel(dikeAssessmentSectionEntity, () => null); + TestDelegate test = () => converter.ConvertEntityToModel(dikeAssessmentSectionEntity, func); // Assert Assert.Throws(test); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/FailureMechanismEntityConverterTest.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/FailureMechanismEntityConverterTest.cs (.../FailureMechanismEntityConverterTest.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/FailureMechanismEntityConverterTest.cs (.../FailureMechanismEntityConverterTest.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using Application.Ringtoets.Storage.Converters; using Application.Ringtoets.Storage.DbContext; using NUnit.Framework; @@ -33,6 +34,15 @@ [TestFixture] public class FailureMechanismEntityConverterTest { + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + [Test] public void DefaultConstructor_Always_NewFailureMechanismEntityConverter() { @@ -62,14 +72,15 @@ } [Test] - public void ConvertEntityToModel_ValidEntityNullModel_ThrowsArgumentNullException() + [TestCaseSource("TestCases")] + public void ConvertEntityToModel_ValidEntityNullModel_ThrowsArgumentNullException(Func func) { // Setup var entity = new FailureMechanismEntity(); FailureMechanismEntityConverter converter = new FailureMechanismEntityConverter(); // Call - TestDelegate test = () => converter.ConvertEntityToModel(entity, () => null); + TestDelegate test = () => converter.ConvertEntityToModel(entity, func); // Assert var exception = Assert.Throws(test); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -0,0 +1,113 @@ +// 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 Application.Ringtoets.Storage.Converters; +using Application.Ringtoets.Storage.DbContext; +using NUnit.Framework; +using Ringtoets.HydraRing.Data; + +namespace Application.Ringtoets.Storage.Test.Converters +{ + [TestFixture] + public class HydraulicLocationConverterTest + { + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + + [Test] + public void Constructor_Always_NewInstance() + { + // Call + HydraulicLocationConverter converter = new HydraulicLocationConverter(); + + // Assert + Assert.IsInstanceOf>(converter); + } + + [Test] + public void ConvertEntityToModel_NullEntity_ThrowsArgumentNullException() + { + // Setup + HydraulicLocationConverter converter = new HydraulicLocationConverter(); + + // Call + TestDelegate test = () => converter.ConvertEntityToModel(null, () => new HydraulicBoundaryLocation()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + [TestCaseSource("TestCases")] + public void ConvertEntityToModel_NullModel_ThrowsArgumentNullException(Func funcModel) + { + // Setup + HydraulicLocationConverter converter = new HydraulicLocationConverter(); + + // Call + TestDelegate test = () => converter.ConvertEntityToModel(new HydraulicLocationEntity(), funcModel); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("model", exception.ParamName); + } + + [Test] + public void ConvertEntityToModel_ValidEntityValidModel_ReturnsTheEntityAsModel() + { + // Setup + const string name = "test"; + const double designWaterLevel = 15.6; + const long storageId = 1234L; + const decimal locationX = 253; + const decimal locationY = 123; + var entity = new HydraulicLocationEntity() + { + Name = name, + DesignWaterLevel = designWaterLevel, + HydraulicLocationEntityId = storageId, + LocationX = locationX, + LocationY = locationY + }; + HydraulicLocationConverter converter = new HydraulicLocationConverter(); + + // Call + HydraulicBoundaryLocation location = converter.ConvertEntityToModel(entity, () => new HydraulicBoundaryLocation()); + + // Assert + Assert.AreNotEqual(entity, location); + Assert.AreEqual(storageId, location.StorageId); + Assert.AreEqual(name, location.Name); + Assert.AreEqual(designWaterLevel, location.DesignWaterLevel); + Assert.AreEqual(locationX, location.Location.X); + Assert.AreEqual(locationY, location.Location.Y); + } + } +} Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ProjectEntityConverterTest.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Application.Ringtoets.Storage.Converters; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; @@ -9,6 +10,15 @@ [TestFixture] public class ProjectEntityConverterTest { + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + [Test] public void DefaultConstructor_Always_NewProjectEntityConverter() { @@ -33,7 +43,8 @@ } [Test] - public void ConvertEntityToModel_ValidProjectEntityNullModel_ThrowsArgumentNullException() + [TestCaseSource("TestCases")] + public void ConvertEntityToModel_ValidProjectEntityNullModel_ThrowsArgumentNullException(Func func) { // SetUp const long storageId = 1234L; @@ -47,7 +58,7 @@ ProjectEntityConverter converter = new ProjectEntityConverter(); // Call - TestDelegate test = () => converter.ConvertEntityToModel(projectEntity, () => null); + TestDelegate test = () => converter.ConvertEntityToModel(projectEntity, func); // Assert Assert.Throws(test); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/DikeAssessmentSectionEntityPersistorTest.cs =================================================================== diff -u -rbd8a3e95f0145815fa6724a162404a76c9dc9f5a -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/DikeAssessmentSectionEntityPersistorTest.cs (.../DikeAssessmentSectionEntityPersistorTest.cs) (revision bd8a3e95f0145815fa6724a162404a76c9dc9f5a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/DikeAssessmentSectionEntityPersistorTest.cs (.../DikeAssessmentSectionEntityPersistorTest.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -17,6 +17,15 @@ { private MockRepository mockRepository; + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + [SetUp] public void SetUp() { @@ -43,6 +52,7 @@ // Assert Assert.IsInstanceOf(persistor); + Assert.IsInstanceOf>(persistor); mockRepository.VerifyAll(); } @@ -65,7 +75,8 @@ } [Test] - public void LoadModel_ValidEntityNullModel_ThrowsArgumentNullException() + [TestCaseSource("TestCases")] + public void LoadModel_ValidEntityNullModel_ThrowsArgumentNullException(Func func) { // Setup const long storageId = 1234L; @@ -90,7 +101,7 @@ mockRepository.ReplayAll(); // Call - TestDelegate test = () => persistor.LoadModel(entity, () => null); + TestDelegate test = () => persistor.LoadModel(entity, func); // Assert Assert.Throws(test); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -0,0 +1,144 @@ +// 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 Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Persistors; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.HydraRing.Data; + +namespace Application.Ringtoets.Storage.Test.Persistors +{ + [TestFixture] + public class HydraulicLocationEntityPersistorTest + { + private static IEnumerable> TestCases + { + get + { + yield return () => null; + yield return null; + } + } + + [Test] + public void Constructor_NullDataSet_ThrowsAgrumentNullException() + { + // Call + TestDelegate test = () => new HydraulicLocationEntityPersistor(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("ringtoetsContext", exception.ParamName); + } + + [Test] + public void Constructor_EmtpyDataSet_NewInstance() + { + // Setup + var mocks = new MockRepository(); + var ringtoetsEntities = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + HydraulicLocationEntityPersistor persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities); + + // Assert + Assert.IsInstanceOf>(persistor); + mocks.VerifyAll(); + } + + [Test] + public void LoadModel_NullEntity_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var ringtoetsEntities = mocks.StrictMock(); + var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => persistor.LoadModel(null, () => new HydraulicBoundaryLocation()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("entity", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + [TestCaseSource("TestCases")] + public void LoadModel_ValidEntityNullModel_ThrowsArgumentNullException(Func modelFunc) + { + // Setup + var mocks = new MockRepository(); + var ringtoetsEntities = mocks.StrictMock(); + var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => persistor.LoadModel(new HydraulicLocationEntity(), modelFunc); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("model", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void LoadModel_ValidEntityValidModel_EntityAsModel() + { + // Setup + var mocks = new MockRepository(); + var ringtoetsEntities = mocks.StrictMock(); + var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities); + mocks.ReplayAll(); + + const string name = "test"; + const double designWaterLevel = 15.6; + const long storageId = 1234L; + const decimal locationX = 253; + const decimal locationY = 123; + var entity = new HydraulicLocationEntity() + { + Name = name, + DesignWaterLevel = designWaterLevel, + HydraulicLocationEntityId = storageId, + LocationX = locationX, + LocationY = locationY + }; + + // Call + HydraulicBoundaryLocation location = persistor.LoadModel(entity, () => new HydraulicBoundaryLocation()); + + // Assert + Assert.AreEqual(name, location.Name); + Assert.AreEqual(designWaterLevel, location.DesignWaterLevel); + Assert.AreEqual(locationX, location.Location.X); + Assert.AreEqual(locationY, location.Location.Y); + Assert.AreEqual(storageId, location.StorageId); + + mocks.VerifyAll(); + } + } +} Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs =================================================================== diff -u -r92a966a0a5ae5144b90b89be0cdf30c5eea25d7d -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision 92a966a0a5ae5144b90b89be0cdf30c5eea25d7d) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4) @@ -34,6 +34,14 @@ /// /// Creates a new instance of . /// + public HydraulicBoundaryLocation() + { + DesignWaterLevel = Double.NaN; + } + + /// + /// Creates a new instance of . + /// /// Id of the . /// Name of the . /// X coordinate of the . @@ -54,31 +62,31 @@ /// /// Gets the database id of . /// - public long Id { get; private set; } + public long Id { get; set; } /// /// Gets the name of . /// - public string Name { get; private set; } + public string Name { get; set; } /// /// Gets the coordinates of . /// - public Point2D Location { get; private set; } + public Point2D Location { get; set; } /// /// Gets the design water level of . /// public double DesignWaterLevel { get; set; } - public override string ToString() - { - return Name; - } - /// /// Gets or sets the unique identifier for the storage of the class. /// public long StorageId { get; set; } + + public override string ToString() + { + return Name; + } } } \ No newline at end of file