Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -rda0356f2b46faed6744d985f39372ab5ffa0ac2b --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (.../ExportableFailureMechanismSectionFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (.../ExportableFailureMechanismSectionFactory.cs) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -21,9 +21,12 @@ using System; using Riskeer.AssemblyTool.IO.Model; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Integration.Data.Assembly; using Riskeer.Integration.IO.Helpers; using Riskeer.Integration.IO.Properties; +using Riskeer.Integration.Util; namespace Riskeer.Integration.IO.Factories { @@ -74,5 +77,53 @@ registry.Register(section, exportableSection); return exportableSection; } + + /// + /// Creates a based on its input arguments. + /// + /// The generator to generate ids for the exportable components. + /// The to keep track of the created items. + /// The the section results belong to. + /// The to create the section with. + /// An . + /// Thrown when any parameter is null. + public static ExportableCombinedFailureMechanismSection CreateExportableCombinedFailureMechanismSection( + IdentifierGenerator idGenerator, ExportableModelRegistry registry, + ReferenceLine referenceLine, CombinedFailureMechanismSectionAssemblyResult assemblyResult) + { + if (idGenerator == null) + { + throw new ArgumentNullException(nameof(idGenerator)); + } + + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + if (referenceLine == null) + { + throw new ArgumentNullException(nameof(referenceLine)); + } + + if (assemblyResult == null) + { + throw new ArgumentNullException(nameof(assemblyResult)); + } + + if (registry.Contains(assemblyResult)) + { + return registry.Get(assemblyResult); + } + + var exportableSection = new ExportableCombinedFailureMechanismSection( + idGenerator.GetNewId(Resources.ExportableFailureMechanismSection_IdPrefix), + FailureMechanismSectionHelper.GetFailureMechanismSectionGeometry(referenceLine, assemblyResult.SectionStart, assemblyResult.SectionEnd), + assemblyResult.SectionStart, assemblyResult.SectionEnd, + ExportableAssemblyMethodFactory.Create(assemblyResult.CommonSectionAssemblyMethod)); + + registry.Register(assemblyResult, exportableSection); + return exportableSection; + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -0,0 +1,53 @@ +// 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 Core.Common.TestUtil; +using Riskeer.AssemblyTool.Data; +using Riskeer.Integration.Data.Assembly; + +namespace Riskeer.Integration.Data.TestUtil +{ + /// + /// Creates for test purposes. + /// + public static class CombinedFailureMechanismSectionAssemblyResultTestFactory + { + /// + /// Creates a default instance of . + /// + /// A . + public static CombinedFailureMechanismSectionAssemblyResult Create() + { + var random = new Random(21); + double sectionStart = random.NextDouble(); + double sectionEnd = random.NextDouble(); + var totalResult = random.NextEnumValue(); + var commonSectionAssemblyMethod = random.NextEnumValue(); + var failureMechanismResultsAssemblyMethod = random.NextEnumValue(); + var combinedSectionResultAssemblyMethod = random.NextEnumValue(); + + return new CombinedFailureMechanismSectionAssemblyResult(sectionStart, sectionEnd, totalResult, commonSectionAssemblyMethod, + failureMechanismResultsAssemblyMethod, combinedSectionResultAssemblyMethod, + new CombinedFailureMechanismSectionAssemblyResult.ConstructionProperties()); + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/Riskeer.Integration.Data.TestUtil.csproj =================================================================== diff -u -ra4dc2c1f95dda01617154dadd930c624d22d3f73 -rda0356f2b46faed6744d985f39372ab5ffa0ac2b --- Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/Riskeer.Integration.Data.TestUtil.csproj (.../Riskeer.Integration.Data.TestUtil.csproj) (revision a4dc2c1f95dda01617154dadd930c624d22d3f73) +++ Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/Riskeer.Integration.Data.TestUtil.csproj (.../Riskeer.Integration.Data.TestUtil.csproj) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -10,5 +10,6 @@ + Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -rda0356f2b46faed6744d985f39372ab5ffa0ac2b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (.../ExportableFailureMechanismSectionFactoryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (.../ExportableFailureMechanismSectionFactoryTest.cs) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -20,12 +20,19 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Geometry; using NUnit.Framework; using Riskeer.AssemblyTool.IO.Model; +using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; +using Riskeer.Integration.Data.Assembly; +using Riskeer.Integration.Data.TestUtil; using Riskeer.Integration.IO.Factories; using Riskeer.Integration.IO.Helpers; +using Riskeer.Integration.Util; namespace Riskeer.Integration.IO.Test.Factories { @@ -63,7 +70,7 @@ } [Test] - public void CreateExportableFailureMechanismSection_SectionsNull_ThrowsArgumentNullException() + public void CreateExportableFailureMechanismSection_SectionNull_ThrowsArgumentNullException() { // Setup var random = new Random(21); @@ -103,26 +110,131 @@ } [Test] - public void CreateExportableFailureMechanismSection_SectionAlreadyRegistered_ReturnsRegisteredExportableModel() + public void CreateExportableFailureMechanismSection_SectionAlreadyRegistered_ReturnsRegisteredExportableFailureMechanismSection() { // Setup var random = new Random(21); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var idGenerator = new IdentifierGenerator(); var registry = new ExportableModelRegistry(); - ExportableFailureMechanismSection exportableModel1 = + ExportableFailureMechanismSection exportableSection1 = ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, random.NextDouble()); // Precondition Assert.True(registry.Contains(section)); // Call - ExportableFailureMechanismSection exportableModel2 = + ExportableFailureMechanismSection exportableSection2 = ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, random.NextDouble()); // Assert - Assert.AreSame(exportableModel1, exportableModel2); + Assert.AreSame(exportableSection1, exportableSection2); } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_IdGeneratorNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + null, new ExportableModelRegistry(), ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("idGenerator", exception.ParamName); + } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_RegistryNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + new IdentifierGenerator(), null, ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_ReferenceLineNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + new IdentifierGenerator(), new ExportableModelRegistry(), null, + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("referenceLine", exception.ParamName); + } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_AssemblyResultNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + new IdentifierGenerator(), new ExportableModelRegistry(), ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assemblyResult", exception.ParamName); + } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_WithValidArguments_ReturnsExpectedExportableCombinedFailureMechanismSection() + { + // Setup + var idGenerator = new IdentifierGenerator(); + ReferenceLine referenceLine = ReferenceLineTestFactory.CreateReferenceLineWithGeometry(); + CombinedFailureMechanismSectionAssemblyResult assemblyResult = CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(); + + var registry = new ExportableModelRegistry(); + + // Call + ExportableCombinedFailureMechanismSection exportableSection = + ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection(idGenerator, registry, + referenceLine, assemblyResult); + + // Assert + Assert.AreEqual("Bv.0", exportableSection.Id); + + IEnumerable expectedGeometry = FailureMechanismSectionHelper.GetFailureMechanismSectionGeometry( + referenceLine, + exportableSection.StartDistance, + exportableSection.EndDistance).ToArray(); + CollectionAssert.IsNotEmpty(expectedGeometry); + + Assert.AreEqual(assemblyResult.SectionStart, exportableSection.StartDistance); + Assert.AreEqual(assemblyResult.SectionEnd, exportableSection.EndDistance); + CollectionAssert.AreEqual(expectedGeometry, exportableSection.Geometry); + Assert.AreEqual(ExportableAssemblyMethodFactory.Create(assemblyResult.CommonSectionAssemblyMethod), exportableSection.AssemblyMethod); + } + + [Test] + public void CreateExportableCombinedFailureMechanismSection_AssemblyResultAlreadyRegistered_ReturnsRegisteredExportableCombinedFailureMechanismSection() + { + // Setup + CombinedFailureMechanismSectionAssemblyResult assemblyResult = CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(); + + var idGenerator = new IdentifierGenerator(); + var registry = new ExportableModelRegistry(); + ExportableCombinedFailureMechanismSection exportableSection1 = + ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + idGenerator, registry, ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), assemblyResult); + + // Precondition + Assert.True(registry.Contains(assemblyResult)); + + // Call + ExportableCombinedFailureMechanismSection exportableSection2 = + ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + idGenerator, registry, ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), assemblyResult); + + // Assert + Assert.AreSame(exportableSection1, exportableSection2); + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs =================================================================== diff -u -r2cd36eedaac4fa2986b41823527527a279e4dbe5 -rda0356f2b46faed6744d985f39372ab5ffa0ac2b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -20,14 +20,13 @@ // All rights reserved. using System; -using Core.Common.TestUtil; using NUnit.Framework; -using Riskeer.AssemblyTool.Data; using Riskeer.AssemblyTool.IO.Model; using Riskeer.AssemblyTool.IO.TestUtil; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; using Riskeer.Integration.Data.Assembly; +using Riskeer.Integration.Data.TestUtil; using Riskeer.Integration.IO.Helpers; namespace Riskeer.Integration.IO.Test.Helpers @@ -257,17 +256,7 @@ protected override CombinedFailureMechanismSectionAssemblyResult CreateDataModel() { - var random = new Random(21); - double sectionStart = random.NextDouble(); - double sectionEnd = random.NextDouble(); - var totalResult = random.NextEnumValue(); - var commonSectionAssemblyMethod = random.NextEnumValue(); - var failureMechanismResultsAssemblyMethod = random.NextEnumValue(); - var combinedSectionResultAssemblyMethod = random.NextEnumValue(); - - return new CombinedFailureMechanismSectionAssemblyResult(sectionStart, sectionEnd, totalResult, commonSectionAssemblyMethod, - failureMechanismResultsAssemblyMethod, combinedSectionResultAssemblyMethod, - new CombinedFailureMechanismSectionAssemblyResult.ConstructionProperties()); + return CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(); } protected override ExportableCombinedFailureMechanismSection CreateExportableModel() Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj =================================================================== diff -u -rbea3287c5025ee31665b6161bc707eceb8e78a6d -rda0356f2b46faed6744d985f39372ab5ffa0ac2b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj (.../Riskeer.Integration.IO.Test.csproj) (revision bea3287c5025ee31665b6161bc707eceb8e78a6d) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj (.../Riskeer.Integration.IO.Test.csproj) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) @@ -45,6 +45,7 @@ +