Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs =================================================================== diff -u -r95173b2bf8347650672885f9422e8864d1f8c857 -rd7264e2c19e7531625a5b408d5f9d7c15229a904 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 95173b2bf8347650672885f9422e8864d1f8c857) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision d7264e2c19e7531625a5b408d5f9d7c15229a904) @@ -26,12 +26,13 @@ using Application.Ringtoets.Storage.Serializers; using Core.Common.Base.Geometry; using Core.Common.Utils.Extensions; +using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Read { /// - /// This class defines extension methods for read operations for an + /// This class defines extension methods for read operations for a surface line /// based on the . /// internal static class SurfaceLineEntityReadExtensions @@ -47,7 +48,8 @@ /// Thrown when any input parameter is null. /// Thrown when /// of is null or empty. - public static PipingSurfaceLine ReadAsPipingSurfaceLine(this SurfaceLineEntity entity, ReadConversionCollector collector) + public static PipingSurfaceLine ReadAsPipingSurfaceLine(this SurfaceLineEntity entity, + ReadConversionCollector collector) { if (entity == null) { @@ -65,9 +67,7 @@ var surfaceLine = new PipingSurfaceLine(entity.Name) { - ReferenceLineIntersectionWorldPoint = new Point2D( - entity.ReferenceLineIntersectionX.ToNullAsNaN(), - entity.ReferenceLineIntersectionY.ToNullAsNaN()) + ReferenceLineIntersectionWorldPoint = GetReferenceLineIntersectionWorldPoint(entity) }; surfaceLine.SetGeometry(ReadGeometryPoints(entity)); @@ -78,6 +78,54 @@ return surfaceLine; } + /// + /// Read the and use the information to construct + /// a . + /// + /// The to create + /// for. + /// The object keeping track of read operations. + /// A new . + /// Thrown when any input parameter is null. + /// Thrown when + /// of is null or empty. + public static MacroStabilityInwardsSurfaceLine ReadAsMacroStabilityInwardsSurfaceLine( + this SurfaceLineEntity entity, + ReadConversionCollector collector) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + if (collector == null) + { + throw new ArgumentNullException(nameof(collector)); + } + + if (collector.ContainsMacroStabilityInwardsSurfaceLine(entity)) + { + return collector.GetMacroStabilityInwardsSurfaceLine(entity); + } + + var surfaceLine = new MacroStabilityInwardsSurfaceLine(entity.Name) + { + ReferenceLineIntersectionWorldPoint = GetReferenceLineIntersectionWorldPoint(entity) + }; + + surfaceLine.SetGeometry(ReadGeometryPoints(entity)); + entity.ReadCharacteristicPoints(surfaceLine); + + collector.Read(entity, surfaceLine); + + return surfaceLine; + } + + private static Point2D GetReferenceLineIntersectionWorldPoint(SurfaceLineEntity entity) + { + return new Point2D(entity.ReferenceLineIntersectionX.ToNullAsNaN(), + entity.ReferenceLineIntersectionY.ToNullAsNaN()); + } + private static void ReadCharacteristicPoints(this SurfaceLineEntity entity, PipingSurfaceLine surfaceLine) { var characteristicPoints = new Dictionary(); @@ -91,9 +139,17 @@ characteristicPoints.ForEachElementDo(cp => SetCharacteristicPoint(surfaceLine, cp.Key, cp.Value)); } - private static IEnumerable ReadGeometryPoints(SurfaceLineEntity entity) + private static void ReadCharacteristicPoints(this SurfaceLineEntity entity, MacroStabilityInwardsSurfaceLine surfaceLine) { - return new Point3DXmlSerializer().FromXml(entity.PointsXml); + var characteristicPoints = new Dictionary(); + foreach (MacroStabilityInwardsCharacteristicPointEntity pointEntity in entity.MacroStabilityInwardsCharacteristicPointEntities) + { + characteristicPoints[(MacroStabilityInwardsCharacteristicPointType) pointEntity.Type] = new Point3D(pointEntity.X.ToNullAsNaN(), + pointEntity.Y.ToNullAsNaN(), + pointEntity.Z.ToNullAsNaN()); + } + + characteristicPoints.ForEachElementDo(cp => SetCharacteristicPoint(surfaceLine, cp.Key, cp.Value)); } private static void SetCharacteristicPoint(PipingSurfaceLine surfaceLine, @@ -126,5 +182,65 @@ typeof(PipingCharacteristicPointType)); } } + + private static void SetCharacteristicPoint(MacroStabilityInwardsSurfaceLine surfaceLine, + MacroStabilityInwardsCharacteristicPointType type, + Point3D geometryPoint) + { + switch (type) + { + case MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside: + surfaceLine.SetSurfaceLevelOutsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside: + surfaceLine.SetSurfaceLevelInsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.TrafficLoadOutside: + surfaceLine.SetTrafficLoadOutsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.TrafficLoadInside: + surfaceLine.SetTrafficLoadInsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside: + surfaceLine.SetShoulderBaseInsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside: + surfaceLine.SetShoulderTopInsideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver: + surfaceLine.SetDikeToeAtRiverAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder: + surfaceLine.SetDikeToeAtPolderAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide: + surfaceLine.SetBottomDitchDikeSideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide: + surfaceLine.SetBottomDitchPolderSideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DitchDikeSide: + surfaceLine.SetDitchDikeSideAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver: + surfaceLine.SetDikeTopAtRiverAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder: + surfaceLine.SetDikeTopAtPolderAt(geometryPoint); + break; + case MacroStabilityInwardsCharacteristicPointType.DitchPolderSide: + surfaceLine.SetDitchPolderSideAt(geometryPoint); + break; + default: + throw new InvalidEnumArgumentException(nameof(type), + (int) type, + typeof(MacroStabilityInwardsCharacteristicPointType)); + } + } + + private static IEnumerable ReadGeometryPoints(SurfaceLineEntity entity) + { + return new Point3DXmlSerializer().FromXml(entity.PointsXml); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs =================================================================== diff -u -r95173b2bf8347650672885f9422e8864d1f8c857 -rd7264e2c19e7531625a5b408d5f9d7c15229a904 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 95173b2bf8347650672885f9422e8864d1f8c857) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision d7264e2c19e7531625a5b408d5f9d7c15229a904) @@ -26,6 +26,7 @@ using Application.Ringtoets.Storage.Serializers; using Core.Common.Base.Geometry; using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Test.Read @@ -85,26 +86,23 @@ { // Setup var collector = new ReadConversionCollector(); + var random = new Random(31); - const string name = "nice name!"; - const double intersectionX = 1.1; - const double intersectionY = 2.2; - var entity = new SurfaceLineEntity { - Name = name, - ReferenceLineIntersectionX = intersectionX, - ReferenceLineIntersectionY = intersectionY, + Name = "nice name!", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), PointsXml = new Point3DXmlSerializer().ToXml(new Point3D[0]) }; // Call PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); // Assert - Assert.AreEqual(name, surfaceLine.Name); - Assert.AreEqual(intersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); - Assert.AreEqual(intersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); CollectionAssert.IsEmpty(surfaceLine.Points); @@ -179,14 +177,17 @@ Name = "Better name.", ReferenceLineIntersectionX = random.NextDouble(), ReferenceLineIntersectionY = random.NextDouble(), - PointsXml = new Point3DXmlSerializer().ToXml(points) + PointsXml = new Point3DXmlSerializer().ToXml(points), + PipingCharacteristicPointEntities = + { + CreatePipingCharacteristicPointEntity(points[1], PipingCharacteristicPointType.BottomDitchDikeSide), + CreatePipingCharacteristicPointEntity(points[2], PipingCharacteristicPointType.BottomDitchPolderSide), + CreatePipingCharacteristicPointEntity(points[3], PipingCharacteristicPointType.DikeToeAtPolder), + CreatePipingCharacteristicPointEntity(points[4], PipingCharacteristicPointType.DikeToeAtRiver), + CreatePipingCharacteristicPointEntity(points[5], PipingCharacteristicPointType.DitchDikeSide), + CreatePipingCharacteristicPointEntity(points[6], PipingCharacteristicPointType.DitchPolderSide) + } }; - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[1], PipingCharacteristicPointType.BottomDitchDikeSide)); - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[2], PipingCharacteristicPointType.BottomDitchPolderSide)); - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[3], PipingCharacteristicPointType.DikeToeAtPolder)); - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[4], PipingCharacteristicPointType.DikeToeAtRiver)); - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[5], PipingCharacteristicPointType.DitchDikeSide)); - entity.PipingCharacteristicPointEntities.Add(CreatePipingCharacteristicPointEntity(points[6], PipingCharacteristicPointType.DitchPolderSide)); // Call PipingSurfaceLine surfaceLine = entity.ReadAsPipingSurfaceLine(collector); @@ -325,6 +326,353 @@ Assert.AreSame(surfaceLine1, surfaceLine2); } + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_CollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new SurfaceLineEntity(); + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("collector", exception.ParamName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_EntityNull_ThrowArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate call = () => ((SurfaceLineEntity) null).ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void ReadAsMacroStabilityInwardsSurfaceLine_PointsXmlNullOrEmpty_ThrowsArgumentException(string xml) + { + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = xml + }; + + // Call + TestDelegate call = () => entity.ReadAsMacroStabilityInwardsSurfaceLine(new ReadConversionCollector()); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("xml", paramName); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithoutGeometryPointEntities_ReturnSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var entity = new SurfaceLineEntity + { + Name = "nice name!", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.IsEmpty(surfaceLine.Points); + + Assert.IsNull(surfaceLine.SurfaceLevelOutside); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.TrafficLoadOutside); + Assert.IsNull(surfaceLine.TrafficLoadInside); + Assert.IsNull(surfaceLine.DikeTopAtPolder); + Assert.IsNull(surfaceLine.DikeTopAtRiver); + Assert.IsNull(surfaceLine.ShoulderBaseInside); + Assert.IsNull(surfaceLine.ShoulderTopInside); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + Assert.IsNull(surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithGeometryPointEntitiesButNoCharacteristicPoints_ReturnSurfaceLineWithGeometry() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var points = new[] + { + CreatePoint3D(random), + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = nameof(SurfaceLineEntity), + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DXmlSerializer().ToXml(points) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.IsNull(surfaceLine.SurfaceLevelOutside); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.TrafficLoadOutside); + Assert.IsNull(surfaceLine.TrafficLoadInside); + Assert.IsNull(surfaceLine.DikeTopAtPolder); + Assert.IsNull(surfaceLine.DikeTopAtRiver); + Assert.IsNull(surfaceLine.ShoulderBaseInside); + Assert.IsNull(surfaceLine.ShoulderTopInside); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DitchPolderSide); + Assert.IsNull(surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityWithGeometryPointEntitiesAndCharacteristicPoints_ReturnFullSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + Point3D[] points = Array.ConvertAll(new Point3D[14], p => CreatePoint3D(random)); + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[1], MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[2], MacroStabilityInwardsCharacteristicPointType.TrafficLoadOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[3], MacroStabilityInwardsCharacteristicPointType.TrafficLoadInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[4], MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[5], MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[6], MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[7], MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[8], MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[9], MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[10], MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[11], MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[12], MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[13], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + CollectionAssert.AreEqual(points, surfaceLine.Points); + + Assert.AreSame(surfaceLine.Points[0], surfaceLine.SurfaceLevelOutside); + Assert.AreSame(surfaceLine.Points[1], surfaceLine.DikeToeAtRiver); + Assert.AreSame(surfaceLine.Points[2], surfaceLine.TrafficLoadOutside); + Assert.AreSame(surfaceLine.Points[3], surfaceLine.TrafficLoadInside); + Assert.AreSame(surfaceLine.Points[4], surfaceLine.DikeTopAtPolder); + Assert.AreSame(surfaceLine.Points[5], surfaceLine.DikeTopAtRiver); + Assert.AreSame(surfaceLine.Points[6], surfaceLine.ShoulderBaseInside); + Assert.AreSame(surfaceLine.Points[7], surfaceLine.ShoulderTopInside); + Assert.AreSame(surfaceLine.Points[8], surfaceLine.DikeToeAtPolder); + Assert.AreSame(surfaceLine.Points[9], surfaceLine.DitchDikeSide); + Assert.AreSame(surfaceLine.Points[10], surfaceLine.BottomDitchDikeSide); + Assert.AreSame(surfaceLine.Points[11], surfaceLine.BottomDitchPolderSide); + Assert.AreSame(surfaceLine.Points[12], surfaceLine.DitchPolderSide); + Assert.AreSame(surfaceLine.Points[13], surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_FullSurfaceLineEntity_ReturnFullSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var points = new[] + { + CreatePoint3D(random), + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = "Better name.", + ReferenceLineIntersectionX = random.NextDouble(), + ReferenceLineIntersectionY = random.NextDouble(), + PointsXml = new Point3DXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.TrafficLoadOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.TrafficLoadInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.AreEqual(entity.ReferenceLineIntersectionX, surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.AreEqual(entity.ReferenceLineIntersectionY, surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D[] geometry = surfaceLine.Points.ToArray(); + Assert.AreEqual(2, geometry.Length); + Point3D geometryPoint = geometry[0]; + + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelOutside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.TrafficLoadOutside); + Assert.AreSame(geometryPoint, surfaceLine.TrafficLoadInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderBaseInside); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderTopInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_WithNullValues_ReturnsMacroStabilityInwardsSurfaceLineWithNaNValues() + { + // Setup + var collector = new ReadConversionCollector(); + var random = new Random(31); + + var point3D = new Point3D(double.NaN, double.NaN, double.NaN); + var points = new[] + { + point3D, + CreatePoint3D(random) + }; + + var entity = new SurfaceLineEntity + { + Name = "name", + PointsXml = new Point3DXmlSerializer().ToXml(points), + MacroStabilityInwardsCharacteristicPointEntities = + { + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.TrafficLoadOutside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.TrafficLoadInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), + CreateMacroStabilityInwardsCharacteristicPointEntity(points[0], MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) + } + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreEqual(entity.Name, surfaceLine.Name); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.X); + Assert.IsNaN(surfaceLine.ReferenceLineIntersectionWorldPoint.Y); + + Point3D[] geometry = surfaceLine.Points.ToArray(); + Assert.AreEqual(2, geometry.Length); + Point3D geometryPoint = geometry[0]; + + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelOutside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.TrafficLoadOutside); + Assert.AreSame(geometryPoint, surfaceLine.TrafficLoadInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DikeTopAtRiver); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderBaseInside); + Assert.AreSame(geometryPoint, surfaceLine.ShoulderTopInside); + Assert.AreSame(geometryPoint, surfaceLine.DikeToeAtPolder); + Assert.AreSame(geometryPoint, surfaceLine.DitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchDikeSide); + Assert.AreSame(geometryPoint, surfaceLine.BottomDitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.DitchPolderSide); + Assert.AreSame(geometryPoint, surfaceLine.SurfaceLevelInside); + } + + [Test] + public void ReadAsMacroStabilityInwardsSurfaceLine_SurfaceLineEntityReadMultipleTimes_ReturnSameSurfaceLine() + { + // Setup + var collector = new ReadConversionCollector(); + + var entity = new SurfaceLineEntity + { + Name = "surface line", + PointsXml = new Point3DXmlSerializer().ToXml(new Point3D[0]) + }; + + // Call + MacroStabilityInwardsSurfaceLine surfaceLine1 = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + MacroStabilityInwardsSurfaceLine surfaceLine2 = entity.ReadAsMacroStabilityInwardsSurfaceLine(collector); + + // Assert + Assert.AreSame(surfaceLine1, surfaceLine2); + } + private static Point3D CreatePoint3D(Random random) { return new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); @@ -341,5 +689,18 @@ Z = point.Z }; } + + private static MacroStabilityInwardsCharacteristicPointEntity CreateMacroStabilityInwardsCharacteristicPointEntity( + Point3D point, + MacroStabilityInwardsCharacteristicPointType type) + { + return new MacroStabilityInwardsCharacteristicPointEntity + { + Type = (byte) type, + X = point.X, + Y = point.Y, + Z = point.Z + }; + } } } \ No newline at end of file