Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -r2cd36eedaac4fa2986b41823527527a279e4dbe5 --- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) @@ -61,11 +61,6 @@ 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) @@ -77,10 +72,8 @@ startDistance = exportableFailureMechanismSection.EndDistance; } - var exportableCollection = new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), - exportableSections); - registry.Register(sections, exportableCollection); - return exportableCollection; + return new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix), + exportableSections); } } } \ No newline at end of file Index: Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -r2cd36eedaac4fa2986b41823527527a279e4dbe5 --- Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs (.../ExportableModelRegistry.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs (.../ExportableModelRegistry.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) @@ -24,16 +24,17 @@ using Core.Common.Util; using Riskeer.AssemblyTool.IO.Model; using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Integration.Data.Assembly; namespace Riskeer.Integration.IO.Helpers { /// - /// Class that keeps track of the the created objects of the exportable model. + /// Class that keeps track of the created objects of the exportable model. /// public class ExportableModelRegistry { - private readonly Dictionary, ExportableFailureMechanismSectionCollection> failureMechanismSectionCollections = - CreateDictionary, ExportableFailureMechanismSectionCollection>(); + private readonly Dictionary combinedFailureMechanismSectionAssemblyResults = + CreateDictionary(); private readonly Dictionary failureMechanismSections = CreateDictionary(); @@ -53,7 +54,8 @@ return collection.ContainsKey(model); } - private static void Register(Dictionary collection, TModel model, TExportableModel exportableModel) + private static void Register(Dictionary collection, TModel model, + TExportableModel exportableModel) { if (exportableModel == null) { @@ -104,23 +106,21 @@ #region Register methods /// - /// Registers a create operation for and the - /// that was constructed with the information. + /// Registers the with the value . /// /// The collection of to be registered. /// The to be registered with. /// Thrown when any of the input parameters is null. - public void Register(IEnumerable model, ExportableFailureMechanismSectionCollection exportableModel) + public void Register(CombinedFailureMechanismSectionAssemblyResult model, ExportableCombinedFailureMechanismSection exportableModel) { - Register(failureMechanismSectionCollections, model, exportableModel); + Register(combinedFailureMechanismSectionAssemblyResults, model, exportableModel); } /// - /// Registers a create operation for and the - /// that was constructed with the information. + /// Registers the with the value . /// - /// The to be registered with. - /// The to be registered. + /// The to be registered. + /// The to be registered with. /// Thrown when any of the input parameters is null. internal void Register(FailureMechanismSection model, ExportableFailureMechanismSection exportableModel) { @@ -132,18 +132,18 @@ #region Contains methods /// - /// Checks whether a create operations has been registered for the given . + /// Checks whether a value has been registered for the given . /// /// The collection of to check for. /// true if the was registered before, false otherwise. /// Thrown when is null. - internal bool Contains(IEnumerable model) + internal bool Contains(CombinedFailureMechanismSectionAssemblyResult model) { - return ContainsValue(failureMechanismSectionCollections, model); + return ContainsValue(combinedFailureMechanismSectionAssemblyResults, model); } /// - /// Checks whether a create operations has been registered for the given . + /// Checks whether a value has been registered for the given . /// /// The to check for. /// true if the was registered before, false otherwise. @@ -158,19 +158,19 @@ #region Get methods /// - /// Obtains the which was registered for the + /// Obtains the which was registered for the /// given . /// - /// The collection of that has been registered. - /// The associated . + /// The that has been registered. + /// The associated . /// Thrown when is null. /// Thrown when no exportable model /// has been registered for . - /// Use to find out whether a create + /// Use to find out whether a create /// operation has been registered for . - public ExportableFailureMechanismSectionCollection Get(IEnumerable model) + public ExportableCombinedFailureMechanismSection Get(CombinedFailureMechanismSectionAssemblyResult model) { - return Get(failureMechanismSectionCollections, model); + return Get(combinedFailureMechanismSectionAssemblyResults, model); } /// Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -r2cd36eedaac4fa2986b41823527527a279e4dbe5 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Factories/ExportableFailureMechanismSectionCollectionFactoryTest.cs (.../ExportableFailureMechanismSectionCollectionFactoryTest.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; using NUnit.Framework; @@ -58,7 +57,7 @@ var exception = Assert.Throws(Call); Assert.AreEqual("registry", exception.ParamName); } - + [Test] public void CreateExportableFailureMechanismSectionCollection_SectionsNull_ThrowsArgumentNullException() { @@ -110,41 +109,18 @@ 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/Helpers/ExportableModelRegistryTest.cs =================================================================== diff -u -r1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b -r2cd36eedaac4fa2986b41823527527a279e4dbe5 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision 1a5616c5fe4da4c7d7c4fe75efad59f88b6aa90b) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision 2cd36eedaac4fa2986b41823527527a279e4dbe5) @@ -1,11 +1,33 @@ -using System; -using System.Collections.Generic; -using System.Linq; +// 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 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.IO.Helpers; namespace Riskeer.Integration.IO.Test.Helpers @@ -223,27 +245,37 @@ /// protected abstract TExportableModel CreateExportableModel(); } - + [TestFixture] - private class FailureMechanismSectionCollectionTest : RegistryTest, - ExportableFailureMechanismSectionCollection> + private class CombinedFailureMechanismSectionAssemblyResultTest : RegistryTest { - public FailureMechanismSectionCollectionTest() : base( + public CombinedFailureMechanismSectionAssemblyResultTest() : base( (r, e, m) => r.Register(m, e), (r, m) => r.Contains(m), (r, m) => r.Get(m)) {} - protected override IEnumerable CreateDataModel() + protected override CombinedFailureMechanismSectionAssemblyResult CreateDataModel() { - return new List(); + 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()); } - protected override ExportableFailureMechanismSectionCollection CreateExportableModel() + protected override ExportableCombinedFailureMechanismSection CreateExportableModel() { - return new ExportableFailureMechanismSectionCollection("id", Enumerable.Empty()); + return ExportableFailureMechanismSectionTestFactory.CreateExportableCombinedFailureMechanismSection(); } } - + [TestFixture] private class FailureMechanismSectionTest : RegistryTest