Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/IStochasticSoilModelTransformer.cs
===================================================================
diff -u -r94ce658a9488c346f114446f0e37dabab7acaa38 -r15ba57d868f00dfd3d6b52ac2e03a202d47d0303
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/IStochasticSoilModelTransformer.cs (.../IStochasticSoilModelTransformer.cs) (revision 94ce658a9488c346f114446f0e37dabab7acaa38)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/IStochasticSoilModelTransformer.cs (.../IStochasticSoilModelTransformer.cs) (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -35,7 +35,9 @@
/// stochastic soil model of type .
///
/// The stochastic soil model to use in the transformation.
- /// A new based on the given data.
+ /// A new based on the given data, or null when
+ /// is not of a type that can be transformed to
+ /// the mechanism specific .
/// Thrown when transformation would not result
/// in a valid transformed instance.
T Transform(StochasticSoilModel stochasticSoilModel);
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSoilProfileTransformer.cs
===================================================================
diff -u
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSoilProfileTransformer.cs (revision 0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSoilProfileTransformer.cs (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -0,0 +1,77 @@
+// 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 Ringtoets.Common.IO.Exceptions;
+using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.IO.Importers
+{
+ ///
+ /// Transforms generic into .
+ ///
+ public static class PipingSoilProfileTransformer
+ {
+ ///
+ /// Transforms the generic into a mechanism specific
+ /// soil profile of type .
+ ///
+ /// The soil profile to use in the transformation.
+ /// A new based on the given data, or null when
+ /// is not of a type that can be transformed to
+ /// the mechanism specific .
+ /// Thrown when is null.
+ /// Thrown when transformation would not result
+ /// in a valid transformed instance.
+ public static PipingSoilProfile Transform(ISoilProfile soilProfile)
+ {
+ if (soilProfile == null)
+ {
+ throw new ArgumentNullException(nameof(soilProfile));
+ }
+
+ var soilProfile1D = soilProfile as SoilProfile1D;
+ if (soilProfile1D != null)
+ {
+ return CreatePipingSoilProfile(soilProfile1D);
+ }
+
+ var soilProfile2D = soilProfile as SoilProfile2D;
+ if (soilProfile2D != null)
+ {
+ return CreatePipingSoilProfile(soilProfile2D);
+ }
+
+ return null;
+ }
+
+ private static PipingSoilProfile CreatePipingSoilProfile(SoilProfile2D soilProfile2D)
+ {
+ return null;
+ }
+
+ private static PipingSoilProfile CreatePipingSoilProfile(SoilProfile1D soilProfile1D)
+ {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilModelTransformer.cs
===================================================================
diff -u -rb78437864e9677d66dc309d766b0e706c8af0c1f -r15ba57d868f00dfd3d6b52ac2e03a202d47d0303
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilModelTransformer.cs (.../PipingStochasticSoilModelTransformer.cs) (revision b78437864e9677d66dc309d766b0e706c8af0c1f)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilModelTransformer.cs (.../PipingStochasticSoilModelTransformer.cs) (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -19,8 +19,12 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System.Collections.Generic;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Common.IO.SoilProfile.Schema;
using Ringtoets.Piping.Data.SoilProfile;
+using Ringtoets.Piping.Primitives;
namespace Ringtoets.Piping.IO.Importers
{
@@ -29,9 +33,65 @@
///
public class PipingStochasticSoilModelTransformer : IStochasticSoilModelTransformer
{
+ private readonly Dictionary soilProfiles = new Dictionary();
+
public PipingStochasticSoilModel Transform(StochasticSoilModel stochasticSoilModel)
{
- return null;
+ if (stochasticSoilModel.FailureMechanismType != FailureMechanismType.Piping)
+ {
+ return null;
+ }
+
+ IEnumerable pipingStochasticSoilProfiles = TransformStochasticSoilProfiles(stochasticSoilModel.StochasticSoilProfiles);
+
+ var pipingModel = new PipingStochasticSoilModel(stochasticSoilModel.Name);
+ pipingModel.Geometry.AddRange(stochasticSoilModel.Geometry);
+ pipingModel.StochasticSoilProfiles.AddRange(pipingStochasticSoilProfiles);
+
+ return pipingModel;
}
+
+ ///
+ /// Transforms all generic into .
+ ///
+ /// The stochastic soil profiles to use in the transformation.
+ /// The transformed piping stochastic soil profiles.
+ /// Thrown when transformation would
+ /// not result in a valid transformed instance.
+ private IEnumerable TransformStochasticSoilProfiles(IEnumerable stochasticSoilProfiles)
+ {
+ foreach (StochasticSoilProfile stochasticSoilProfile in stochasticSoilProfiles)
+ {
+ PipingSoilProfile pipingSoilProfile = GetTransformedPipingSoilProfile(stochasticSoilProfile.SoilProfile);
+
+ if (pipingSoilProfile != null)
+ {
+ yield return PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, pipingSoilProfile);
+ }
+ }
+ }
+
+ ///
+ /// Transforms all generic into .
+ ///
+ /// The soil profile to use in the transformation.
+ /// The transformed piping soil profile, or null when
+ /// is not of a type that can be transformed to .
+ /// Thrown when transformation would
+ /// not result in a valid transformed instance.
+ private PipingSoilProfile GetTransformedPipingSoilProfile(ISoilProfile soilProfile)
+ {
+ PipingSoilProfile pipingStochasticSoilProfile;
+ if (soilProfiles.ContainsKey(soilProfile))
+ {
+ pipingStochasticSoilProfile = soilProfiles[soilProfile];
+ }
+ else
+ {
+ pipingStochasticSoilProfile = PipingSoilProfileTransformer.Transform(soilProfile);
+ soilProfiles.Add(soilProfile, pipingStochasticSoilProfile);
+ }
+ return pipingStochasticSoilProfile;
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilProfileTransformer.cs
===================================================================
diff -u
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilProfileTransformer.cs (revision 0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingStochasticSoilProfileTransformer.cs (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -0,0 +1,58 @@
+// 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 Ringtoets.Common.IO.Exceptions;
+using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Piping.Data.SoilProfile;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.IO.Importers
+{
+ ///
+ /// Transforms generic into .
+ ///
+ public static class PipingStochasticSoilProfileTransformer
+ {
+ ///
+ /// Transforms the generic into .
+ ///
+ /// The stochastic soil profile to use in the transformation.
+ /// The transformed piping soil profile.
+ /// A new based on the given data.
+ /// Thrown when any of the input parameters is null.
+ /// Thrown when transformation would not result
+ /// in a valid transformed instance.
+ public static PipingStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile, PipingSoilProfile soilProfile)
+ {
+ if (stochasticSoilProfile == null)
+ {
+ throw new ArgumentNullException(nameof(stochasticSoilProfile));
+ }
+ if (soilProfile == null)
+ {
+ throw new ArgumentNullException(nameof(soilProfile));
+ }
+
+ return new PipingStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj
===================================================================
diff -u -r94ce658a9488c346f114446f0e37dabab7acaa38 -r15ba57d868f00dfd3d6b52ac2e03a202d47d0303
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 94ce658a9488c346f114446f0e37dabab7acaa38)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -50,7 +50,9 @@
+
+
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSoilProfileTransformerTest.cs
===================================================================
diff -u
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSoilProfileTransformerTest.cs (revision 0)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSoilProfileTransformerTest.cs (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -0,0 +1,62 @@
+// 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 NUnit.Framework;
+using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Piping.IO.Importers;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.IO.Test.Importers
+{
+ [TestFixture]
+ public class PipingSoilProfileTransformerTest
+ {
+ [Test]
+ public void Transform_SoilProfileNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => PipingSoilProfileTransformer.Transform(null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("soilProfile", exception.ParamName);
+ }
+
+ [Test]
+ public void Transform_InvalidSoilProfile_ReturnsNull()
+ {
+ // Setup
+ var invalidType = new TestSoilProfile();
+
+ // Call
+ PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(invalidType);
+
+ // Assert
+ Assert.IsNull(transformed);
+ }
+
+ private class TestSoilProfile : ISoilProfile
+ {
+ public string Name { get; }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilModelTransformerTest.cs
===================================================================
diff -u -rb78437864e9677d66dc309d766b0e706c8af0c1f -r15ba57d868f00dfd3d6b52ac2e03a202d47d0303
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilModelTransformerTest.cs (.../PipingStochasticSoilModelTransformerTest.cs) (revision b78437864e9677d66dc309d766b0e706c8af0c1f)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilModelTransformerTest.cs (.../PipingStochasticSoilModelTransformerTest.cs) (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -19,8 +19,12 @@
// 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 NUnit.Framework;
using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Common.IO.SoilProfile.Schema;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.IO.Importers;
@@ -38,5 +42,27 @@
// Assert
Assert.IsInstanceOf>(transformer);
}
+
+ [Test]
+ [TestCaseSource(nameof(InvalidFailureMechanismTypes))]
+ public void Transform_InvalidFailureMechanismType_ReturnsNull(FailureMechanismType failureMechanismType)
+ {
+ // Setup
+ var transformer = new PipingStochasticSoilModelTransformer();
+ var soilModel = new StochasticSoilModel("some name", failureMechanismType);
+
+ // Call
+ PipingStochasticSoilModel transformed = transformer.Transform(soilModel);
+
+ // Assert
+ Assert.IsNull(transformed);
+ }
+
+ private static IEnumerable InvalidFailureMechanismTypes()
+ {
+ return Enum.GetValues(typeof(FailureMechanismType))
+ .Cast()
+ .Where(t => t != FailureMechanismType.Piping);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilProfileTransformerTest.cs
===================================================================
diff -u
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilProfileTransformerTest.cs (revision 0)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingStochasticSoilProfileTransformerTest.cs (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -0,0 +1,90 @@
+// 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 NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Piping.Data.SoilProfile;
+using Ringtoets.Piping.Data.TestUtil;
+using Ringtoets.Piping.IO.Importers;
+using Ringtoets.Piping.Primitives;
+
+namespace Ringtoets.Piping.IO.Test.Importers
+{
+ [TestFixture]
+ public class PipingStochasticSoilProfileTransformerTest
+ {
+ [Test]
+ public void Transform_StochasticSoilProfileNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
+
+ // Call
+ TestDelegate test = () => PipingStochasticSoilProfileTransformer.Transform(null, soilProfile);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("stochasticSoilProfile", exception.ParamName);
+ }
+
+ [Test]
+ public void Transform_PipingSoilProfileNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var soilProfile = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var stochasticSoilProfile = new StochasticSoilProfile(0, soilProfile);
+
+ // Call
+ TestDelegate test = () => PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("soilProfile", exception.ParamName);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Transform_ValidStochasticSoilProfile_ReturnsExpectedPipingStochasticSoilProfile()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var soilProfile = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ PipingSoilProfile pipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
+
+ var stochasticSoilProfile = new StochasticSoilProfile(new Random(9).NextDouble(), soilProfile);
+
+ // Call
+ PipingStochasticSoilProfile pipingStochasticSoilProfile = PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, pipingSoilProfile);
+
+ // Assert
+ Assert.AreEqual(stochasticSoilProfile.Probability, pipingStochasticSoilProfile.Probability);
+ Assert.AreSame(pipingSoilProfile, pipingStochasticSoilProfile.SoilProfile);
+ mockRepository.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj
===================================================================
diff -u -r94ce658a9488c346f114446f0e37dabab7acaa38 -r15ba57d868f00dfd3d6b52ac2e03a202d47d0303
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 94ce658a9488c346f114446f0e37dabab7acaa38)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 15ba57d868f00dfd3d6b52ac2e03a202d47d0303)
@@ -78,7 +78,9 @@
+
+