Index: Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs
===================================================================
diff -u -r08cc37ec1d27835d4ccefd628f47a72d5e8d1d1e -r90c7a8c93ed280d5881307f04b103ed23be3a2ba
--- Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 08cc37ec1d27835d4ccefd628f47a72d5e8d1d1e)
+++ Riskeer/Integration/src/Riskeer.Integration.IO/Factories/ExportableFailureMechanismSectionCollectionFactory.cs (.../ExportableFailureMechanismSectionCollectionFactory.cs) (revision 90c7a8c93ed280d5881307f04b103ed23be3a2ba)
@@ -29,19 +29,19 @@
namespace Riskeer.Integration.IO.Factories
{
///
- /// Factory for creating .
+ /// Factory for creating .
///
public static class ExportableFailureMechanismSectionCollectionFactory
{
///
- /// Creates an based on a collection of
+ /// 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 collection of to create the
/// with.
- /// A .
+ /// An .
/// Thrown when any parameter is null.
public static ExportableFailureMechanismSectionCollection CreateExportableFailureMechanismSectionCollection(
IdentifierGenerator idGenerator, ExportableModelRegistry registry, IEnumerable sections)
@@ -79,7 +79,7 @@
var exportableCollection = new ExportableFailureMechanismSectionCollection(idGenerator.GetNewId(Resources.ExportableFailureMechanismSectionCollection_IdPrefix),
exportableSections);
- registry.Register(exportableCollection, sections);
+ registry.Register(sections, exportableCollection);
return exportableCollection;
}
}
Index: Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs
===================================================================
diff -u -raa4cf1ac8798c978fb5423367283178b9ed01914 -r90c7a8c93ed280d5881307f04b103ed23be3a2ba
--- Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs (.../ExportableModelRegistry.cs) (revision aa4cf1ac8798c978fb5423367283178b9ed01914)
+++ Riskeer/Integration/src/Riskeer.Integration.IO/Helpers/ExportableModelRegistry.cs (.../ExportableModelRegistry.cs) (revision 90c7a8c93ed280d5881307f04b103ed23be3a2ba)
@@ -21,7 +21,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using Core.Common.Util;
using Riskeer.AssemblyTool.IO.Model;
using Riskeer.Common.Data.FailureMechanism;
@@ -33,50 +32,73 @@
///
public class ExportableModelRegistry
{
- private readonly Dictionary> failureMechanismSectionCollections =
- CreateDictionary>();
+ private readonly Dictionary, ExportableFailureMechanismSectionCollection> failureMechanismSectionCollections =
+ CreateDictionary, ExportableFailureMechanismSectionCollection>();
- private readonly Dictionary failureMechanismSections =
- CreateDictionary();
-
- private static Dictionary CreateDictionary()
+ private readonly Dictionary failureMechanismSections =
+ CreateDictionary();
+
+ private static Dictionary CreateDictionary()
{
- return new Dictionary(new ReferenceEqualityComparer());
+ return new Dictionary(new ReferenceEqualityComparer());
}
- private static bool ContainsValue(Dictionary collection, TModel model)
+ private static bool ContainsValue(Dictionary collection, TModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
- return collection.Values.Contains(model, new ReferenceEqualityComparer());
+ return collection.ContainsKey(model);
}
- private static void Register(Dictionary collection, TExportableModel entity, TModel model)
+ private static void Register(Dictionary collection, TModel model, TExportableModel exportableModel)
{
- if (entity == null)
+ if (exportableModel == null)
{
- throw new ArgumentNullException(nameof(entity));
+ throw new ArgumentNullException(nameof(exportableModel));
}
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
- collection[entity] = model;
+ collection[model] = exportableModel;
}
- private TExportableModel Get(Dictionary collection, TModel model)
+ ///
+ /// Obtains the from a registered .
+ ///
+ /// The collection that contains the lookup information of
+ /// and .
+ /// The to retrieve the for.
+ /// The model that was registered.
+ /// The type of exportable model that was registered with .
+ /// A .
+ /// Thrown when any parameter is null.
+ /// Thrown when no item was registered for .
+ private static TExportableModel Get(Dictionary collection, TModel model)
{
+ if (collection == null)
+ {
+ throw new ArgumentNullException(nameof(collection));
+ }
+
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
- return collection.Keys.Single(k => ReferenceEquals(collection[k], model));
+ try
+ {
+ return collection[model];
+ }
+ catch (KeyNotFoundException e)
+ {
+ throw new InvalidOperationException(e.Message);
+ }
}
#region Register methods
@@ -85,24 +107,24 @@
/// Registers a create operation for and the
/// that was constructed with the information.
///
- /// The to be registered.
/// The collection of to be registered.
+ /// The to be registered with.
/// Thrown when any of the input parameters is null.
- public void Register(ExportableFailureMechanismSectionCollection exportableModel, IEnumerable model)
+ public void Register(IEnumerable model, ExportableFailureMechanismSectionCollection exportableModel)
{
- Register(failureMechanismSectionCollections, exportableModel, model);
+ Register(failureMechanismSectionCollections, model, exportableModel);
}
-
+
///
/// Registers a create operation for and the
/// that was constructed with the information.
///
+ /// The to be registered with.
/// The to be registered.
- /// The to be registered.
/// Thrown when any of the input parameters is null.
- internal void Register(ExportableFailureMechanismSection exportableModel, FailureMechanismSection model)
+ internal void Register(FailureMechanismSection model, ExportableFailureMechanismSection exportableModel)
{
- Register(failureMechanismSections, exportableModel, model);
+ Register(failureMechanismSections, model, exportableModel);
}
#endregion
@@ -119,7 +141,7 @@
{
return ContainsValue(failureMechanismSectionCollections, model);
}
-
+
///
/// Checks whether a create operations has been registered for the given .
///
@@ -150,7 +172,7 @@
{
return Get(failureMechanismSectionCollections, model);
}
-
+
///
/// Obtains the which was registered for the
/// given .
@@ -168,6 +190,5 @@
}
#endregion
-
}
}
\ No newline at end of file
Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs
===================================================================
diff -u -raa4cf1ac8798c978fb5423367283178b9ed01914 -r90c7a8c93ed280d5881307f04b103ed23be3a2ba
--- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision aa4cf1ac8798c978fb5423367283178b9ed01914)
+++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Helpers/ExportableModelRegistryTest.cs (.../ExportableModelRegistryTest.cs) (revision 90c7a8c93ed280d5881307f04b103ed23be3a2ba)
@@ -78,7 +78,7 @@
// Assert
string paramName = Assert.Throws(Call).ParamName;
- Assert.AreEqual("entity", paramName);
+ Assert.AreEqual("exportableModel", paramName);
}
[Test]
@@ -229,7 +229,7 @@
ExportableFailureMechanismSectionCollection>
{
public FailureMechanismSectionCollectionTest() : base(
- (r, e, m) => r.Register(e, m),
+ (r, e, m) => r.Register(m, e),
(r, m) => r.Contains(m),
(r, m) => r.Get(m)) {}
@@ -249,7 +249,7 @@
ExportableFailureMechanismSection>
{
public FailureMechanismSectionTest() : base(
- (r, e, m) => r.Register(e, m),
+ (r, e, m) => r.Register(m, e),
(r, m) => r.Contains(m),
(r, m) => r.Get(m)) {}