Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -427,6 +427,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs =================================================================== diff -u -r3fb0df0ed6e64657154700ee7706e035d5bf99f5 -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs (.../DataCollectionSerializer.cs) (revision 3fb0df0ed6e64657154700ee7706e035d5bf99f5) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs (.../DataCollectionSerializer.cs) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -32,6 +32,8 @@ /// Converter class that converts between a collection of and an XML representation of that data. /// internal abstract class DataCollectionSerializer + where TData : class + where TSerializedData : class { private static readonly Type serializationRootType = typeof(TSerializedData[]); private readonly Encoding encoding = Encoding.UTF8; @@ -98,8 +100,18 @@ } } + /// + /// Converts to the serializable representation. + /// + /// The elements to convert. + /// The serialized elements. protected abstract TSerializedData[] ToSerializableData(IEnumerable elements); + /// + /// Converts the to . + /// + /// The serialized data to convert. + /// The deserialized elements protected abstract TData[] FromSerializableData(IEnumerable serializedElements); } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/MacroStabilityInwardsSliceXmlSerializer.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/MacroStabilityInwardsSliceXmlSerializer.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/MacroStabilityInwardsSliceXmlSerializer.cs (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -0,0 +1,187 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Geometry; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Application.Ringtoets.Storage.Serializers +{ + /// + /// Converter class that converts between a collection of + /// and an XML representation of that data. + /// + internal class MacroStabilityInwardsSliceXmlSerializer : DataCollectionSerializer + { + protected override SerializableMacroStabilityInwardsSlice[] ToSerializableData(IEnumerable elements) + { + return elements.Select(s => new SerializableMacroStabilityInwardsSlice(s)).ToArray(); + } + + protected override MacroStabilityInwardsSlice[] FromSerializableData(IEnumerable serializedElements) + { + return serializedElements.Select(se => se.ToMacroStabilityInwardsSlice()).ToArray(); + } + + [Serializable] + internal class SerializableMacroStabilityInwardsSlice + { + private readonly double topLeftPointX; + private readonly double topLeftPointY; + private readonly double topRightPointX; + private readonly double topRightPointY; + + private readonly double bottomLeftPointX; + private readonly double bottomLeftPointY; + private readonly double bottomRightPointX; + private readonly double bottomRightPointY; + + private readonly double cohesion; + private readonly double frictionAngle; + private readonly double criticalPressure; + private readonly double overConsolidationRatio; + private readonly double pop; + private readonly double degreeOfConsolidationPorePressureSoil; + private readonly double degreeOfConsolidationPorePressureLoad; + private readonly double dilatancy; + private readonly double externalLoad; + private readonly double hydrostaticPorePressure; + private readonly double leftForce; + private readonly double leftForceAngle; + private readonly double leftForceY; + private readonly double rightForce; + private readonly double rightForceAngle; + private readonly double rightForceY; + private readonly double loadStress; + private readonly double normalStress; + private readonly double porePressure; + private readonly double horizontalPorePressure; + private readonly double verticalPorePressure; + private readonly double piezometricPorePressure; + private readonly double effectiveStress; + private readonly double effectiveStressDaily; + private readonly double excessPorePressure; + private readonly double shearStress; + private readonly double soilStress; + private readonly double totalPorePressure; + private readonly double totalStress; + private readonly double weight; + + /// + /// Creates a new instance of . + /// + /// The to base the + /// on. + public SerializableMacroStabilityInwardsSlice(MacroStabilityInwardsSlice slice) + { + topLeftPointX = slice.TopLeftPoint.X; + topLeftPointY = slice.TopLeftPoint.Y; + topRightPointX = slice.TopRightPoint.X; + topRightPointY = slice.TopRightPoint.Y; + + bottomLeftPointX = slice.BottomLeftPoint.X; + bottomLeftPointY = slice.BottomLeftPoint.Y; + bottomRightPointX = slice.BottomRightPoint.X; + bottomRightPointY = slice.BottomRightPoint.Y; + + cohesion = slice.Cohesion; + frictionAngle = slice.FrictionAngle; + criticalPressure = slice.CriticalPressure; + overConsolidationRatio = slice.OverConsolidationRatio; + pop = slice.Pop; + degreeOfConsolidationPorePressureSoil = slice.DegreeOfConsolidationPorePressureSoil; + degreeOfConsolidationPorePressureLoad = slice.DegreeOfConsolidationPorePressureLoad; + dilatancy = slice.Dilatancy; + externalLoad = slice.ExternalLoad; + hydrostaticPorePressure = slice.HydrostaticPorePressure; + leftForce = slice.LeftForce; + leftForceAngle = slice.LeftForceAngle; + leftForceY = slice.LeftForceY; + rightForce = slice.RightForce; + rightForceAngle = slice.RightForceAngle; + rightForceY = slice.RightForceY; + loadStress = slice.LoadStress; + normalStress = slice.NormalStress; + porePressure = slice.PorePressure; + horizontalPorePressure = slice.HorizontalPorePressure; + verticalPorePressure = slice.VerticalPorePressure; + piezometricPorePressure = slice.PiezometricPorePressure; + effectiveStress = slice.EffectiveStress; + effectiveStressDaily = slice.EffectiveStressDaily; + excessPorePressure = slice.ExcessPorePressure; + shearStress = slice.ShearStress; + soilStress = slice.SoilStress; + totalPorePressure = slice.TotalPorePressure; + totalStress = slice.TotalStress; + weight = slice.Weight; + } + + /// + /// Creates a new instance of . + /// + /// The new instance of . + public MacroStabilityInwardsSlice ToMacroStabilityInwardsSlice() + { + return new MacroStabilityInwardsSlice( + new Point2D(topLeftPointX, topLeftPointY), + new Point2D(topRightPointX, topRightPointY), + new Point2D(bottomLeftPointX, bottomLeftPointY), + new Point2D(bottomRightPointX, bottomRightPointY), + new MacroStabilityInwardsSlice.ConstructionProperties + { + Cohesion = cohesion, + FrictionAngle = frictionAngle, + CriticalPressure = criticalPressure, + OverConsolidationRatio = overConsolidationRatio, + Pop = pop, + DegreeOfConsolidationPorePressureSoil = degreeOfConsolidationPorePressureSoil, + DegreeOfConsolidationPorePressureLoad = degreeOfConsolidationPorePressureLoad, + Dilatancy = dilatancy, + ExternalLoad = externalLoad, + HydrostaticPorePressure = hydrostaticPorePressure, + LeftForce = leftForce, + LeftForceAngle = leftForceAngle, + LeftForceY = leftForceY, + RightForce = rightForce, + RightForceAngle = rightForceAngle, + RightForceY = rightForceY, + LoadStress = loadStress, + NormalStress = normalStress, + PorePressure = porePressure, + HorizontalPorePressure = horizontalPorePressure, + VerticalPorePressure = verticalPorePressure, + PiezometricPorePressure = piezometricPorePressure, + EffectiveStress = effectiveStress, + EffectiveStressDaily = effectiveStressDaily, + ExcessPorePressure = excessPorePressure, + ShearStress = shearStress, + SoilStress = soilStress, + TotalPorePressure = totalPorePressure, + TotalStress = totalStress, + Weight = weight + }); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r9f936b0b29f490a024df02345df182133b1c041a -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 9f936b0b29f490a024df02345df182133b1c041a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -167,6 +167,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/MacroStabilityInwardsSliceXmlSerializerTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/MacroStabilityInwardsSliceXmlSerializerTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/MacroStabilityInwardsSliceXmlSerializerTest.cs (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -0,0 +1,155 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections; +using Application.Ringtoets.Storage.Serializers; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data; + +namespace Application.Ringtoets.Storage.Test.Serializers +{ + [TestFixture] + public class MacroStabilityInwardsSliceXmlSerializerTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var serializer = new MacroStabilityInwardsSliceXmlSerializer(); + + // Assert + Assert.IsInstanceOf>(serializer); + } + + [Test] + public void GivenArrayOfMacroStabilityInwardsSlices_WhenConvertingRoundTrip_ThenEqualMacroStabilityInwardsSlices() + { + // Given + var random = new Random(31); + var original = new[] + { + new MacroStabilityInwardsSlice( + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new Point2D(double.NaN, double.NaN), + new MacroStabilityInwardsSlice.ConstructionProperties()), + new MacroStabilityInwardsSlice( + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new MacroStabilityInwardsSlice.ConstructionProperties + { + Cohesion = random.NextDouble(), + FrictionAngle = random.NextDouble(), + CriticalPressure = random.NextDouble(), + OverConsolidationRatio = random.NextDouble(), + Pop = random.NextDouble(), + DegreeOfConsolidationPorePressureSoil = random.NextDouble(), + DegreeOfConsolidationPorePressureLoad = random.NextDouble(), + Dilatancy = random.NextDouble(), + ExternalLoad = random.NextDouble(), + HydrostaticPorePressure = random.NextDouble(), + LeftForce = random.NextDouble(), + LeftForceAngle = random.NextDouble(), + LeftForceY = random.NextDouble(), + RightForce = random.NextDouble(), + RightForceAngle = random.NextDouble(), + RightForceY = random.NextDouble(), + LoadStress = random.NextDouble(), + NormalStress = random.NextDouble(), + PorePressure = random.NextDouble(), + HorizontalPorePressure = random.NextDouble(), + VerticalPorePressure = random.NextDouble(), + PiezometricPorePressure = random.NextDouble(), + EffectiveStress = random.NextDouble(), + EffectiveStressDaily = random.NextDouble(), + ExcessPorePressure = random.NextDouble(), + ShearStress = random.NextDouble(), + SoilStress = random.NextDouble(), + TotalPorePressure = random.NextDouble(), + TotalStress = random.NextDouble(), + Weight = random.NextDouble() + }) + }; + var serializer = new MacroStabilityInwardsSliceXmlSerializer(); + + // When + string xml = serializer.ToXml(original); + MacroStabilityInwardsSlice[] roundtripResult = serializer.FromXml(xml); + + // Then + CollectionAssert.AreEqual(original, roundtripResult, new MacroStabilityInwardsSliceComparer()); + } + + private class MacroStabilityInwardsSliceComparer : IComparer + { + public int Compare(object x, object y) + { + var x1 = (MacroStabilityInwardsSlice) x; + var y1 = (MacroStabilityInwardsSlice) y; + if (x1.TopLeftPoint.Equals(y1.TopLeftPoint) + && x1.TopRightPoint.Equals(y1.TopRightPoint) + && x1.BottomLeftPoint.Equals(y1.BottomLeftPoint) + && x1.BottomRightPoint.Equals(y1.BottomRightPoint) + && x1.Cohesion.Equals(y1.Cohesion) + && x1.FrictionAngle.Equals(y1.FrictionAngle) + && x1.CriticalPressure.Equals(y1.CriticalPressure) + && x1.OverConsolidationRatio.Equals(y1.OverConsolidationRatio) + && x1.Pop.Equals(y1.Pop) + && x1.DegreeOfConsolidationPorePressureSoil.Equals(y1.DegreeOfConsolidationPorePressureSoil) + && x1.DegreeOfConsolidationPorePressureLoad.Equals(y1.DegreeOfConsolidationPorePressureLoad) + && x1.Dilatancy.Equals(y1.Dilatancy) + && x1.ExternalLoad.Equals(y1.ExternalLoad) + && x1.HydrostaticPorePressure.Equals(y1.HydrostaticPorePressure) + && x1.LeftForce.Equals(y1.LeftForce) + && x1.LeftForceAngle.Equals(y1.LeftForceAngle) + && x1.LeftForceY.Equals(y1.LeftForceY) + && x1.RightForce.Equals(y1.RightForce) + && x1.RightForceAngle.Equals(y1.RightForceAngle) + && x1.RightForceY.Equals(y1.RightForceY) + && x1.LoadStress.Equals(y1.LoadStress) + && x1.NormalStress.Equals(y1.NormalStress) + && x1.PorePressure.Equals(y1.PorePressure) + && x1.HorizontalPorePressure.Equals(y1.HorizontalPorePressure) + && x1.VerticalPorePressure.Equals(y1.VerticalPorePressure) + && x1.PiezometricPorePressure.Equals(y1.PiezometricPorePressure) + && x1.EffectiveStress.Equals(y1.EffectiveStress) + && x1.EffectiveStressDaily.Equals(y1.EffectiveStressDaily) + && x1.ExcessPorePressure.Equals(y1.ExcessPorePressure) + && x1.ShearStress.Equals(y1.ShearStress) + && x1.SoilStress.Equals(y1.SoilStress) + && x1.TotalPorePressure.Equals(y1.TotalPorePressure) + && x1.TotalStress.Equals(y1.TotalStress) + && x1.Weight.Equals(y1.Weight) + ) + { + return 0; + } + return 1; + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point2DXmlSerializerTest.cs =================================================================== diff -u -r8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point2DXmlSerializerTest.cs (.../Point2DXmlSerializerTest.cs) (revision 8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point2DXmlSerializerTest.cs (.../Point2DXmlSerializerTest.cs) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -63,20 +63,5 @@ // Then CollectionAssert.AreEqual(original, roundtripResult); } - - [Test] - public void GivenEmptyArray_WhenConvertingRoundTrip_ThenReturnEmptyArray() - { - // Given - var original = new Point2D[0]; - var serializer = new Point2DXmlSerializer(); - - // When - string xml = serializer.ToXml(original); - Point2D[] roundtripResult = serializer.FromXml(xml); - - // Then - CollectionAssert.IsEmpty(roundtripResult); - } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point3DXmlSerializerTest.cs =================================================================== diff -u -r8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point3DXmlSerializerTest.cs (.../Point3DXmlSerializerTest.cs) (revision 8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/Point3DXmlSerializerTest.cs (.../Point3DXmlSerializerTest.cs) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -60,20 +60,5 @@ // Then CollectionAssert.AreEqual(original, roundtripResult); } - - [Test] - public void GivenEmptyArray_WhenConvertingRoundTrip_ThenReturnEmptyArray() - { - // Given - var original = new Point3D[0]; - var serializer = new Point3DXmlSerializer(); - - // When - string xml = serializer.ToXml(original); - Point3D[] roundtripResult = serializer.FromXml(xml); - - // Then - CollectionAssert.IsEmpty(roundtripResult); - } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RingXmlSerializerTest.cs =================================================================== diff -u -r9f936b0b29f490a024df02345df182133b1c041a -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RingXmlSerializerTest.cs (.../RingXmlSerializerTest.cs) (revision 9f936b0b29f490a024df02345df182133b1c041a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RingXmlSerializerTest.cs (.../RingXmlSerializerTest.cs) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -71,20 +71,5 @@ // Then CollectionAssert.AreEqual(original, roundtripResult); } - - [Test] - public void GivenEmptyArray_WhenConvertingRoundTrip_ThenReturnEmptyArray() - { - // Given - var original = new Ring[0]; - var serializer = new RingXmlSerializer(); - - // When - string xml = serializer.ToXml(original); - Ring[] roundtripResult = serializer.FromXml(xml); - - // Then - CollectionAssert.IsEmpty(roundtripResult); - } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RoughnessPointXmlSerializerTest.cs =================================================================== diff -u -r8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc -r2a585c57b57dac62d39293e51dda15c7392305de --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RoughnessPointXmlSerializerTest.cs (.../RoughnessPointXmlSerializerTest.cs) (revision 8ff26e0d7885f432a6e470e8d68ce325bdc6a9bc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/RoughnessPointXmlSerializerTest.cs (.../RoughnessPointXmlSerializerTest.cs) (revision 2a585c57b57dac62d39293e51dda15c7392305de) @@ -41,7 +41,7 @@ } [Test] - public void GivenArrayWithPoint2D_WhenConvertingRoundTrip_ThenEqualArrayOfPoints2D() + public void GivenArrayWithRoughnessPoint_WhenConvertingRoundTrip_ThenEqualArrayOfRoughnessPoint() { // Given var original = new[] @@ -66,21 +66,6 @@ CollectionAssert.AreEqual(original, roundtripResult, new RoughnessPointComparer()); } - [Test] - public void GivenEmptyArray_WhenConvertingRoundTrip_ThenReturnEmptyArray() - { - // Given - var original = new RoughnessPoint[0]; - var converter = new RoughnessPointXmlSerializer(); - - // When - string xml = converter.ToXml(original); - RoughnessPoint[] roundtripResult = converter.FromXml(xml); - - // Then - CollectionAssert.IsEmpty(roundtripResult); - } - private class RoughnessPointComparer : IComparer { public int Compare(object x, object y)