Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs (.../HydraulicLocationConverter.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/HydraulicLocationConverter.cs (.../HydraulicLocationConverter.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -20,8 +20,8 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using Application.Ringtoets.Storage.DbContext;
-using Core.Common.Base.Geometry;
using Ringtoets.HydraRing.Data;
namespace Application.Ringtoets.Storage.Converters
@@ -30,29 +30,43 @@
/// Converter for to
/// and to .
///
- public class HydraulicLocationConverter : IEntityConverter
+ public class HydraulicLocationConverter // : IEntityConverter
{
- public HydraulicBoundaryLocation ConvertEntityToModel(HydraulicLocationEntity entity)
+ ///
+ /// Converts to an of .
+ ///
+ /// The of to convert.
+ /// An of .
+ /// Thrown when is null.
+ public IEnumerable ConvertEntityToModel(ICollection entities)
{
- if (entity == null)
+ if (entities == null)
{
- throw new ArgumentNullException("entity");
+ throw new ArgumentNullException("entities");
}
-
- HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation();
- hydraulicBoundaryLocation.Id = entity.LocationId;
- hydraulicBoundaryLocation.StorageId = entity.HydraulicLocationEntityId;
- hydraulicBoundaryLocation.Name = entity.Name;
- hydraulicBoundaryLocation.Location = new Point2D(Convert.ToDouble(entity.LocationX), Convert.ToDouble(entity.LocationY));
- if (entity.DesignWaterLevel.HasValue)
+ foreach (var entity in entities)
{
- hydraulicBoundaryLocation.DesignWaterLevel = (double)entity.DesignWaterLevel;
- }
+ HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(entity.LocationId, entity.Name, Convert.ToDouble(entity.LocationX), Convert.ToDouble(entity.LocationY))
+ {
+ StorageId = entity.HydraulicLocationEntityId,
+ };
- return hydraulicBoundaryLocation;
+ if (entity.DesignWaterLevel.HasValue)
+ {
+ hydraulicBoundaryLocation.DesignWaterLevel = (double)entity.DesignWaterLevel;
+ }
+
+ yield return hydraulicBoundaryLocation;
+ }
}
+ ///
+ /// Converts to .
+ ///
+ /// The to convert.
+ /// A reference to the to be saved.
+ /// Thrown when or is null.
public void ConvertModelToEntity(HydraulicBoundaryLocation modelObject, HydraulicLocationEntity entity)
{
if (modelObject == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs (.../DikeAssessmentSectionEntityPersistor.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/DikeAssessmentSectionEntityPersistor.cs (.../DikeAssessmentSectionEntityPersistor.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -74,9 +74,9 @@
{
var dikeAssessmentSection = converter.ConvertEntityToModel(entity);
- foreach (var hydraulicLocationEntity in entity.HydraulicLocationEntities)
+ if (dikeAssessmentSection.HydraulicBoundaryDatabase != null)
{
- dikeAssessmentSection.HydraulicBoundaryDatabase.Locations.Add(hydraulicLocationEntityPersistor.LoadModel(hydraulicLocationEntity));
+ dikeAssessmentSection.HydraulicBoundaryDatabase.Locations.AddRange(hydraulicLocationEntityPersistor.LoadModel(entity.HydraulicLocationEntities));
}
foreach (var failureMechanismEntity in entity.FailureMechanismEntities)
@@ -202,15 +202,9 @@
private void InsertChildren(DikeAssessmentSection model, DikeAssessmentSectionEntity entity)
{
dikePipingFailureMechanismEntityPersistor.InsertModel(entity.FailureMechanismEntities, model.PipingFailureMechanism);
+ hydraulicLocationEntityPersistor.InsertModel(entity.HydraulicLocationEntities, model.HydraulicBoundaryDatabase);
+
dikePipingFailureMechanismEntityPersistor.RemoveUnModifiedEntries(entity.FailureMechanismEntities);
-
- if (model.HydraulicBoundaryDatabase != null)
- {
- foreach (var hydraulicBoundaryLocation in model.HydraulicBoundaryDatabase.Locations)
- {
- hydraulicLocationEntityPersistor.InsertModel(entity.HydraulicLocationEntities, hydraulicBoundaryLocation, 0);
- }
- }
hydraulicLocationEntityPersistor.RemoveUnModifiedEntries(entity.HydraulicLocationEntities);
}
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs (.../HydraulicLocationEntityPersistor.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/HydraulicLocationEntityPersistor.cs (.../HydraulicLocationEntityPersistor.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Data.Entity;
using System.Linq;
using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
@@ -58,68 +59,124 @@
converter = new HydraulicLocationConverter();
}
- public void UpdateModel(ICollection parentNavigationProperty, HydraulicBoundaryLocation model, int order)
+ ///
+ /// Loads the as .
+ ///
+ /// The to load.
+ /// A new instance of , based on the properties of .
+ /// Thrown when is null.
+ public IEnumerable LoadModel(ICollection entities)
{
- if (model == null)
+ if (entities == null)
{
- throw new ArgumentNullException("model");
+ throw new ArgumentNullException("entities");
}
- if (model.StorageId < 1)
+ return converter.ConvertEntityToModel(entities);
+ }
+
+ ///
+ /// Ensures that the is set as in the .
+ /// All other in will be removed.
+ ///
+ /// Collection where objects can be searched and added.
+ /// Usually, this collection is a navigation property of a .
+ /// The to be saved in the storage.
+ public void UpdateModel(ICollection parentNavigationProperty, HydraulicBoundaryDatabase model)
+ {
+ if (model == null)
{
- InsertModel(parentNavigationProperty, model, 0);
- return;
+ throw new ArgumentNullException("model");
}
if (parentNavigationProperty == null)
{
throw new ArgumentNullException("parentNavigationProperty");
}
- HydraulicLocationEntity entity;
- try
+ foreach (var location in model.Locations)
{
- entity = parentNavigationProperty.SingleOrDefault(db => db.HydraulicLocationEntityId == model.StorageId);
+ if (location == null)
+ {
+ throw new ArgumentException("Null location cannot be added");
+ }
+
+ if (location.StorageId < 1)
+ {
+ InsertLocation(parentNavigationProperty, location);
+ continue;
+ }
+
+ HydraulicLocationEntity entity;
+ try
+ {
+ entity = parentNavigationProperty.SingleOrDefault(db => db.HydraulicLocationEntityId == location.StorageId);
+ }
+ catch (InvalidOperationException exception)
+ {
+ throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "HydraulicLocationEntity", location.StorageId), exception);
+ }
+
+ if (entity == null)
+ {
+ throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "HydraulicLocationEntity", location.StorageId));
+ }
+
+ modifiedList.Add(entity);
+
+ converter.ConvertModelToEntity(location, entity);
}
- catch (InvalidOperationException exception)
- {
- throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "HydraulicLocationEntity", model.StorageId), exception);
- }
+ }
- if (entity == null)
+ private void InsertLocation(ICollection parentNavigationProperty, HydraulicBoundaryLocation location)
+ {
+ if (location == null)
{
- throw new EntityNotFoundException(String.Format(Resources.Error_Entity_Not_Found_0_1, "HydraulicLocationEntity", model.StorageId));
+ throw new ArgumentNullException("location");
}
- modifiedList.Add(entity);
+ var entity = new HydraulicLocationEntity();
+ parentNavigationProperty.Add(entity);
+ insertedList.Add(entity, location);
- converter.ConvertModelToEntity(model, entity);
+ converter.ConvertModelToEntity(location, entity);
+
+ if (location.StorageId > 0)
+ {
+ modifiedList.Add(entity);
+ }
}
- public void InsertModel(ICollection parentNavigationProperty, HydraulicBoundaryLocation model, int order)
+ ///
+ /// Ensures that the is added as in the .
+ /// All other in will be removed.
+ ///
+ /// Collection where objects can be added.
+ /// Usually, this collection is a navigation property of a .
+ /// The to be saved in the storage.
+ public void InsertModel(ICollection parentNavigationProperty, HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
{
if (parentNavigationProperty == null)
{
throw new ArgumentNullException("parentNavigationProperty");
}
- if (model == null)
+ if (hydraulicBoundaryDatabase == null)
{
- throw new ArgumentNullException("model");
+ return;
}
- var entity = new HydraulicLocationEntity();
- parentNavigationProperty.Add(entity);
- insertedList.Add(entity, model);
-
- converter.ConvertModelToEntity(model, entity);
-
- if (model.StorageId > 0)
+ foreach (var location in hydraulicBoundaryDatabase.Locations)
{
- modifiedList.Add(entity);
+ InsertLocation(parentNavigationProperty, location);
}
}
+ ///
+ /// Removes all entities from that are not marked as 'updated'.
+ ///
+ /// List where objects can be searched.
+ /// Usually, this collection is a navigation property of a .
public void RemoveUnModifiedEntries(ICollection parentNavigationProperty)
{
var originalList = parentNavigationProperty.ToList();
@@ -140,6 +197,9 @@
modifiedList.Clear();
}
+ ///
+ /// Perform actions that can only be executed after has been called.
+ ///
public void PerformPostSaveActions()
{
foreach (var entry in insertedList)
@@ -148,15 +208,5 @@
}
insertedList.Clear();
}
-
- public HydraulicBoundaryLocation LoadModel(HydraulicLocationEntity entity)
- {
- if (entity == null)
- {
- throw new ArgumentNullException("entity");
- }
-
- return converter.ConvertEntityToModel(entity);
- }
}
}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs (.../HydraulicLocationConverterTest.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/HydraulicLocationConverterTest.cs (.../HydraulicLocationConverterTest.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -20,6 +20,9 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
using NUnit.Framework;
@@ -31,27 +34,17 @@
public class HydraulicLocationConverterTest
{
[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);
+ TestDelegate test = () => converter.ConvertEntityToModel(null).ToList();
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("entity", exception.ParamName);
+ Assert.AreEqual("entities", exception.ParamName);
}
[Test]
@@ -76,9 +69,11 @@
HydraulicLocationConverter converter = new HydraulicLocationConverter();
// Call
- HydraulicBoundaryLocation location = converter.ConvertEntityToModel(entity);
+ List locations = converter.ConvertEntityToModel(new List {entity}).ToList();
// Assert
+ Assert.AreEqual(1, locations.Count);
+ var location = locations[0];
Assert.AreNotEqual(entity, location);
Assert.AreEqual(locationId, location.Id);
Assert.AreEqual(storageId, location.StorageId);
@@ -109,7 +104,7 @@
HydraulicLocationConverter converter = new HydraulicLocationConverter();
// Call
- TestDelegate test = () => converter.ConvertModelToEntity(new HydraulicBoundaryLocation(), null);
+ TestDelegate test = () => converter.ConvertModelToEntity(new HydraulicBoundaryLocation(1, "test", 1, 1), null);
// Assert
var exception = Assert.Throws(test);
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
using NUnit.Framework;
@@ -32,27 +33,17 @@
public class ReferenceLineConverterTest
{
[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);
+ TestDelegate test = () => converter.ConvertEntityToModel(null).ToList();
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("entity", exception.ParamName);
+ Assert.AreEqual("entities", exception.ParamName);
}
[Test]
@@ -77,9 +68,11 @@
HydraulicLocationConverter converter = new HydraulicLocationConverter();
// Call
- HydraulicBoundaryLocation location = converter.ConvertEntityToModel(entity);
+ List locations = converter.ConvertEntityToModel(new List { entity }).ToList();
// Assert
+ Assert.AreEqual(1, locations.Count);
+ var location = locations[0];
Assert.AreNotEqual(entity, location);
Assert.AreEqual(locationId, location.Id);
Assert.AreEqual(storageId, location.StorageId);
@@ -110,7 +103,7 @@
HydraulicLocationConverter converter = new HydraulicLocationConverter();
// Call
- TestDelegate test = () => converter.ConvertModelToEntity(new HydraulicBoundaryLocation(), null);
+ TestDelegate test = () => converter.ConvertModelToEntity(new HydraulicBoundaryLocation(1, "test", 1, 1), null);
// Assert
var exception = Assert.Throws(test);
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs
===================================================================
diff -u -rd242e89e13ef602facae6a1ef91660242bcef340 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs (.../HydraulicLocationEntityPersistorTest.cs) (revision d242e89e13ef602facae6a1ef91660242bcef340)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/HydraulicLocationEntityPersistorTest.cs (.../HydraulicLocationEntityPersistorTest.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -36,15 +36,6 @@
[TestFixture]
public class HydraulicLocationEntityPersistorTest
{
- private static IEnumerable> TestCases
- {
- get
- {
- yield return () => null;
- yield return null;
- }
- }
-
[Test]
public void Constructor_NullDataSet_ThrowsAgrumentNullException()
{
@@ -87,7 +78,7 @@
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("entity", exception.ParamName);
+ Assert.AreEqual("entities", exception.ParamName);
mocks.VerifyAll();
}
@@ -117,9 +108,11 @@
};
// Call
- HydraulicBoundaryLocation location = persistor.LoadModel(entity);
+ List locations = persistor.LoadModel(new List{entity}).ToList();
// Assert
+ Assert.AreEqual(1, locations.Count);
+ var location = locations[0];
Assert.AreEqual(locationId, location.Id);
Assert.AreEqual(name, location.Name);
Assert.AreEqual(designWaterLevel, location.DesignWaterLevel);
@@ -137,10 +130,12 @@
var mocks = new MockRepository();
var ringtoetsEntities = mocks.StrictMock();
var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1, 1));
mocks.ReplayAll();
// Call
- TestDelegate test = () => persistor.InsertModel(null, new HydraulicBoundaryLocation(), 0);
+ TestDelegate test = () => persistor.InsertModel(null, hydraulicBoundaryDatabase);
// Assert
var exception = Assert.Throws(test);
@@ -150,48 +145,26 @@
}
[Test]
- public void InsertModel_NullModel_ThrowsArgumentNullException()
+ public void InsertModel_NullModel_DoesNotAddEntityInParentNavigationProperty()
{
// Setup
var mocks = new MockRepository();
var ringtoetsEntities = mocks.StrictMock();
var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
+ var parentNavigationProperty = new List();
mocks.ReplayAll();
// Call
- TestDelegate test = () => persistor.InsertModel(new List(), null, 0);
+ TestDelegate test = () => persistor.InsertModel(parentNavigationProperty, null);
// Assert
- var exception = Assert.Throws(test);
- Assert.AreEqual("model", exception.ParamName);
+ Assert.DoesNotThrow(test);
+ CollectionAssert.AreEquivalent(new List(), parentNavigationProperty);
mocks.VerifyAll();
}
[Test]
- public void InsertModel_EmptyDatasetValidModel_ValidEntityInDataModel()
- {
- // Setup
- var mocks = new MockRepository();
- var ringtoetsEntities = mocks.StrictMock();
- var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
- IList parentNavigationProperty = new List();
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation();
- mocks.ReplayAll();
-
- // Call
- persistor.InsertModel(parentNavigationProperty, model, 0);
-
- // Assert
- Assert.AreEqual(1, parentNavigationProperty.Count);
- var entity = parentNavigationProperty[0];
- Assert.AreNotEqual(model, entity);
- Assert.IsNaN(entity.DesignWaterLevel);
-
- mocks.VerifyAll();
- }
-
- [Test]
public void InsertModel_SingleEntityInParentNavigationPropertyHydraulicLocationWithSameStorageId_HydraulicLocationAsEntityInParentNavigationProperty()
{
// Setup
@@ -210,15 +183,18 @@
entityToDelete
};
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
mocks.ReplayAll();
// Call
- persistor.InsertModel(parentNavigationProperty, model, 0);
+ persistor.InsertModel(parentNavigationProperty, hydraulicBoundaryDatabase);
// Assert
Assert.AreEqual(2, parentNavigationProperty.Count);
@@ -230,6 +206,28 @@
}
[Test]
+ public void InsertModel_LocationNull_ThrowsArgumentNullException()
+ {
+ var mocks = new MockRepository();
+ var ringtoetsEntities = mocks.StrictMock();
+ var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
+ IList parentNavigationProperty = new List();
+
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(null);
+
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate test = () => persistor.InsertModel(parentNavigationProperty, hydraulicBoundaryDatabase);
+
+ // Assert
+ Assert.Throws(test);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
public void UpdateModel_NullDatasetValidModel_ThrowsArgumentNullException()
{
// Setup
@@ -239,13 +237,16 @@
var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
mocks.ReplayAll();
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
// Call
- TestDelegate test = () => persistor.UpdateModel(null, model, 0);
+ TestDelegate test = () => persistor.UpdateModel(null, hydraulicBoundaryDatabase);
// Assert
var exception = Assert.Throws(test);
@@ -265,7 +266,7 @@
mocks.ReplayAll();
// Call
- TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, null, 0);
+ TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, null);
// Assert
var exception = Assert.Throws(test);
@@ -284,15 +285,18 @@
var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
IList parentNavigationProperty = new List();
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
mocks.ReplayAll();
// Call
- TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, model, 0);
+ TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
// Assert
var exception = Assert.Throws(test);
@@ -321,15 +325,18 @@
}
};
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
mocks.ReplayAll();
// Call
- TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, model, 0);
+ TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
// Assert
var exception = Assert.Throws(test);
@@ -354,15 +361,18 @@
}
};
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
mocks.ReplayAll();
// Call
- persistor.UpdateModel(parentNavigationProperty, model, 0);
+ persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
// Assert
Assert.AreEqual(1, parentNavigationProperty.Count);
@@ -380,15 +390,18 @@
var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
IList parentNavigationProperty = new List();
- HydraulicBoundaryLocation model = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation model = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = 0
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(model);
+
mocks.ReplayAll();
// Call
- persistor.UpdateModel(parentNavigationProperty, model, 0);
+ persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
// Assert
Assert.AreEqual(1, parentNavigationProperty.Count);
@@ -397,6 +410,28 @@
}
[Test]
+ public void UpdateModel_LocationNull_ThrowsArgumentException()
+ {
+ var mocks = new MockRepository();
+ var ringtoetsEntities = mocks.StrictMock();
+ var persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
+ IList parentNavigationProperty = new List();
+
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(null);
+
+ mocks.ReplayAll();
+
+ // Call
+ TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
+
+ // Assert
+ Assert.Throws(test);
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
public void RemoveUnModifiedEntries_SingleEntityInParentNavigationPropertySingleHydraulicLocationWithoutStorageId_UpdatedHydraulicLocationAsEntityInParentNavigationPropertyAndOthersDeletedInDbSet()
{
// Setup
@@ -420,11 +455,13 @@
ringtoetsEntities.Expect(x => x.HydraulicLocationEntities).Return(dbset);
HydraulicLocationEntityPersistor persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
- HydraulicBoundaryLocation location = new HydraulicBoundaryLocation();
+ HydraulicBoundaryLocation location = new HydraulicBoundaryLocation(13001, "test", 13, 52);
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(location);
mocks.ReplayAll();
// Call
- persistor.UpdateModel(parentNavigationProperty, location, 0);
+ persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
persistor.RemoveUnModifiedEntries(parentNavigationProperty);
// Assert
@@ -463,13 +500,16 @@
ringtoetsEntities.Expect(x => x.HydraulicLocationEntities).Return(dbset);
HydraulicLocationEntityPersistor persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
- HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation
+ HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = storageId
};
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation);
+
mocks.ReplayAll();
- TestDelegate updateTest = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryLocation, 0);
+ TestDelegate updateTest = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
Assert.DoesNotThrow(updateTest, "Precondition failed: Update should not throw exception.");
// Call
@@ -510,10 +550,12 @@
ringtoetsEntities.Expect(x => x.HydraulicLocationEntities).Return(dbset).Repeat.Twice();
HydraulicLocationEntityPersistor persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
- HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation();
+ HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation(13001, "test", 13, 52);
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation);
mocks.ReplayAll();
- TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryLocation, 0);
+ TestDelegate test = () => persistor.UpdateModel(parentNavigationProperty, hydraulicBoundaryDatabase);
Assert.DoesNotThrow(test, "Precondition failed: UpdateModel");
// Call
@@ -561,27 +603,27 @@
IList hydraulicLocations = new List();
for (var i = 0; i < numberOfInserts; i++)
{
- hydraulicLocations.Add(new HydraulicBoundaryLocation
+ hydraulicLocations.Add(new HydraulicBoundaryLocation(13001, "test", 13, 52)
{
StorageId = 0L
});
}
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase();
+ hydraulicBoundaryDatabase.Locations.AddRange(hydraulicLocations);
+
var ringtoetsEntities = mocks.StrictMock();
HydraulicLocationEntityPersistor persistor = new HydraulicLocationEntityPersistor(ringtoetsEntities);
mocks.ReplayAll();
- foreach (var hydraulicLocation in hydraulicLocations)
+ try
{
- try
- {
- persistor.UpdateModel(parentNavigationPropertyMock, hydraulicLocation, 0);
- }
- catch (Exception)
- {
- Assert.Fail("Precondition failed: persistor.UpdateModel");
- }
+ persistor.UpdateModel(parentNavigationPropertyMock, hydraulicBoundaryDatabase);
}
+ catch (Exception)
+ {
+ Assert.Fail("Precondition failed: persistor.UpdateModel");
+ }
// Call
for (var i = 0; i < insertedHydraulicLocationEntities.Count; i++)
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj
===================================================================
diff -u -rfadb006ef0285eb3fdbdbfc805729b37c8dbc0e6 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision fadb006ef0285eb3fdbdbfc805729b37c8dbc0e6)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/Application.Ringtoets.Storage.TestUtil.csproj (.../Application.Ringtoets.Storage.TestUtil.csproj) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -73,6 +73,10 @@
{d4200f43-3f72-4f42-af0a-8ced416a38ec}
Ringtoets.Common.Data
+
+ {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2}
+ Ringtoets.HydraRing.Data
+
{11F1F874-45AF-43E4-8AE5-15A5C9593E28}
Ringtoets.Integration.Data
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs
===================================================================
diff -u -r2ae1c9433c3c28b32105b9778b682b5e512a0f00 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision 2ae1c9433c3c28b32105b9778b682b5e512a0f00)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectHelper.cs (.../RingtoetsProjectHelper.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -19,7 +19,9 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System.Collections.Generic;
using Core.Common.Base.Data;
+using Ringtoets.HydraRing.Data;
using Ringtoets.Integration.Data;
namespace Application.Ringtoets.Storage.TestUtil
@@ -43,10 +45,23 @@
{
new DikeAssessmentSection
{
- Name = "dikeAssessmentSection"
+ Name = "dikeAssessmentSection",
+ HydraulicBoundaryDatabase = GetHydraulicBoundaryDatabase()
}
}
};
}
+
+ private static HydraulicBoundaryDatabase GetHydraulicBoundaryDatabase()
+ {
+ var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
+ {
+ FilePath = "/temp/test",
+ Version = "1.0"
+ };
+ hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(13001, "test", 152.3, 2938.5));
+
+ return hydraulicBoundaryDatabase;
+ }
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs
===================================================================
diff -u -r20cf7c61dec992770e5e59193f1922c960341495 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs (.../HydraulicBoundaryDatabase.cs) (revision 20cf7c61dec992770e5e59193f1922c960341495)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryDatabase.cs (.../HydraulicBoundaryDatabase.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -51,7 +51,7 @@
///
/// Gets the hydraulic boundary locations.
///
- public ICollection Locations { get; private set; }
+ public List Locations { get; private set; }
///
/// Clears all the locations from the .
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs
===================================================================
diff -u -raf521f167fabb7052a06e6a3d12575d3c3f18ab4 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision af521f167fabb7052a06e6a3d12575d3c3f18ab4)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -34,14 +34,6 @@
///
/// 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 .
@@ -62,17 +54,17 @@
///
/// Gets the database id of .
///
- public long Id { get; set; }
+ public long Id { get; private set; }
///
/// Gets the name of .
///
- public string Name { get; set; }
+ public string Name { get; private set; }
///
/// Gets the coordinates of .
///
- public Point2D Location { get; set; }
+ public Point2D Location { get; private set; }
///
/// Gets the design water level of .
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs
===================================================================
diff -u -r5efe386d38b0b0686283bae9952a47e29aa6b7b1 -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs (.../HydraulicBoundaryLocationTest.cs) (revision 5efe386d38b0b0686283bae9952a47e29aa6b7b1)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs (.../HydraulicBoundaryLocationTest.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
@@ -44,21 +44,6 @@
}
[Test]
- public void Constructor_WithoutParameters_PropertiesAsExpected()
- {
- // Call
- HydraulicBoundaryLocation hydraulicBoundaryLocation = new HydraulicBoundaryLocation();
-
- // Assert
- Assert.IsInstanceOf(hydraulicBoundaryLocation);
- Assert.IsInstanceOf(hydraulicBoundaryLocation);
- Assert.AreEqual(0, hydraulicBoundaryLocation.Id);
- Assert.IsNull(hydraulicBoundaryLocation.Name);
- Assert.IsNull(hydraulicBoundaryLocation.Location);
- Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel);
- }
-
- [Test]
public void Constructor_ValidParameters_PropertiesAsExpected()
{
// Setup