Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs =================================================================== diff -u -r2cd36eedaac4fa2986b41823527527a279e4dbe5 -r3f16d047b4c6d2a626357315f8ae38d678be17bb --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 3f16d047b4c6d2a626357315f8ae38d678be17bb) @@ -21,8 +21,11 @@ using System; using System.Collections.Generic; +using System.Linq; 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; @@ -72,8 +75,53 @@ startDistance = exportableFailureMechanismSection.EndDistance; } - return new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), - exportableSections); + return new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), exportableSections); } + + /// + /// Creates an based on a collection of + /// . + /// + /// The generator to generate ids for the exportable components. + /// The to keep track of the created items. + /// The to create the + /// with. + /// The collection of to create the + /// with. + /// An . + /// Thrown when any parameter is null. + public static ExportableFailureMechanismSectionCollection CreateExportableFailureMechanismSectionCollection( + IdentifierGenerator idGenerator, ExportableModelRegistry registry, + ReferenceLine referenceLine, IEnumerable assemblyResults) + { + 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 (assemblyResults == null) + { + throw new ArgumentNullException(nameof(assemblyResults)); + } + + IEnumerable exportableSections = + assemblyResults.Select(assemblyResult => ExportableFailureMechanismSectionFactory.CreateExportableCombinedFailureMechanismSection( + idGenerator, registry, referenceLine, assemblyResult)) + .ToArray(); + + var exportableCollection = new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), + exportableSections); + return exportableCollection; + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs =================================================================== diff -u -rda0356f2b46faed6744d985f39372ab5ffa0ac2b -r3f16d047b4c6d2a626357315f8ae38d678be17bb --- Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs (.../CombinedFailureMechanismSectionAssemblyResultTestFactory.cs) (revision da0356f2b46faed6744d985f39372ab5ffa0ac2b) +++ Riskeer/Integration/test/Riskeer.Integration.Data.TestUtil/CombinedFailureMechanismSectionAssemblyResultTestFactory.cs (.../CombinedFailureMechanismSectionAssemblyResultTestFactory.cs) (revision 3f16d047b4c6d2a626357315f8ae38d678be17bb) @@ -38,8 +38,20 @@ public static CombinedFailureMechanismSectionAssemblyResult Create() { var random = new Random(21); - double sectionStart = random.NextDouble(); - double sectionEnd = random.NextDouble(); + return Create(random.NextDouble(), random.NextDouble()); + } + + /// + /// Creates an instance of . + /// + /// The start of the section from the beginning of the reference line + /// in meters. + /// The end of the section from the beginning of the reference line + /// in meters. + /// A configured . + public static CombinedFailureMechanismSectionAssemblyResult Create(double sectionStart, double sectionEnd) + { + var random = new Random(21); var totalResult = random.NextEnumValue(); var commonSectionAssemblyMethod = random.NextEnumValue(); var failureMechanismResultsAssemblyMethod = random.NextEnumValue(); @@ -49,5 +61,48 @@ failureMechanismResultsAssemblyMethod, combinedSectionResultAssemblyMethod, new CombinedFailureMechanismSectionAssemblyResult.ConstructionProperties()); } + + /// + /// Creates an instance of . + /// + /// The seed to randomize the result. + /// Indicator whether the result has assembly group results. + /// A configured . + public static CombinedFailureMechanismSectionAssemblyResult Create(int seed, bool hasAssemblyGroupResults) + { + var random = new Random(seed); + return new CombinedFailureMechanismSectionAssemblyResult(random.NextDouble(), random.NextDouble(), random.NextEnumValue(), + random.NextEnumValue(), random.NextEnumValue(), random.NextEnumValue(), + new CombinedFailureMechanismSectionAssemblyResult.ConstructionProperties + { + Piping = GetAssemblyGroup(random, hasAssemblyGroupResults), + GrassCoverErosionInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), + MacroStabilityInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), + Microstability = GetAssemblyGroup(random, hasAssemblyGroupResults), + StabilityStoneCover = GetAssemblyGroup(random, hasAssemblyGroupResults), + WaveImpactAsphaltCover = GetAssemblyGroup(random, hasAssemblyGroupResults), + WaterPressureAsphaltCover = GetAssemblyGroup(random, hasAssemblyGroupResults), + GrassCoverErosionOutwards = GetAssemblyGroup(random, hasAssemblyGroupResults), + GrassCoverSlipOffOutwards = GetAssemblyGroup(random, hasAssemblyGroupResults), + GrassCoverSlipOffInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), + HeightStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), + ClosingStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), + PipingStructure = GetAssemblyGroup(random, hasAssemblyGroupResults), + StabilityPointStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), + DuneErosion = GetAssemblyGroup(random, hasAssemblyGroupResults), + SpecificFailureMechanisms = new[] + { + GetAssemblyGroup(random, hasAssemblyGroupResults), + GetAssemblyGroup(random, hasAssemblyGroupResults) + } + }); + } + + private static FailureMechanismSectionAssemblyGroup? GetAssemblyGroup(Random random, bool hasAssemblyGroupResults) + { + return hasAssemblyGroupResults + ? random.NextEnumValue() + : (FailureMechanismSectionAssemblyGroup?) null; + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs =================================================================== diff -u -r67b3d776bcd2a24360d3187557b5aaa6ba74f7c9 -r3f16d047b4c6d2a626357315f8ae38d678be17bb --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs (.../ExportableCombinedSectionAssemblyFactoryTest.cs) (revision 67b3d776bcd2a24360d3187557b5aaa6ba74f7c9) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs (.../ExportableCombinedSectionAssemblyFactoryTest.cs) (revision 3f16d047b4c6d2a626357315f8ae38d678be17bb) @@ -32,6 +32,7 @@ using Riskeer.Common.Data.FailureMechanism; using Riskeer.Integration.Data; using Riskeer.Integration.Data.Assembly; +using Riskeer.Integration.Data.TestUtil; using Riskeer.Integration.IO.Exceptions; using Riskeer.Integration.IO.Factories; using Riskeer.Integration.Util; @@ -117,8 +118,8 @@ CombinedFailureMechanismSectionAssemblyResult[] assemblyResults = { - CreateCombinedFailureMechanismSectionAssemblyResult(21, hasAssemblyGroupResults), - CreateCombinedFailureMechanismSectionAssemblyResult(22, hasAssemblyGroupResults) + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(21, hasAssemblyGroupResults), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(22, hasAssemblyGroupResults) }; // Call @@ -131,44 +132,6 @@ assessmentSection.ReferenceLine, hasAssemblyGroupResults); } - private static CombinedFailureMechanismSectionAssemblyResult CreateCombinedFailureMechanismSectionAssemblyResult(int seed, bool hasAssemblyGroupResults) - { - var random = new Random(seed); - - return new CombinedFailureMechanismSectionAssemblyResult(random.NextDouble(), random.NextDouble(), random.NextEnumValue(), - random.NextEnumValue(), random.NextEnumValue(), random.NextEnumValue(), - new CombinedFailureMechanismSectionAssemblyResult.ConstructionProperties - { - Piping = GetAssemblyGroup(random, hasAssemblyGroupResults), - GrassCoverErosionInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), - MacroStabilityInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), - Microstability = GetAssemblyGroup(random, hasAssemblyGroupResults), - StabilityStoneCover = GetAssemblyGroup(random, hasAssemblyGroupResults), - WaveImpactAsphaltCover = GetAssemblyGroup(random, hasAssemblyGroupResults), - WaterPressureAsphaltCover = GetAssemblyGroup(random, hasAssemblyGroupResults), - GrassCoverErosionOutwards = GetAssemblyGroup(random, hasAssemblyGroupResults), - GrassCoverSlipOffOutwards = GetAssemblyGroup(random, hasAssemblyGroupResults), - GrassCoverSlipOffInwards = GetAssemblyGroup(random, hasAssemblyGroupResults), - HeightStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), - ClosingStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), - PipingStructure = GetAssemblyGroup(random, hasAssemblyGroupResults), - StabilityPointStructures = GetAssemblyGroup(random, hasAssemblyGroupResults), - DuneErosion = GetAssemblyGroup(random, hasAssemblyGroupResults), - SpecificFailureMechanisms = new[] - { - GetAssemblyGroup(random, hasAssemblyGroupResults), - GetAssemblyGroup(random, hasAssemblyGroupResults) - } - }); - } - - private static FailureMechanismSectionAssemblyGroup? GetAssemblyGroup(Random random, bool hasAssemblyGroupResults) - { - return hasAssemblyGroupResults - ? random.NextEnumValue() - : (FailureMechanismSectionAssemblyGroup?) null; - } - private static void AssertCombinedFailureMechanismSectionAssemblyResults(IEnumerable assemblyResults, IEnumerable exportableCombinedSectionAssemblies, ReferenceLine referenceLine, bool hasAssemblyGroupResults) Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs =================================================================== diff -u -r2cd36eedaac4fa2986b41823527527a279e4dbe5 -r3f16d047b4c6d2a626357315f8ae38d678be17bb --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 3f16d047b4c6d2a626357315f8ae38d678be17bb) @@ -20,14 +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 { @@ -102,25 +107,134 @@ // Assert Assert.AreEqual("Vi.0", collection.Id); - Assert.AreEqual(sections.Length, collection.Sections.Count()); + IEnumerable exportableFailureMechanismSections = collection.Sections; + Assert.AreEqual(sections.Length, exportableFailureMechanismSections.Count()); - ExportableFailureMechanismSection firstExportableSection = collection.Sections.ElementAt(0); + ExportableFailureMechanismSection firstExportableSection = exportableFailureMechanismSections.ElementAt(0); Assert.AreSame(sections[0].Points, firstExportableSection.Geometry); Assert.AreEqual("Bv.0", firstExportableSection.Id); Assert.AreEqual(0, firstExportableSection.StartDistance); Assert.AreEqual(10, firstExportableSection.EndDistance); - ExportableFailureMechanismSection secondExportableSection = collection.Sections.ElementAt(1); + ExportableFailureMechanismSection secondExportableSection = exportableFailureMechanismSections.ElementAt(1); Assert.AreSame(sections[1].Points, secondExportableSection.Geometry); Assert.AreEqual("Bv.1", secondExportableSection.Id); Assert.AreEqual(10, secondExportableSection.StartDistance); Assert.AreEqual(20, secondExportableSection.EndDistance); - ExportableFailureMechanismSection thirdExportableSection = collection.Sections.ElementAt(2); + ExportableFailureMechanismSection thirdExportableSection = exportableFailureMechanismSections.ElementAt(2); Assert.AreEqual("Bv.2", thirdExportableSection.Id); Assert.AreSame(sections[2].Points, thirdExportableSection.Geometry); Assert.AreEqual(20, thirdExportableSection.StartDistance); Assert.AreEqual(40, thirdExportableSection.EndDistance); } + + [Test] + public void CreateExportableFailureMechanismSectionCollectionWithCombinedAssemblyResults_IdGeneratorNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + null, new ExportableModelRegistry(), ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), + Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("idGenerator", exception.ParamName); + } + + [Test] + public void CreateExportableFailureMechanismSectionCollectionWithCombinedAssemblyResults_RegistryNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + new IdentifierGenerator(), null, ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), + Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("registry", exception.ParamName); + } + + [Test] + public void CreateExportableFailureMechanismSectionCollectionWithCombinedAssemblyResults_ReferenceLineNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + new IdentifierGenerator(), new ExportableModelRegistry(), null, + Enumerable.Empty()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("referenceLine", exception.ParamName); + } + + [Test] + public void CreateExportableFailureMechanismSectionCollectionWithCombinedAssemblyResults_AssemblyResultsNull_ThrowsArgumentNullException() + { + // Call + void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + new IdentifierGenerator(), new ExportableModelRegistry(), ReferenceLineTestFactory.CreateReferenceLineWithGeometry(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assemblyResults", exception.ParamName); + } + + [Test] + public void CreateExportableFailureMechanismSectionCollectionWithCombinedAssemblyResults_WithValidArguments_ReturnsExpectedExportableFailureMechanismSectionCollection() + { + // Setup + var idGenerator = new IdentifierGenerator(); + var registry = new ExportableModelRegistry(); + + CombinedFailureMechanismSectionAssemblyResult[] assemblyResults = + { + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(0, 5), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(5, 10), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(10, 15) + }; + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(0, 0), + new Point2D(10, 10) + }); + + // Call + ExportableFailureMechanismSectionCollection collection = + ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + idGenerator, registry, referenceLine, assemblyResults); + + // Assert + Assert.AreEqual("Vi.0", collection.Id); + Assert.AreEqual(assemblyResults.Length, collection.Sections.Count()); + CollectionAssert.AllItemsAreInstancesOfType(collection.Sections, typeof(ExportableCombinedFailureMechanismSection)); + + IEnumerable exportableSections = + collection.Sections.Cast(); + + for (var i = 0; i < assemblyResults.Length; i++) + { + AssertExportableCombinedFailureMechanismSection(i, referenceLine, assemblyResults[i], exportableSections.ElementAt(i)); + } + } + + private static void AssertExportableCombinedFailureMechanismSection(int index, ReferenceLine referenceLine, + CombinedFailureMechanismSectionAssemblyResult assemblyResult, + ExportableCombinedFailureMechanismSection exportableCombinedFailureMechanismSection) + { + IEnumerable expectedGeometry = FailureMechanismSectionHelper.GetFailureMechanismSectionGeometry( + referenceLine, + assemblyResult.SectionStart, + assemblyResult.SectionEnd).ToArray(); + CollectionAssert.IsNotEmpty(expectedGeometry); + + Assert.AreEqual($"Bv.{index}", exportableCombinedFailureMechanismSection.Id); + Assert.AreEqual(assemblyResult.SectionStart, exportableCombinedFailureMechanismSection.StartDistance); + Assert.AreEqual(assemblyResult.SectionEnd, exportableCombinedFailureMechanismSection.EndDistance); + CollectionAssert.AreEqual(expectedGeometry, exportableCombinedFailureMechanismSection.Geometry); + Assert.AreEqual(ExportableAssemblyMethodFactory.Create(assemblyResult.CommonSectionAssemblyMethod), exportableCombinedFailureMechanismSection.AssemblyMethod); + } } } \ No newline at end of file