Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismSectionEntityReadExtensions.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismSectionEntityReadExtensions.cs (.../FailureMechanismSectionEntityReadExtensions.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismSectionEntityReadExtensions.cs (.../FailureMechanismSectionEntityReadExtensions.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -40,6 +40,8 @@
/// The object keeping track of read operations.
/// A new .
/// Thrown when is null.
+ /// Thrown when
+ /// of is null or empty.
internal static FailureMechanismSection Read(this FailureMechanismSectionEntity entity, ReadConversionCollector collector)
{
if (collector == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ForeshoreProfileEntityReadExtensions.cs
===================================================================
diff -u -r8aaa7b9a8a2826cf8da31d0fd136f2d559933afe -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ForeshoreProfileEntityReadExtensions.cs (.../ForeshoreProfileEntityReadExtensions.cs) (revision 8aaa7b9a8a2826cf8da31d0fd136f2d559933afe)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ForeshoreProfileEntityReadExtensions.cs (.../ForeshoreProfileEntityReadExtensions.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -40,6 +40,8 @@
/// The object keeping track of read operations.
/// A new .
/// Thrown when is null.
+ /// Thrown when
+ /// of is null or empty.
internal static ForeshoreProfile Read(this ForeshoreProfileEntity entity, ReadConversionCollector collector)
{
if (collector == null)
@@ -50,14 +52,14 @@
Point2D[] points = new Point2DXmlSerializer().FromXml(entity.GeometryXml);
return new ForeshoreProfile(new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()),
- points,
- CreateBreakWater(entity.BreakWaterType, entity.BreakWaterHeight),
- new ForeshoreProfile.ConstructionProperties
- {
- Name = entity.Name,
- Orientation = entity.Orientation.ToNullAsNaN(),
- X0 = entity.X0.ToNullAsNaN()
- });
+ points,
+ CreateBreakWater(entity.BreakWaterType, entity.BreakWaterHeight),
+ new ForeshoreProfile.ConstructionProperties
+ {
+ Name = entity.Name,
+ Orientation = entity.Orientation.ToNullAsNaN(),
+ X0 = entity.X0.ToNullAsNaN()
+ });
}
private static BreakWater CreateBreakWater(byte? breakWaterType, double? breakWaterHeight)
@@ -66,7 +68,7 @@
{
return null;
}
- return new BreakWater((BreakWaterType)breakWaterType.Value, breakWaterHeight.ToNullAsNaN());
+ return new BreakWater((BreakWaterType) breakWaterType.Value, breakWaterHeight.ToNullAsNaN());
}
}
}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensions.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensions.cs (.../DikeProfileEntityReadExtensions.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensions.cs (.../DikeProfileEntityReadExtensions.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -40,6 +40,9 @@
/// The to create for.
/// The object keeping track of read operations.
/// A new .
+ /// Thrown when is null.
+ /// Thrown when
+ /// or of is null or empty.
internal static DikeProfile Read(this DikeProfileEntity entity, ReadConversionCollector collector)
{
if (collector == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/StochasticSoilModelEntityReadExtensions.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/StochasticSoilModelEntityReadExtensions.cs (.../StochasticSoilModelEntityReadExtensions.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/StochasticSoilModelEntityReadExtensions.cs (.../StochasticSoilModelEntityReadExtensions.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -40,6 +40,8 @@
/// The object keeping track of read operations.
/// A new .
/// Thrown when is null.
+ /// Thrown when
+ /// of is null or empty.
internal static StochasticSoilModel Read(this StochasticSoilModelEntity entity, ReadConversionCollector collector)
{
if (collector == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/SurfaceLineEntityReadExtensions.cs
===================================================================
diff -u -r11f0867b39150ae5fac83dc178a89fee46d27611 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 11f0867b39150ae5fac83dc178a89fee46d27611)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/Piping/SurfaceLineEntityReadExtensions.cs (.../SurfaceLineEntityReadExtensions.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -43,6 +43,8 @@
/// The object keeping track of read operations.
/// A new .
/// Thrown when is null.
+ /// Thrown when
+ /// of is null or empty.
internal static RingtoetsPipingSurfaceLine Read(this SurfaceLineEntity entity, ReadConversionCollector collector)
{
if (collector == null)
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs
===================================================================
diff -u -rf64dceaa32788bad28dcf09f4a1c3150595f1327 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs (.../DataCollectionSerializer.cs) (revision f64dceaa32788bad28dcf09f4a1c3150595f1327)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/DataCollectionSerializer.cs (.../DataCollectionSerializer.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -23,13 +23,15 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
-using System.ServiceModel;
using System.Text;
using System.Xml;
namespace Application.Ringtoets.Storage.Serializers
{
- internal abstract class SimpleDataCollectionSerializer
+ ///
+ /// Converter class that converts between a collection of and an XML representation of that data.
+ ///
+ internal abstract class DataCollectionSerializer
{
private static readonly Type serializationRootType = typeof(TSerializedData[]);
private readonly Encoding encoding = Encoding.UTF8;
@@ -41,9 +43,9 @@
/// The XML data.
/// Thrown when is null.
/// Thrown when an I/O error occurs.
+ /// Thrown when does not conform to data contract rules.
+ /// E.g., the has not been applied to the .
/// Thrown when an error occurs during serialization.
- /// Thrown when
- /// contains too many objects.
public string ToXml(IEnumerable elements)
{
if (elements == null)
@@ -71,14 +73,14 @@
///
/// The XML.
/// An array of .
- /// Thrown when is null.
+ /// Thrown when is null or empty.
/// Thrown when an I/O error occurs.
/// Thrown when an error occurs during deserialization.
public TData[] FromXml(string xml)
{
- if (xml == null)
+ if (string.IsNullOrEmpty(xml))
{
- throw new ArgumentNullException("xml");
+ throw new ArgumentException(@"xml cannot be empty.", "xml");
}
var stream = new MemoryStream();
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point2DXmlSerializer.cs
===================================================================
diff -u -rc2bf0666539fa1a781c6d5d633ac292fa4fe2bd4 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point2DXmlSerializer.cs (.../Point2DXmlSerializer.cs) (revision c2bf0666539fa1a781c6d5d633ac292fa4fe2bd4)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point2DXmlSerializer.cs (.../Point2DXmlSerializer.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -30,7 +30,7 @@
/// Converter class that converts between a collection of and an
/// XML representation of that data.
///
- internal class Point2DXmlSerializer : SimpleDataCollectionSerializer
+ internal class Point2DXmlSerializer : DataCollectionSerializer
{
protected override SerializablePoint2D[] ToSerializableData(IEnumerable points)
{
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point3DXmlSerializer.cs
===================================================================
diff -u -rc2bf0666539fa1a781c6d5d633ac292fa4fe2bd4 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point3DXmlSerializer.cs (.../Point3DXmlSerializer.cs) (revision c2bf0666539fa1a781c6d5d633ac292fa4fe2bd4)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/Point3DXmlSerializer.cs (.../Point3DXmlSerializer.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -30,7 +30,7 @@
/// Converter class that converts between a collection of and an
/// XML representation of that data.
///
- internal class Point3DXmlSerializer : SimpleDataCollectionSerializer
+ internal class Point3DXmlSerializer : DataCollectionSerializer
{
protected override Point3D[] FromSerializableData(IEnumerable serializedElements)
{
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/RoughnessPointXmlSerializer.cs
===================================================================
diff -u -r30b8231f92b90ea4b05e98e3d0285368f6dfe2e4 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/RoughnessPointXmlSerializer.cs (.../RoughnessPointXmlSerializer.cs) (revision 30b8231f92b90ea4b05e98e3d0285368f6dfe2e4)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Serializers/RoughnessPointXmlSerializer.cs (.../RoughnessPointXmlSerializer.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -31,7 +31,7 @@
/// Converter class that converts between a collection of
/// and an XML representation of that data.
///
- internal class RoughnessPointXmlSerializer : SimpleDataCollectionSerializer
+ internal class RoughnessPointXmlSerializer : DataCollectionSerializer
{
protected override SerializableRoughnessPoint[] ToSerializableData(IEnumerable elements)
{
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -r8aaa7b9a8a2826cf8da31d0fd136f2d559933afe -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 8aaa7b9a8a2826cf8da31d0fd136f2d559933afe)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -68,6 +68,7 @@
True
+
@@ -80,6 +81,7 @@
+
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ForeshoreProfileCreateExtensionsTest.cs
===================================================================
diff -u -r8aaa7b9a8a2826cf8da31d0fd136f2d559933afe -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ForeshoreProfileCreateExtensionsTest.cs (.../ForeshoreProfileCreateExtensionsTest.cs) (revision 8aaa7b9a8a2826cf8da31d0fd136f2d559933afe)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ForeshoreProfileCreateExtensionsTest.cs (.../ForeshoreProfileCreateExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -32,6 +32,7 @@
namespace Application.Ringtoets.Storage.Test.Create
{
+ [TestFixture]
public class ForeshoreProfileCreateExtensionsTest
{
[Test]
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs
===================================================================
diff -u -r97018b4e8e9cd81438e8fd0d111d889e20946617 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs (.../FailureMechanismSectionEntityReadExtensionsTest.cs) (revision 97018b4e8e9cd81438e8fd0d111d889e20946617)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismSectionEntityReadExtensionsTest.cs (.../FailureMechanismSectionEntityReadExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -43,6 +43,25 @@
}
[Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_FailureMechanismSectionPointXmlNullOrEmpty_ThrowsArgumentException(string xml)
+ {
+ // Setup
+ var entity = new FailureMechanismSectionEntity
+ {
+ FailureMechanismSectionPointXml = xml
+ };
+
+ // Call
+ TestDelegate test = () => entity.Read(new ReadConversionCollector());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Test]
public void Read_Always_NewPoint()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ForeshoreProfileReadExtensionsTest.cs
===================================================================
diff -u -r8aaa7b9a8a2826cf8da31d0fd136f2d559933afe -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ForeshoreProfileReadExtensionsTest.cs (.../ForeshoreProfileReadExtensionsTest.cs) (revision 8aaa7b9a8a2826cf8da31d0fd136f2d559933afe)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ForeshoreProfileReadExtensionsTest.cs (.../ForeshoreProfileReadExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -46,13 +46,21 @@
}
[Test]
- public void Read_GeometryXmlNull_ThrowsArgumentNullException()
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_GeometryXmlNullOrEmpty_ThrowsArgumentException(string xml)
{
+ // Setup
+ var entity = new ForeshoreProfileEntity
+ {
+ GeometryXml = xml
+ };
+
// Call
- TestDelegate test = () => new ForeshoreProfileEntity().Read(new ReadConversionCollector());
+ TestDelegate test = () => entity.Read(new ReadConversionCollector());
// Assert
- string paramName = Assert.Throws(test).ParamName;
+ string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("xml", paramName);
}
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs
===================================================================
diff -u -r97018b4e8e9cd81438e8fd0d111d889e20946617 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs (.../DikeProfileEntityReadExtensionsTest.cs) (revision 97018b4e8e9cd81438e8fd0d111d889e20946617)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/GrassCoverErosionInwards/DikeProfileEntityReadExtensionsTest.cs (.../DikeProfileEntityReadExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -34,6 +34,11 @@
[TestFixture]
public class DikeProfileEntityReadExtensionsTest
{
+ private const string validRoughnessPointXml = "" +
+ "";
+
[Test]
public void Read_ReadConversionCollectorNull_ThrowArgumentNullException()
{
@@ -49,6 +54,46 @@
}
[Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_DikeGeometryXmlNullOrEmpty_ThrowsArgumentException(string xml)
+ {
+ // Setup
+ var profile = new DikeProfileEntity
+ {
+ DikeGeometryXml = xml,
+ ForeShoreXml = validRoughnessPointXml
+ };
+
+ // Call
+ TestDelegate test = () => profile.Read(new ReadConversionCollector());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_ForeShoreXmlNullOrEmpty_ThrowsArgumentException(string xml)
+ {
+ // Setup
+ var profile = new DikeProfileEntity
+ {
+ DikeGeometryXml = validRoughnessPointXml,
+ ForeShoreXml = xml
+ };
+
+ // Call
+ TestDelegate test = () => profile.Read(new ReadConversionCollector());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Test]
public void Read_DikeProfileEntityWithBreakWaterPropertiesNull_ReturnDikeProfileWithoutBreakWater()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/StochasticSoilModelEntityReadExtensionsTest.cs
===================================================================
diff -u -r97018b4e8e9cd81438e8fd0d111d889e20946617 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/StochasticSoilModelEntityReadExtensionsTest.cs (.../StochasticSoilModelEntityReadExtensionsTest.cs) (revision 97018b4e8e9cd81438e8fd0d111d889e20946617)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/StochasticSoilModelEntityReadExtensionsTest.cs (.../StochasticSoilModelEntityReadExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -49,6 +49,27 @@
}
[Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_StochasticSoilModelSegmentPointXmlNullOrEmpty_ThrowsArgumentException(string xml)
+ {
+ // Setup
+ var entity = new StochasticSoilModelEntity
+ {
+ Name = "Name",
+ SegmentName = "SegmentName",
+ StochasticSoilModelSegmentPointXml = xml
+ };
+
+ // Call
+ TestDelegate test = () => entity.Read(new ReadConversionCollector());
+
+ // Assert
+ string paramName = Assert.Throws(test).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Test]
public void Read_WithCollector_ReturnsNewStochasticSoilModelWithPropertiesSet()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/SurfaceLineEntityReadExtensionsTest.cs
===================================================================
diff -u -r97018b4e8e9cd81438e8fd0d111d889e20946617 -r3b68b0758709ec06ecc7581f4f852f3cea864c5d
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 97018b4e8e9cd81438e8fd0d111d889e20946617)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/Piping/SurfaceLineEntityReadExtensionsTest.cs (.../SurfaceLineEntityReadExtensionsTest.cs) (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -48,6 +48,24 @@
}
[Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Read_PointsXmlNullOrEmpty_ThrowsArgumentException(string xml)
+ {
+ var entity = new SurfaceLineEntity
+ {
+ PointsXml = xml
+ };
+
+ // Call
+ TestDelegate call = () => entity.Read(new ReadConversionCollector());
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Test]
public void Read_SurfaceLineEntityWithoutGeometryPointEntities_ReturnSurfaceLine()
{
// Setup
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/DataCollectionSerializerTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/DataCollectionSerializerTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Serializers/DataCollectionSerializerTest.cs (revision 3b68b0758709ec06ecc7581f4f852f3cea864c5d)
@@ -0,0 +1,154 @@
+// 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 System.Linq;
+using System.Runtime.Serialization;
+using Application.Ringtoets.Storage.Serializers;
+using NUnit.Framework;
+
+namespace Application.Ringtoets.Storage.Test.Serializers
+{
+ [TestFixture]
+ public class DataCollectionSerializerTest
+ {
+ private const string inValidXml = "Invalid";
+
+ [Test]
+ public void ToXml_CollectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var serializer = new TestDataCollectionSerializer();
+
+ // Call
+ TestDelegate call = () => serializer.ToXml(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("elements", paramName);
+ }
+
+ [Test]
+ public void ToXml_CollectionUnableToSerialize_ThrowsInvalidDataContractException()
+ {
+ // Setup
+ var serializer = new UnableToSerializeDataCollectionSerializer();
+ var collection = new[]
+ {
+ new object()
+ };
+
+ // Call
+ TestDelegate call = () => serializer.ToXml(collection);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void GivenArray_WhenConvertingRoundTrip_ThenEqualArray()
+ {
+ // Given
+ var original = new[]
+ {
+ new TestSerializableObject()
+ };
+ var serializer = new TestDataCollectionSerializer();
+
+ // When
+ string xml = serializer.ToXml(original);
+ TestSerializableObject[] roundtripResult = serializer.FromXml(xml);
+
+ // Then
+ Assert.AreEqual(1, roundtripResult.Length);
+ Assert.IsInstanceOf(roundtripResult[0]);
+ }
+
+ [Test]
+ public void FromXml_InvalidXml_ThrowsSerializationException()
+ {
+ // Setup
+ var serializer = new TestDataCollectionSerializer();
+
+ // Call
+ TestDelegate call = () => serializer.FromXml(inValidXml);
+
+ // Assert
+ Assert.Throws(call);
+ }
+
+ [Test]
+ [TestCase(null)]
+ [TestCase("")]
+ public void FromXml_XmlNullOrEmpty_ThrowArgumentException(string xml)
+ {
+ // Setup
+ var serializer = new TestDataCollectionSerializer();
+
+ // Call
+ TestDelegate call = () => serializer.FromXml(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("xml", paramName);
+ }
+
+ [Serializable]
+ private class TestSerializableObject {}
+
+ private class TestUnSerializableObject
+ {
+ public object ToObject()
+ {
+ return new object();
+ }
+ }
+
+ private class TestDataCollectionSerializer : DataCollectionSerializer
+ {
+ protected override TestSerializableObject[] ToSerializableData(IEnumerable objects)
+ {
+ return objects.ToArray();
+ }
+
+ protected override TestSerializableObject[] FromSerializableData(IEnumerable objectData)
+ {
+ return objectData.ToArray();
+ }
+ }
+
+ private class UnableToSerializeDataCollectionSerializer : DataCollectionSerializer