Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Creators/SerializableAssemblyCreator.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Creators/SerializableAssemblyCreator.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Creators/SerializableAssemblyCreator.cs (revision 0a9f06e0327c4b0dafad250ab516d375701d231e) @@ -0,0 +1,81 @@ +// 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.AssemblyTool.IO.Model; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.Integration.IO.Helpers; + +namespace Ringtoets.Integration.IO.Creators +{ + /// + /// Creator class which creates instances of . + /// + public static class SerializableAssemblyCreator + { + /// + /// Creates an instance of based + /// on . + /// + /// The + /// to create a for. + /// A . + /// Thrown when + /// is null. + public static SerializableAssembly Create(ExportableAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var idGenerator = new UniqueIdentifierGenerator(); + string serializableAssemblyId = idGenerator.GetNewId().ToString(); + + return new SerializableAssembly(serializableAssemblyId, + GetLowerCorner(assessmentSection.Geometry), + GetUpperCorner(assessmentSection.Geometry), + new SerializableAssessmentSection(), + new SerializableAssessmentProcess(), + new SerializableTotalAssemblyResult(), + Enumerable.Empty(), + Enumerable.Empty(), + Enumerable.Empty(), + Enumerable.Empty(), + Enumerable.Empty()); + } + + private static Point2D GetLowerCorner(IEnumerable geometry) + { + return new Point2D(geometry.Select(p => p.X).Min(), + geometry.Select(p => p.Y).Min()); + } + + private static Point2D GetUpperCorner(IEnumerable geometry) + { + return new Point2D(geometry.Select(p => p.X).Max(), + geometry.Select(p => p.Y).Max()); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj =================================================================== diff -u -r77af63e3ae290bffd192ac96059661e15181c775 -r0a9f06e0327c4b0dafad250ab516d375701d231e --- Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 77af63e3ae290bffd192ac96059661e15181c775) +++ Ringtoets/Integration/src/Ringtoets.Integration.IO/Ringtoets.Integration.IO.csproj (.../Ringtoets.Integration.IO.csproj) (revision 0a9f06e0327c4b0dafad250ab516d375701d231e) @@ -34,6 +34,7 @@ + @@ -100,6 +101,11 @@ Ringtoets.AssemblyTool.Data False + + {b9838495-b090-4b84-a387-a8974f4f9cc4} + Ringtoets.AssemblyTool.IO + False + {c6309704-d67b-434c-bc98-9f8910bc1d10} Ringtoets.ClosingStructures.Data Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Creators/SerializableAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Creators/SerializableAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Creators/SerializableAssemblyCreatorTest.cs (revision 0a9f06e0327c4b0dafad250ab516d375701d231e) @@ -0,0 +1,120 @@ +// 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 NUnit.Framework; +using Ringtoets.AssemblyTool.IO.Model; +using Ringtoets.AssemblyTool.IO.Model.Gml; +using Ringtoets.AssemblyTool.IO.Model.Helpers; +using Ringtoets.Integration.IO.Assembly; +using Ringtoets.Integration.IO.Creators; +using Ringtoets.Integration.IO.TestUtil; + +namespace Ringtoets.Integration.IO.Test.Creators +{ + [TestFixture] + public class SerializableAssemblyCreatorTest + { + [Test] + public void Create_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => SerializableAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateSerializableAssembly_WithValidArguments_ReturnsSerializableAssembly() + { + // Setup + const string assessmentSectionName = "assessmentSectionName"; + + IEnumerable geometry = CreateGeometry(); + ExportableAssessmentSectionAssemblyResult assessmentSectionAssembly = + ExportableAssessmentSectionAssemblyResultTestFactory.CreateResult(); + ExportableFailureMechanismAssemblyResultWithProbability failureMechanismAssemblyResultWithProbability = + ExportableFailureMechanismAssemblyResultTestFactory.CreateResultWithProbability(); + ExportableFailureMechanismAssemblyResult failureMechanismAssemblyResultWithoutProbability = + ExportableFailureMechanismAssemblyResultTestFactory.CreateResultWithoutProbability(); + IEnumerable> failureMechanismsWithProbability = + Enumerable.Empty>(); + IEnumerable> failureMechanismsWithoutProbability = + Enumerable.Empty>(); + ExportableCombinedSectionAssemblyCollection combinedSectionAssemblyResults = CreateCombinedSectionAssemblyCollection(); + + var exportableAssessmentSection = new ExportableAssessmentSection(assessmentSectionName, + geometry, + assessmentSectionAssembly, + failureMechanismAssemblyResultWithProbability, + failureMechanismAssemblyResultWithoutProbability, + failureMechanismsWithProbability, + failureMechanismsWithoutProbability, + combinedSectionAssemblyResults); + + // Call + SerializableAssembly serializableAssembly = SerializableAssemblyCreator.Create(exportableAssessmentSection); + + // Assert + Assert.AreEqual("0", serializableAssembly.Id); + AssertSerializableBoundary(exportableAssessmentSection.Geometry, serializableAssembly.Boundary); + Assert.AreEqual(3, serializableAssembly.FeatureMembers.Length); + } + + private static IEnumerable CreateGeometry() + { + return new[] + { + new Point2D(1, 1), + new Point2D(4, 4), + new Point2D(5, -1) + }; + } + + private static ExportableCombinedSectionAssemblyCollection CreateCombinedSectionAssemblyCollection() + { + return new ExportableCombinedSectionAssemblyCollection(Enumerable.Empty(), + Enumerable.Empty()); + } + + private static void AssertSerializableBoundary(IEnumerable geometry, + SerializableBoundary actualBoundary) + { + var expectedLowerCorner = new Point2D(geometry.Select(p => p.X).Min(), + geometry.Select(p => p.Y).Min()); + + var expectedUpperCorner = new Point2D(geometry.Select(p => p.X).Max(), + geometry.Select(p => p.Y).Max()); + + string expectedLowerCornerFormat = GeometrySerializationFormatter.Format(expectedLowerCorner); + string expectedUpperCornerFormat = GeometrySerializationFormatter.Format(expectedUpperCorner); + + SerializableEnvelope envelope = actualBoundary.Envelope; + Assert.AreEqual(expectedLowerCornerFormat, envelope.LowerCorner); + Assert.AreEqual(expectedUpperCornerFormat, envelope.UpperCorner); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj =================================================================== diff -u -r1d99b76fe3803f4ca528ff2af110f4da166c0686 -r0a9f06e0327c4b0dafad250ab516d375701d231e --- Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 1d99b76fe3803f4ca528ff2af110f4da166c0686) +++ Ringtoets/Integration/test/Ringtoets.Integration.IO.Test/Ringtoets.Integration.IO.Test.csproj (.../Ringtoets.Integration.IO.Test.csproj) (revision 0a9f06e0327c4b0dafad250ab516d375701d231e) @@ -36,6 +36,7 @@ + @@ -83,6 +84,10 @@ {420ED9C3-0C33-47EA-B893-121A9C0DB4F1} Ringtoets.AssemblyTool.Data + + {B9838495-B090-4B84-A387-A8974F4F9CC4} + Ringtoets.AssemblyTool.IO + {358B6DA2-A1DF-477F-B6AC-C30204265CB0} Ringtoets.AssemblyTool.KernelWrapper