Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableCombinedSectionAssemblyFactory.cs =================================================================== diff -u -rb25d71c274bf802dc8dd9fce8c69fd8263f7c054 -r08a22799875699c55ccdf224a272bdc93d2b0ed1 --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableCombinedSectionAssemblyFactory.cs (.../ExportableCombinedSectionAssemblyFactory.cs) (revision b25d71c274bf802dc8dd9fce8c69fd8263f7c054) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableCombinedSectionAssemblyFactory.cs (.../ExportableCombinedSectionAssemblyFactory.cs) (revision 08a22799875699c55ccdf224a272bdc93d2b0ed1) @@ -22,10 +22,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base.Geometry; using Riskeer.AssemblyTool.Data; using Riskeer.AssemblyTool.IO.Model; -using Riskeer.AssemblyTool.IO.Model.Enums; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Integration.Data; using Riskeer.Integration.Data.Assembly; @@ -87,12 +85,12 @@ throw new AssemblyFactoryException("The assembly result is invalid and cannot be created."); } - ExportableCombinedFailureMechanismSection exportableSection = registry.Get(assemblyResult); + ExportableCombinedFailureMechanismSection exportableCombinedSection = registry.Get(assemblyResult); var exportableSectionResult = new ExportableCombinedSectionAssembly( - idGenerator.GetNewId(Resources.ExportableCombinedSectionAssembly_IdPrefix), exportableSection, assemblyResult.TotalResult, + idGenerator.GetNewId(Resources.ExportableCombinedSectionAssembly_IdPrefix), exportableCombinedSection, assemblyResult.TotalResult, ExportableAssemblyMethodConverter.ConvertTo(assemblyResult.CombinedSectionResultAssemblyMethod), - CreateFailureMechanismCombinedSectionAssemblyResults(assemblyResult, assessmentSection)); + CreateFailureMechanismCombinedSectionAssemblyResults(registry, exportableCombinedSection, assemblyResult, assessmentSection)); sectionResults.Add(exportableSectionResult); } @@ -101,31 +99,33 @@ } private static IEnumerable CreateFailureMechanismCombinedSectionAssemblyResults( + ExportableModelRegistry registry, ExportableCombinedFailureMechanismSection combinedFailureMechanismSection, CombinedFailureMechanismSectionAssemblyResult assemblyResult, AssessmentSection assessmentSection) { - Tuple[] failureMechanisms = + Tuple>[] failureMechanisms = { - CreateTuple(assemblyResult.Piping, assessmentSection.Piping), - CreateTuple(assemblyResult.GrassCoverErosionInwards, assessmentSection.GrassCoverErosionInwards), - CreateTuple(assemblyResult.MacroStabilityInwards, assessmentSection.MacroStabilityInwards), - CreateTuple(assemblyResult.Microstability, assessmentSection.Microstability), - CreateTuple(assemblyResult.StabilityStoneCover, assessmentSection.StabilityStoneCover), - CreateTuple(assemblyResult.WaveImpactAsphaltCover, assessmentSection.WaveImpactAsphaltCover), - CreateTuple(assemblyResult.WaterPressureAsphaltCover, assessmentSection.WaterPressureAsphaltCover), - CreateTuple(assemblyResult.GrassCoverErosionOutwards, assessmentSection.GrassCoverErosionOutwards), - CreateTuple(assemblyResult.GrassCoverSlipOffOutwards, assessmentSection.GrassCoverSlipOffOutwards), - CreateTuple(assemblyResult.GrassCoverSlipOffInwards, assessmentSection.GrassCoverSlipOffInwards), - CreateTuple(assemblyResult.HeightStructures, assessmentSection.HeightStructures), - CreateTuple(assemblyResult.ClosingStructures, assessmentSection.ClosingStructures), - CreateTuple(assemblyResult.PipingStructure, assessmentSection.PipingStructure), - CreateTuple(assemblyResult.StabilityPointStructures, assessmentSection.StabilityPointStructures), - CreateTuple(assemblyResult.DuneErosion, assessmentSection.DuneErosion) + CreateTuple(assemblyResult.Piping, assessmentSection.Piping.SectionResults), + CreateTuple(assemblyResult.GrassCoverErosionInwards, assessmentSection.GrassCoverErosionInwards.SectionResults), + CreateTuple(assemblyResult.MacroStabilityInwards, assessmentSection.MacroStabilityInwards.SectionResults), + CreateTuple(assemblyResult.Microstability, assessmentSection.Microstability.SectionResults), + CreateTuple(assemblyResult.StabilityStoneCover, assessmentSection.StabilityStoneCover.SectionResults), + CreateTuple(assemblyResult.WaveImpactAsphaltCover, assessmentSection.WaveImpactAsphaltCover.SectionResults), + CreateTuple(assemblyResult.WaterPressureAsphaltCover, assessmentSection.WaterPressureAsphaltCover.SectionResults), + CreateTuple(assemblyResult.GrassCoverErosionOutwards, assessmentSection.GrassCoverErosionOutwards.SectionResults), + CreateTuple(assemblyResult.GrassCoverSlipOffOutwards, assessmentSection.GrassCoverSlipOffOutwards.SectionResults), + CreateTuple(assemblyResult.GrassCoverSlipOffInwards, assessmentSection.GrassCoverSlipOffInwards.SectionResults), + CreateTuple(assemblyResult.HeightStructures, assessmentSection.HeightStructures.SectionResults), + CreateTuple(assemblyResult.ClosingStructures, assessmentSection.ClosingStructures.SectionResults), + CreateTuple(assemblyResult.PipingStructure, assessmentSection.PipingStructure.SectionResults), + CreateTuple(assemblyResult.StabilityPointStructures, assessmentSection.StabilityPointStructures.SectionResults), + CreateTuple(assemblyResult.DuneErosion, assessmentSection.DuneErosion.SectionResults) }; List exportableAssemblyResults = failureMechanisms.Where(fm => fm.Item1.HasValue) .Select(fm => CreateExportableFailureMechanismCombinedSectionAssemblyResult( - fm.Item1.Value, assemblyResult.FailureMechanismResultsAssemblyMethod)) + registry, fm.Item2, combinedFailureMechanismSection, fm.Item1.Value, + assemblyResult.FailureMechanismResultsAssemblyMethod)) .ToList(); for (var i = 0; i < assessmentSection.SpecificFailureMechanisms.Count; i++) @@ -136,27 +136,29 @@ { SpecificFailureMechanism specificFailureMechanism = assessmentSection.SpecificFailureMechanisms.ElementAt(i); exportableAssemblyResults.Add(CreateExportableFailureMechanismCombinedSectionAssemblyResult( + registry, specificFailureMechanism.SectionResults, combinedFailureMechanismSection, specificFailureMechanismAssemblyResult.Value, assemblyResult.FailureMechanismResultsAssemblyMethod)); } } return exportableAssemblyResults; } - private static Tuple CreateTuple( - FailureMechanismSectionAssemblyGroup? assemblyResultGroup, IFailureMechanism failureMechanism) + private static Tuple> CreateTuple( + FailureMechanismSectionAssemblyGroup? assemblyResultGroup, IEnumerable sectionResults) { - return new Tuple(assemblyResultGroup, failureMechanism.Code, failureMechanism.Name); + return new Tuple>(assemblyResultGroup, sectionResults); } private static ExportableFailureMechanismCombinedSectionAssemblyResult CreateExportableFailureMechanismCombinedSectionAssemblyResult( + ExportableModelRegistry registry, IEnumerable sectionResults, ExportableCombinedFailureMechanismSection combinedFailureMechanismSection, FailureMechanismSectionAssemblyGroup sectionAssemblyGroup, AssemblyMethod assemblyMethod) { + ExportableFailureMechanismSectionAssemblyResult failureMechanismSectionAssemblyResult = + ExportableCombinedFailureMechanismSectionHelper.GetExportableFailureMechanismSectionAssemblyResult(registry, sectionResults, combinedFailureMechanismSection); + return new ExportableFailureMechanismCombinedSectionAssemblyResult( - sectionAssemblyGroup, ExportableAssemblyMethodConverter.ConvertTo(assemblyMethod), - new ExportableFailureMechanismSectionAssemblyResult( - "id", new ExportableFailureMechanismSection("id", Array.Empty(), double.NaN, double.NaN), double.NaN, - FailureMechanismSectionAssemblyGroup.Zero, ExportableAssemblyMethod.Manual, ExportableAssemblyMethod.Manual)); + sectionAssemblyGroup, ExportableAssemblyMethodConverter.ConvertTo(assemblyMethod), failureMechanismSectionAssemblyResult); } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs =================================================================== diff -u -r9b32336135a84049f0b77296616370691f4cd407 -r08a22799875699c55ccdf224a272bdc93d2b0ed1 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs (.../ExportableCombinedSectionAssemblyFactoryTest.cs) (revision 9b32336135a84049f0b77296616370691f4cd407) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableCombinedSectionAssemblyFactoryTest.cs (.../ExportableCombinedSectionAssemblyFactoryTest.cs) (revision 08a22799875699c55ccdf224a272bdc93d2b0ed1) @@ -27,8 +27,10 @@ using NUnit.Framework; using Riskeer.AssemblyTool.Data; using Riskeer.AssemblyTool.IO.Model; +using Riskeer.AssemblyTool.IO.TestUtil; using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.TestUtil; using Riskeer.Integration.Data; using Riskeer.Integration.Data.Assembly; using Riskeer.Integration.Data.TestUtil; @@ -123,6 +125,12 @@ public void CreateExportableCombinedSectionAssemblyCollection_WithAssemblyResults_ReturnsExportableCombinedSectionAssemblyCollection(bool hasAssemblyGroupResults) { // Setup + CombinedFailureMechanismSectionAssemblyResult[] assemblyResults = + { + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(21, hasAssemblyGroupResults), + CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(22, hasAssemblyGroupResults) + }; + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); assessmentSection.ReferenceLine.SetGeometry(new[] { @@ -141,38 +149,81 @@ Code = "Nieuw2" } }); + SetFailureMechanismSections(assessmentSection, assemblyResults.Length); - CombinedFailureMechanismSectionAssemblyResult[] assemblyResults = - { - CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(21, hasAssemblyGroupResults), - CombinedFailureMechanismSectionAssemblyResultTestFactory.Create(22, hasAssemblyGroupResults) - }; - var idGenerator = new IdentifierGenerator(); var registry = new ExportableModelRegistry(); RegisterFailureMechanismSections(registry, assessmentSection.ReferenceLine, assemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection, assemblyResults); // Call IEnumerable exportableCombinedSectionAssemblies = ExportableCombinedSectionAssemblyFactory.CreateExportableCombinedSectionAssemblyCollection( idGenerator, registry, assemblyResults, assessmentSection); // Assert - AssertCombinedFailureMechanismSectionAssemblyResults(registry, assemblyResults, exportableCombinedSectionAssemblies, - hasAssemblyGroupResults); + AssertCombinedFailureMechanismSectionAssemblyResults(registry, assessmentSection, assemblyResults, + exportableCombinedSectionAssemblies, hasAssemblyGroupResults); } + private static void SetFailureMechanismSections(AssessmentSection assessmentSection, int nrOfCombinedAssemblyResults) + { + IEnumerable failureMechanisms = assessmentSection.GetFailureMechanisms() + .Concat(assessmentSection.SpecificFailureMechanisms); + foreach (IFailureMechanism failureMechanism in failureMechanisms) + { + FailureMechanismTestHelper.AddSections(failureMechanism, nrOfCombinedAssemblyResults); + } + } + private static void RegisterFailureMechanismSections(ExportableModelRegistry registry, ReferenceLine referenceLine, IEnumerable assemblyResults) { - ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection(new IdentifierGenerator(), registry, referenceLine, assemblyResults); + ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( + new IdentifierGenerator(), registry, referenceLine, assemblyResults); } + private static void RegisterFailureMechanismSectionResults(ExportableModelRegistry registry, AssessmentSection assessmentSection, + IEnumerable combinedSectionAssemblyResults) + { + RegisterFailureMechanismSectionResults(registry, assessmentSection.Piping.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.GrassCoverErosionInwards.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.MacroStabilityInwards.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.Microstability.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.StabilityStoneCover.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.WaveImpactAsphaltCover.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.WaterPressureAsphaltCover.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.GrassCoverErosionOutwards.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.GrassCoverSlipOffOutwards.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.GrassCoverSlipOffInwards.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.HeightStructures.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.ClosingStructures.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.PipingStructure.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.StabilityPointStructures.SectionResults, combinedSectionAssemblyResults); + RegisterFailureMechanismSectionResults(registry, assessmentSection.DuneErosion.SectionResults, combinedSectionAssemblyResults); + + foreach (SpecificFailureMechanism specificFailureMechanism in assessmentSection.SpecificFailureMechanisms) + { + RegisterFailureMechanismSectionResults(registry, specificFailureMechanism.SectionResults, combinedSectionAssemblyResults); + } + } + + private static void RegisterFailureMechanismSectionResults(ExportableModelRegistry registry, + IEnumerable sectionAssemblyResults, + IEnumerable combinedSectionAssemblyResults) + { + for (int i = 0; i < combinedSectionAssemblyResults.Count(); i++) + { + CombinedFailureMechanismSectionAssemblyResult assemblyResult = combinedSectionAssemblyResults.ElementAt(i); + ExportableFailureMechanismSection exportableSection = ExportableFailureMechanismSectionTestFactory.CreateExportableFailureMechanismSection( + assemblyResult.SectionStart, assemblyResult.SectionEnd); + registry.Register(sectionAssemblyResults.ElementAt(i), ExportableFailureMechanismSectionAssemblyResultTestFactory.Create(exportableSection, i)); + } + } + private static void AssertCombinedFailureMechanismSectionAssemblyResults( - ExportableModelRegistry registry, - IEnumerable assemblyResults, - IEnumerable exportableCombinedSectionAssemblies, - bool hasAssemblyGroupResults) + ExportableModelRegistry registry, AssessmentSection assessmentSection, IEnumerable assemblyResults, + IEnumerable exportableCombinedSectionAssemblies, bool hasAssemblyGroupResults) { int expectedNrOfSections = assemblyResults.Count(); Assert.AreEqual(expectedNrOfSections, exportableCombinedSectionAssemblies.Count()); @@ -182,13 +233,15 @@ CombinedFailureMechanismSectionAssemblyResult combinedFailureMechanismSectionAssemblyResult = assemblyResults.ElementAt(i); ExportableCombinedSectionAssembly exportableCombinedSectionAssembly = exportableCombinedSectionAssemblies.ElementAt(i); - AssertExportableCombinedFailureMechanismSectionResult( - i, combinedFailureMechanismSectionAssemblyResult, registry.Get(combinedFailureMechanismSectionAssemblyResult), - exportableCombinedSectionAssembly, hasAssemblyGroupResults); + AssertExportableCombinedFailureMechanismSectionResult(i, registry, assessmentSection, combinedFailureMechanismSectionAssemblyResult, + registry.Get(combinedFailureMechanismSectionAssemblyResult), + exportableCombinedSectionAssembly, hasAssemblyGroupResults); } } private static void AssertExportableCombinedFailureMechanismSectionResult(int index, + ExportableModelRegistry registry, + AssessmentSection assessmentSection, CombinedFailureMechanismSectionAssemblyResult expectedSection, ExportableCombinedFailureMechanismSection actualSection, ExportableCombinedSectionAssembly actualSectionResult, @@ -212,46 +265,52 @@ Assert.IsTrue(failureMechanismCombinedSectionResults.All(result => result.AssemblyMethod == ExportableAssemblyMethodConverter.ConvertTo( expectedSection.FailureMechanismResultsAssemblyMethod))); - AssertSubSection(expectedSection.Piping, "STPH", - failureMechanismCombinedSectionResults.ElementAt(0)); - AssertSubSection(expectedSection.GrassCoverErosionInwards, "GEKB", - failureMechanismCombinedSectionResults.ElementAt(1)); - AssertSubSection(expectedSection.MacroStabilityInwards, "STBI", - failureMechanismCombinedSectionResults.ElementAt(2)); - AssertSubSection(expectedSection.Microstability, "STMI", - failureMechanismCombinedSectionResults.ElementAt(3)); - AssertSubSection(expectedSection.StabilityStoneCover, "ZST", - failureMechanismCombinedSectionResults.ElementAt(4)); - AssertSubSection(expectedSection.WaveImpactAsphaltCover, "AGK", - failureMechanismCombinedSectionResults.ElementAt(5)); - AssertSubSection(expectedSection.WaterPressureAsphaltCover, "AWO", - failureMechanismCombinedSectionResults.ElementAt(6)); - AssertSubSection(expectedSection.GrassCoverErosionOutwards, "GEBU", - failureMechanismCombinedSectionResults.ElementAt(7)); - AssertSubSection(expectedSection.GrassCoverSlipOffOutwards, "GABU", - failureMechanismCombinedSectionResults.ElementAt(8)); - AssertSubSection(expectedSection.GrassCoverSlipOffInwards, "GABI", - failureMechanismCombinedSectionResults.ElementAt(9)); - AssertSubSection(expectedSection.HeightStructures, "HTKW", - failureMechanismCombinedSectionResults.ElementAt(10)); - AssertSubSection(expectedSection.ClosingStructures, "BSKW", - failureMechanismCombinedSectionResults.ElementAt(11)); - AssertSubSection(expectedSection.PipingStructure, "PKW", - failureMechanismCombinedSectionResults.ElementAt(12)); - AssertSubSection(expectedSection.StabilityPointStructures, "STKWp", - failureMechanismCombinedSectionResults.ElementAt(13)); - AssertSubSection(expectedSection.DuneErosion, "DA", - failureMechanismCombinedSectionResults.ElementAt(14)); - AssertSubSection(expectedSection.SpecificFailureMechanisms[0], "Nieuw1", - failureMechanismCombinedSectionResults.ElementAt(15)); - AssertSubSection(expectedSection.SpecificFailureMechanisms[1], "Nieuw2", - failureMechanismCombinedSectionResults.ElementAt(16)); + AssertSubSection(index, registry, assessmentSection.Piping, + expectedSection.Piping, failureMechanismCombinedSectionResults.ElementAt(0)); + AssertSubSection(index, registry, assessmentSection.GrassCoverErosionInwards, + expectedSection.GrassCoverErosionInwards, failureMechanismCombinedSectionResults.ElementAt(1)); + AssertSubSection(index, registry, assessmentSection.MacroStabilityInwards, + expectedSection.MacroStabilityInwards, failureMechanismCombinedSectionResults.ElementAt(2)); + AssertSubSection(index, registry, assessmentSection.Microstability, + expectedSection.Microstability, failureMechanismCombinedSectionResults.ElementAt(3)); + AssertSubSection(index, registry, assessmentSection.StabilityStoneCover, + expectedSection.StabilityStoneCover, failureMechanismCombinedSectionResults.ElementAt(4)); + AssertSubSection(index, registry, assessmentSection.WaveImpactAsphaltCover, + expectedSection.WaveImpactAsphaltCover, failureMechanismCombinedSectionResults.ElementAt(5)); + AssertSubSection(index, registry, assessmentSection.WaterPressureAsphaltCover, + expectedSection.WaterPressureAsphaltCover, failureMechanismCombinedSectionResults.ElementAt(6)); + AssertSubSection(index, registry, assessmentSection.GrassCoverErosionOutwards, + expectedSection.GrassCoverErosionOutwards, failureMechanismCombinedSectionResults.ElementAt(7)); + AssertSubSection(index, registry, assessmentSection.GrassCoverSlipOffOutwards, + expectedSection.GrassCoverSlipOffOutwards, failureMechanismCombinedSectionResults.ElementAt(8)); + AssertSubSection(index, registry, assessmentSection.GrassCoverSlipOffInwards, + expectedSection.GrassCoverSlipOffInwards, failureMechanismCombinedSectionResults.ElementAt(9)); + AssertSubSection(index, registry, assessmentSection.HeightStructures, + expectedSection.HeightStructures, failureMechanismCombinedSectionResults.ElementAt(10)); + AssertSubSection(index, registry, assessmentSection.ClosingStructures, + expectedSection.ClosingStructures, failureMechanismCombinedSectionResults.ElementAt(11)); + AssertSubSection(index, registry, assessmentSection.PipingStructure, + expectedSection.PipingStructure, failureMechanismCombinedSectionResults.ElementAt(12)); + AssertSubSection(index, registry, assessmentSection.StabilityPointStructures, + expectedSection.StabilityPointStructures, failureMechanismCombinedSectionResults.ElementAt(13)); + AssertSubSection(index, registry, assessmentSection.DuneErosion, + expectedSection.DuneErosion, failureMechanismCombinedSectionResults.ElementAt(14)); + AssertSubSection(index, registry, assessmentSection.SpecificFailureMechanisms[0], + expectedSection.SpecificFailureMechanisms[0], failureMechanismCombinedSectionResults.ElementAt(15)); + AssertSubSection(index, registry, assessmentSection.SpecificFailureMechanisms[1], + expectedSection.SpecificFailureMechanisms[1], failureMechanismCombinedSectionResults.ElementAt(16)); } - private static void AssertSubSection(FailureMechanismSectionAssemblyGroup? subSectionGroup, string subSectionCode, - ExportableFailureMechanismCombinedSectionAssemblyResult actualResult) + private static void AssertSubSection(int index, ExportableModelRegistry registry, IFailureMechanism failureMechanism, + FailureMechanismSectionAssemblyGroup? subSectionGroup, + ExportableFailureMechanismCombinedSectionAssemblyResult actualResult) + where T : FailureMechanismSectionResult { Assert.AreEqual(subSectionGroup, actualResult.AssemblyGroup); + + T sectionResult = failureMechanism.SectionResults.ElementAt(index); + ExportableFailureMechanismSectionAssemblyResult expectedExportableSectionResult = registry.Get(sectionResult); + Assert.AreSame(expectedExportableSectionResult, actualResult.FailureMechanismSectionResult); } } } \ No newline at end of file