Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs =================================================================== diff -u -r67b3d776bcd2a24360d3187557b5aaa6ba74f7c9 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 67b3d776bcd2a24360d3187557b5aaa6ba74f7c9) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableAssessmentSectionFactory.cs (.../ExportableAssessmentSectionFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -81,7 +81,7 @@ throw new ArgumentNullException(nameof(assessmentSection)); } - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); return new ExportableAssessmentSection(IdentifierGenerator.GenerateId(assessmentSection), assessmentSection.Name, assessmentSection.ReferenceLine.Points, @@ -151,7 +151,7 @@ /// for failure mechanisms that are in assembly based on . /// /// The generator to generate ids for the exportable components. - /// The + /// The /// to keep track of the created . /// The assessment section to create a collection of /// with probability for. @@ -160,7 +160,7 @@ /// Thrown when assembly results cannot be created for . /// Thrown when assembly results are invalid and cannot be exported. private static IEnumerable CreateExportableFailureMechanisms( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, AssessmentSection assessmentSection) + IdentifierGenerator idGenerator, ExportableModelRegistry registry, AssessmentSection assessmentSection) { var exportableFailureMechanisms = new List(); @@ -242,7 +242,7 @@ /// Adds a generic failure mechanism to the when it is in assembly. /// /// The generator to generate ids for the exportable components. - /// The + /// The /// to keep track of the created . /// The with /// to add the failure mechanism to. @@ -255,7 +255,7 @@ /// Thrown when assembly results cannot be created for . /// Thrown when assembly results are invalid and cannot be exported. private static void AddGenericFailureMechanismWhenInAssembly( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, List exportableFailureMechanisms, + IdentifierGenerator idGenerator, ExportableModelRegistry registry, List exportableFailureMechanisms, TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func assembleFailureMechanismFunc, Func assembleFailureMechanismSectionFunc) @@ -271,7 +271,7 @@ } private static IEnumerable CreateExportableFailureMechanismSectionCollections( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, AssessmentSection assessmentSection) + IdentifierGenerator idGenerator, ExportableModelRegistry registry, AssessmentSection assessmentSection) { IEnumerable failureMechanismsInAssembly = assessmentSection.GetFailureMechanisms() .Concat(assessmentSection.SpecificFailureMechanisms) Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismFactory.cs =================================================================== diff -u -r67b3d776bcd2a24360d3187557b5aaa6ba74f7c9 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismFactory.cs (.../ExportableFailureMechanismFactory.cs) (revision 67b3d776bcd2a24360d3187557b5aaa6ba74f7c9) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismFactory.cs (.../ExportableFailureMechanismFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -44,7 +44,7 @@ /// with assembly results based on the input parameters. /// /// The generator to generate ids for the exportable components. - /// The to keep track of the created . + /// The to keep track of the created items. /// The failure mechanism to create an for. /// The assessment section the failure mechanism belongs to. /// The to perform @@ -59,7 +59,7 @@ /// Thrown when /// returns an invalid result that cannot be exported. public static ExportableGenericFailureMechanism CreateExportableGenericFailureMechanism( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, + IdentifierGenerator idGenerator, ExportableModelRegistry registry, TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func assembleFailureMechanismFunc, Func assembleFailureMechanismSectionFunc) where TFailureMechanism : IFailureMechanism @@ -110,7 +110,7 @@ /// with assembly results based on the input parameters. /// /// The generator to generate ids for the exportable components. - /// The to keep track of the created . + /// The to keep track of the created items. /// The failure mechanism to create an for. /// The assessment section the failure mechanism belongs to. /// The to perform @@ -123,7 +123,7 @@ /// Thrown when /// returns an invalid result that cannot be exported. public static ExportableSpecificFailureMechanism CreateExportableSpecificFailureMechanism( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, SpecificFailureMechanism failureMechanism, IAssessmentSection assessmentSection, + IdentifierGenerator idGenerator, ExportableModelRegistry registry, SpecificFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func assembleFailureMechanismFunc, Func assembleFailureMechanismSectionFunc) { @@ -172,7 +172,7 @@ /// with assembly results based on . /// /// The generator to generate ids for the exportable components. - /// The to keep track of the created . + /// The to keep track of the created items. /// The failure mechanism to create a collection of /// for. /// The to use in the assembly. @@ -185,7 +185,7 @@ /// Thrown when /// returns an invalid result that cannot be exported. private static IEnumerable CreateExportableFailureMechanismSectionResults( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, + IdentifierGenerator idGenerator, ExportableModelRegistry registry, TFailureMechanism failureMechanism, IAssessmentSection assessmentSection, Func assembleFailureMechanismSectionFunc) where TFailureMechanism : IFailureMechanism where TSectionResult : FailureMechanismSectionResult Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs =================================================================== diff -u -r838241db2e78d6f4dc62648bca2fc58aec061365 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 838241db2e78d6f4dc62648bca2fc58aec061365) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -38,13 +38,13 @@ /// . /// /// The generator to generate ids for the exportable components. - /// The to keep track of the created . + /// The to keep track of the created items. /// The collection of to create the /// with. /// An . /// Thrown when any parameter is null. public static ExportableFailureMechanismSectionCollection CreateExportableFailureMechanismSectionCollection( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, IEnumerable sections) + IdentifierGenerator idGenerator, ExportableModelRegistry registry, IEnumerable sections) { if (idGenerator == null) { @@ -61,6 +61,11 @@ throw new ArgumentNullException(nameof(sections)); } + if (registry.Contains(sections)) + { + return registry.Get(sections); + } + var exportableSections = new List(); double startDistance = 0; foreach (FailureMechanismSection section in sections) @@ -74,6 +79,7 @@ var exportableCollection = new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), exportableSections); + registry.Register(sections, exportableCollection); return exportableCollection; } } Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs =================================================================== diff -u -r838241db2e78d6f4dc62648bca2fc58aec061365 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (.../ExportableFailureMechanismSectionFactory.cs) (revision 838241db2e78d6f4dc62648bca2fc58aec061365) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionFactory.cs (.../ExportableFailureMechanismSectionFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -36,7 +36,7 @@ /// Creates an based on its input arguments. /// /// The generator to generate ids for the exportable components. - /// The to keep track of the created . + /// The to keep track of the created items. /// The to create the /// with. /// The start distance of the failure mechanism section between the section @@ -45,7 +45,7 @@ /// Thrown when , /// or is null. public static ExportableFailureMechanismSection CreateExportableFailureMechanismSection( - IdentifierGenerator idGenerator, ExportableFailureMechanismSectionRegistry registry, FailureMechanismSection section, + IdentifierGenerator idGenerator, ExportableModelRegistry registry, FailureMechanismSection section, double startDistance) { if (idGenerator == null) Fisheye: Tag 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b refers to a dead (removed) revision in file `Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableFailureMechanismSectionRegistry.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 838241db2e78d6f4dc62648bca2fc58aec061365 refers to a dead (removed) revision in file `Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismFactoryTest.cs =================================================================== diff -u -r67b3d776bcd2a24360d3187557b5aaa6ba74f7c9 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismFactoryTest.cs (.../ExportableFailureMechanismFactoryTest.cs) (revision 67b3d776bcd2a24360d3187557b5aaa6ba74f7c9) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismFactoryTest.cs (.../ExportableFailureMechanismFactoryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -50,7 +50,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableGenericFailureMechanism( - null, new ExportableFailureMechanismSectionRegistry(), new TestFailureMechanism(), assessmentSection, (fm, section) => null, (sr, fm, section) => null); + null, new ExportableModelRegistry(), new TestFailureMechanism(), assessmentSection, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -86,7 +86,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableGenericFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), null, assessmentSection, (fm, section) => null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), null, assessmentSection, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -99,7 +99,7 @@ { // Call void Call() => ExportableFailureMechanismFactory.CreateExportableGenericFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new TestFailureMechanism(), null, (fm, section) => null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), new TestFailureMechanism(), null, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -116,7 +116,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableGenericFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new TestFailureMechanism(), assessmentSection, null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), new TestFailureMechanism(), assessmentSection, null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -134,7 +134,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableGenericFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new TestFailureMechanism(), assessmentSection, (fm, section) => null, null); + new IdentifierGenerator(), new ExportableModelRegistry(), new TestFailureMechanism(), assessmentSection, (fm, section) => null, null); // Assert var exception = Assert.Throws(Call); @@ -157,7 +157,7 @@ var idGenerator = new IdentifierGenerator(); - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); RegisterFailureMechanismSections(registry, failureMechanism.Sections); // Call @@ -192,7 +192,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableSpecificFailureMechanism( - null, new ExportableFailureMechanismSectionRegistry(), new SpecificFailureMechanism(), assessmentSection, (fm, section) => null, (sr, fm, section) => null); + null, new ExportableModelRegistry(), new SpecificFailureMechanism(), assessmentSection, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -228,7 +228,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableSpecificFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), null, assessmentSection, (fm, section) => null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), null, assessmentSection, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -241,7 +241,7 @@ { // Call void Call() => ExportableFailureMechanismFactory.CreateExportableSpecificFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new SpecificFailureMechanism(), null, (fm, section) => null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), new SpecificFailureMechanism(), null, (fm, section) => null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -258,7 +258,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableSpecificFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new SpecificFailureMechanism(), assessmentSection, null, (sr, fm, section) => null); + new IdentifierGenerator(), new ExportableModelRegistry(), new SpecificFailureMechanism(), assessmentSection, null, (sr, fm, section) => null); // Assert var exception = Assert.Throws(Call); @@ -276,7 +276,7 @@ // Call void Call() => ExportableFailureMechanismFactory.CreateExportableSpecificFailureMechanism( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), new SpecificFailureMechanism(), assessmentSection, (fm, section) => null, null); + new IdentifierGenerator(), new ExportableModelRegistry(), new SpecificFailureMechanism(), assessmentSection, (fm, section) => null, null); // Assert var exception = Assert.Throws(Call); @@ -298,7 +298,7 @@ FailureMechanismSectionAssemblyResultWrapper expectedSectionOutput = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create(); var idGenerator = new IdentifierGenerator(); - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); RegisterFailureMechanismSections(registry, failureMechanism.Sections); // Call @@ -323,7 +323,7 @@ expectedSectionOutput, exportableFailureMechanismSections, exportableFailureMechanism.SectionAssemblyResults); } - private static void RegisterFailureMechanismSections(ExportableFailureMechanismSectionRegistry registry, IEnumerable failureMechanismSections) + private static void RegisterFailureMechanismSections(ExportableModelRegistry registry, IEnumerable failureMechanismSections) { ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( new IdentifierGenerator(), registry, failureMechanismSections); Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs =================================================================== diff -u -r838241db2e78d6f4dc62648bca2fc58aec061365 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 838241db2e78d6f4dc62648bca2fc58aec061365) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; using NUnit.Framework; @@ -39,7 +40,7 @@ { // Call void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( - null, new ExportableFailureMechanismSectionRegistry(), Enumerable.Empty()); + null, new ExportableModelRegistry(), Enumerable.Empty()); // Assert var exception = Assert.Throws(Call); @@ -57,13 +58,13 @@ var exception = Assert.Throws(Call); Assert.AreEqual("registry", exception.ParamName); } - + [Test] public void CreateExportableFailureMechanismSectionCollection_SectionsNull_ThrowsArgumentNullException() { // Call void Call() => ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), null); + new IdentifierGenerator(), new ExportableModelRegistry(), null); // Assert var exception = Assert.Throws(Call); @@ -94,7 +95,7 @@ }) }; - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); // Call ExportableFailureMechanismSectionCollection collection = @@ -109,18 +110,41 @@ Assert.AreEqual("Bv.0", firstExportableSection.Id); Assert.AreEqual(0, firstExportableSection.StartDistance); Assert.AreEqual(10, firstExportableSection.EndDistance); - + ExportableFailureMechanismSection secondExportableSection = collection.Sections.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); 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 CreateExportableFailureMechanismSectionCollection_SectionsAlreadyRegistered_ReturnsRegisteredExportableModel() + { + // Setup + var sections = new List(); + + var registry = new ExportableModelRegistry(); + var idGenerator = new IdentifierGenerator(); + ExportableFailureMechanismSectionCollection exportableCollection1 = + ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection(idGenerator, registry, sections); + + + // Precondition + Assert.True(registry.Contains(sections)); + + // Call + ExportableFailureMechanismSectionCollection exportableCollection2 = + ExportableFailureMechanismSectionCollectionFactory.CreateExportableFailureMechanismSectionCollection(idGenerator, registry, sections); + + // Assert + Assert.AreSame(exportableCollection1, exportableCollection2); + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs =================================================================== diff -u -r838241db2e78d6f4dc62648bca2fc58aec061365 -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (.../ExportableFailureMechanismSectionFactoryTest.cs) (revision 838241db2e78d6f4dc62648bca2fc58aec061365) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionFactoryTest.cs (.../ExportableFailureMechanismSectionFactoryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) @@ -40,7 +40,7 @@ // Call void Call() => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection( - null, new ExportableFailureMechanismSectionRegistry(), FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), random.NextDouble()); + null, new ExportableModelRegistry(), FailureMechanismSectionTestFactory.CreateFailureMechanismSection(), random.NextDouble()); // Assert var exception = Assert.Throws(Call); @@ -70,7 +70,7 @@ // Call void Call() => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection( - new IdentifierGenerator(), new ExportableFailureMechanismSectionRegistry(), null, random.NextDouble()); + new IdentifierGenerator(), new ExportableModelRegistry(), null, random.NextDouble()); // Assert var exception = Assert.Throws(Call); @@ -87,7 +87,7 @@ var idGenerator = new IdentifierGenerator(); FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); // Call ExportableFailureMechanismSection exportableSection = @@ -110,7 +110,7 @@ FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); var idGenerator = new IdentifierGenerator(); - var registry = new ExportableFailureMechanismSectionRegistry(); + var registry = new ExportableModelRegistry(); ExportableFailureMechanismSection exportableModel1 = ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(idGenerator, registry, section, random.NextDouble()); Fisheye: Tag 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableFailureMechanismSectionRegistryTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 838241db2e78d6f4dc62648bca2fc58aec061365 refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs'. Fisheye: No comparison available. Pass `N' to diff?