Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs
===================================================================
diff -u -r90c7a8c93ed280d5881307f04b103ed23be3a2ba -r287331eb74e6e8044ea74ab4acfab6164109bcec
--- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 90c7a8c93ed280d5881307f04b103ed23be3a2ba)
+++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 287331eb74e6e8044ea74ab4acfab6164109bcec)
@@ -70,11 +70,11 @@
double startDistance = 0;
foreach (FailureMechanismSection section in sections)
{
- double endDistance = startDistance + section.Length;
- exportableSections.Add(new ExportableFailureMechanismSection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSection_IdPrefix),
- section.Points, startDistance, endDistance));
+ ExportableFailureMechanismSection exportableFailureMechanismSection =
+ ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, startDistance);
+ exportableSections.Add(exportableFailureMechanismSection);
- startDistance = endDistance;
+ startDistance = exportableFailureMechanismSection.EndDistance;
}
var exportableCollection = new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix),
Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs
===================================================================
diff -u
--- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (revision 0)
+++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (revision 287331eb74e6e8044ea74ab4acfab6164109bcec)
@@ -0,0 +1,78 @@
+// Copyright (C) Stichting Deltares 2022. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer 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 Riskeer.AssemblyTool.IO.Model;
+using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Integration.IO.Helpers;
+using Riskeer.Integration.IO.Properties;
+
+namespace Riskeer.Integration.IO.Factories
+{
+ ///
+ /// Factory for creating .
+ ///
+ public static class ExportableFailureMechanismSectionFactory
+ {
+ ///
+ /// Creates an based on its input arguments.
+ ///
+ /// The generator to generate ids for the exportable components.
+ /// The to keep track of the created items.
+ /// The to create the
+ /// with.
+ /// The start distance of the failure mechanism section between the section
+ /// and the start of the reference line in meters.
+ /// An .
+ /// Thrown when ,
+ /// or is null.
+ public static ExportableFailureMechanismSection CreateExportableFailureMechanismSection(
+ IdentifierGenerator idGenerator, ExportableModelRegistry registry, FailureMechanismSection section,
+ double startDistance)
+ {
+ if (idGenerator == null)
+ {
+ throw new ArgumentNullException(nameof(idGenerator));
+ }
+
+ if (registry == null)
+ {
+ throw new ArgumentNullException(nameof(registry));
+ }
+
+ if (section == null)
+ {
+ throw new ArgumentNullException(nameof(section));
+ }
+
+ if (registry.Contains(section))
+ {
+ return registry.Get(section);
+ }
+
+ double endDistance = startDistance + section.Length;
+ var exportableSection = new ExportableFailureMechanismSection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSection_IdPrefix),
+ section.Points, startDistance, endDistance);
+ registry.Register(section, exportableSection);
+ return exportableSection;
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs
===================================================================
diff -u
--- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (revision 0)
+++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (revision 287331eb74e6e8044ea74ab4acfab6164109bcec)
@@ -0,0 +1,128 @@
+// Copyright (C) Stichting Deltares 2022. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer 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 Riskeer.AssemblyTool.IO.Model;
+using Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Integration.IO.Factories;
+using Riskeer.Integration.IO.Helpers;
+
+namespace Riskeer.Integration.IO.Test.Factories
+{
+ [TestFixture]
+ public class ExportableFailureMechanismSectionFactoryTest
+ {
+ [Test]
+ public void CreateExportableFailureMechanismSection_IdGeneratorNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ // Call
+ void Call() => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(
+ null, new ExportableModelRegistry(), FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("idGenerator", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateExportableFailureMechanism_RegistryNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ // Call
+ void Call() => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(
+ new IdentifierGenerator(), null, FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("registry", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateExportableFailureMechanismSection_SectionsNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var random = new Random(21);
+
+ // Call
+ void Call() => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(
+ new IdentifierGenerator(), new ExportableModelRegistry(), null, random.NextDouble());
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("section", exception.ParamName);
+ }
+
+ [Test]
+ public void CreateExportableFailureMechanismSection_WithValidArguments_ReturnsExpectedExportableFailureMechanismSection()
+ {
+ // Setup
+ var random = new Random(21);
+ double startDistance = random.NextDouble();
+
+ var idGenerator = new IdentifierGenerator();
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+
+ var registry = new ExportableModelRegistry();
+
+ // Call
+ ExportableFailureMechanismSection exportableSection =
+ ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, startDistance);
+
+ // Assert
+ Assert.AreEqual("Bv.0", exportableSection.Id);
+ Assert.AreSame(section.Points, exportableSection.Geometry);
+ Assert.AreEqual(startDistance, exportableSection.StartDistance);
+
+ double expectedEndDistance = startDistance + section.Length;
+ Assert.AreEqual(expectedEndDistance, exportableSection.EndDistance);
+ }
+
+ [Test]
+ public void CreateExportableFailureMechanismSection_SectionAlreadyRegistered_ReturnsRegisteredExportableModel()
+ {
+ // Setup
+ var random = new Random(21);
+ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
+
+ var idGenerator = new IdentifierGenerator();
+ var registry = new ExportableModelRegistry();
+ ExportableFailureMechanismSection exportableModel1 =
+ ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, random.NextDouble());
+
+ // Precondition
+ Assert.True(registry.Contains(section));
+
+ // Call
+ ExportableFailureMechanismSection exportableModel2 =
+ ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, random.NextDouble());
+
+ // Assert
+ Assert.AreSame(exportableModel1, exportableModel2);
+ }
+ }
+}
\ No newline at end of file