Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ReferenceLineConverter.cs
===================================================================
diff -u -r4670af35a2cb3c8b78d68a25804c3b620da19ddb -r3296448aeb47b8958143a00e05db76cd55627e97
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ReferenceLineConverter.cs (.../ReferenceLineConverter.cs) (revision 4670af35a2cb3c8b78d68a25804c3b620da19ddb)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ReferenceLineConverter.cs (.../ReferenceLineConverter.cs) (revision 3296448aeb47b8958143a00e05db76cd55627e97)
@@ -7,10 +7,25 @@
namespace Application.Ringtoets.Storage.Converters
{
+ ///
+ /// This class is able to convert a model to a
+ /// entity and back.
+ ///
public class ReferenceLineConverter : IEntityConverter>
{
+ ///
+ /// Creates a new from the .
+ ///
+ /// Collection of containing
+ /// the geometry of the .
+ /// A new instance with its geometry taken from the
+ /// .
public ReferenceLine ConvertEntityToModel(ICollection entityCollection)
{
+ if (entityCollection == null)
+ {
+ throw new ArgumentNullException("entityCollection");
+ }
var line = new ReferenceLine();
var geometry = entityCollection.Select(entity => new Point2D(decimal.ToDouble(entity.X), decimal.ToDouble(entity.Y)));
@@ -19,21 +34,30 @@
return line;
}
- public ReferenceLine ConvertEntityToModel(ICollection entity, Func model)
+ ///
+ /// Updates the by adding the geometry from to it.
+ ///
+ /// The used as source.
+ /// The target collection.
+ public void ConvertModelToEntity(ReferenceLine modelObject, ICollection entityCollection)
{
- throw new NotImplementedException();
- }
+ if (modelObject == null)
+ {
+ throw new ArgumentNullException("modelObject");
+ }
+ if (entityCollection == null)
+ {
+ throw new ArgumentNullException("entityCollection");
+ }
- public void ConvertModelToEntity(ReferenceLine modelObject, ICollection entity)
- {
- entity.Clear();
+ entityCollection.Clear();
foreach (Point2D point in modelObject.Points)
{
- entity.Add(new ReferenceLinePointEntity
+ entityCollection.Add(new ReferenceLinePointEntity
{
X = Convert.ToDecimal(point.X),
Y = Convert.ToDecimal(point.Y),
- Order = entity.Count
+ Order = entityCollection.Count
});
}
}
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs
===================================================================
diff -u -r1395d3e2c0a6df5b27da3a44c820ca90eab3492c -r3296448aeb47b8958143a00e05db76cd55627e97
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision 1395d3e2c0a6df5b27da3a44c820ca90eab3492c)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converters/ReferenceLineConverterTest.cs (.../ReferenceLineConverterTest.cs) (revision 3296448aeb47b8958143a00e05db76cd55627e97)
@@ -24,72 +24,74 @@
using System.Linq;
using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
+using Core.Common.Base.Geometry;
using NUnit.Framework;
-using Ringtoets.HydraRing.Data;
+using Ringtoets.Common.Data;
namespace Application.Ringtoets.Storage.Test.Converters
{
[TestFixture]
public class ReferenceLineConverterTest
{
[Test]
+ public void Constructor_Always_NewInstance()
+ {
+ // Call
+ var converter = new ReferenceLineConverter();
+
+ // Assert
+ Assert.IsInstanceOf>>(converter);
+ }
+
+ [Test]
public void ConvertEntityToModel_NullEntity_ThrowsArgumentNullException()
{
// Setup
- HydraulicLocationConverter converter = new HydraulicLocationConverter();
+ var converter = new ReferenceLineConverter();
// Call
- TestDelegate test = () => converter.ConvertEntityToModel(null).ToList();
+ TestDelegate test = () => converter.ConvertEntityToModel(null);
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("entities", exception.ParamName);
+ Assert.AreEqual("entityCollection", exception.ParamName);
}
[Test]
public void ConvertEntityToModel_ValidEntityValidModel_ReturnsTheEntityAsModel()
{
// Setup
- const string name = "test";
- const double designWaterLevel = 15.6;
- const long locationId = 1300001;
- const long storageId = 1234L;
- const decimal locationX = 253;
- const decimal locationY = 123;
- var entity = new HydraulicLocationEntity()
+ var random = new Random(21);
+
+ IList points = new []
{
- LocationId = locationId,
- Name = name,
- DesignWaterLevel = designWaterLevel,
- HydraulicLocationEntityId = storageId,
- LocationX = locationX,
- LocationY = locationY
+ new Point2D(random.NextDouble(), random.NextDouble()),
+ new Point2D(random.NextDouble(), random.NextDouble()),
+ new Point2D(random.NextDouble(), random.NextDouble())
};
- HydraulicLocationConverter converter = new HydraulicLocationConverter();
+ var entityCollection = points.Select(p => new ReferenceLinePointEntity { X = Convert.ToDecimal(p.X), Y = Convert.ToDecimal(p.Y) }).ToList();
+ var converter = new ReferenceLineConverter();
// Call
- List locations = converter.ConvertEntityToModel(new List { entity }).ToList();
+ ReferenceLine location = converter.ConvertEntityToModel(entityCollection);
// Assert
- Assert.AreEqual(1, locations.Count);
- var location = locations[0];
- Assert.AreNotEqual(entity, location);
- Assert.AreEqual(locationId, location.Id);
- 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);
+ Assert.AreNotEqual(points, location.Points);
+ for (var i = 0; i < entityCollection.Count; i++)
+ {
+ Assert.AreEqual(Decimal.ToDouble(entityCollection[i].X), points[i].X, 1e-8);
+ Assert.AreEqual(Decimal.ToDouble(entityCollection[i].Y), points[i].Y, 1e-8);
+ }
}
[Test]
public void ConvertModelToEntity_NullModel_ThrowsArgumentNullException()
{
// Setup
- HydraulicLocationConverter converter = new HydraulicLocationConverter();
+ var converter = new ReferenceLineConverter();
// Call
- TestDelegate test = () => converter.ConvertModelToEntity(null, new HydraulicLocationEntity());
+ TestDelegate test = () => converter.ConvertModelToEntity(null,new List());
// Assert
var exception = Assert.Throws(test);
@@ -100,46 +102,44 @@
public void ConvertModelToEntity_NullEntity_ThrowsArgumentNullException()
{
// Setup
- HydraulicLocationConverter converter = new HydraulicLocationConverter();
+ var converter = new ReferenceLineConverter();
// Call
- TestDelegate test = () => converter.ConvertModelToEntity(new HydraulicBoundaryLocation(1, "test", 1, 1), null);
+ TestDelegate test = () => converter.ConvertModelToEntity(new ReferenceLine(), null);
// Assert
var exception = Assert.Throws(test);
- Assert.AreEqual("entity", exception.ParamName);
+ Assert.AreEqual("entityCollection", exception.ParamName);
}
[Test]
public void ConvertModelToEntity_ValidModelValidEntity_ReturnsModelAsEntity()
{
// Setup
- HydraulicLocationConverter converter = new HydraulicLocationConverter();
-
- var entity = new HydraulicLocationEntity();
- const long storageId = 1234L;
- const long locationId = 130002;
- const string name = "test";
- const double locationX = 39.3;
- const double locationY = 583.2;
- const double designWaterLever = 14.7;
+ var converter = new ReferenceLineConverter();
+ var random = new Random(21);
+ var entity = new List();
- var model = new HydraulicBoundaryLocation(locationId, name, locationX, locationY)
+ IList points = new []
{
- StorageId = storageId,
- DesignWaterLevel = designWaterLever
+ new Point2D(random.NextDouble(), random.NextDouble()),
+ new Point2D(random.NextDouble(), random.NextDouble()),
+ new Point2D(random.NextDouble(), random.NextDouble())
};
+ var model = new ReferenceLine();
+ model.SetGeometry(points);
// Call
converter.ConvertModelToEntity(model, entity);
// Assert
- Assert.AreEqual(model.StorageId, entity.HydraulicLocationEntityId);
- Assert.AreEqual(model.Id, entity.LocationId);
- Assert.AreEqual(model.Name, entity.Name);
- Assert.AreEqual(model.Location.X, entity.LocationX);
- Assert.AreEqual(model.Location.Y, entity.LocationY);
- Assert.AreEqual(model.DesignWaterLevel, entity.DesignWaterLevel);
+ Assert.AreEqual(3, entity.Count);
+
+ for (var i = 0; i < entity.Count; i++)
+ {
+ Assert.AreEqual(points[i].X, Decimal.ToDouble(entity[i].X), 1e-8);
+ Assert.AreEqual(points[i].Y, Decimal.ToDouble(entity[i].Y), 1e-8);
+ }
}
}
}