Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/MacroStabilityInwardsExportRegistry.cs =================================================================== diff -u -r88a3fe63295cecea82c45a8f3b8ec2c8736a8dd9 -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/MacroStabilityInwardsExportRegistry.cs (.../MacroStabilityInwardsExportRegistry.cs) (revision 88a3fe63295cecea82c45a8f3b8ec2c8736a8dd9) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/MacroStabilityInwardsExportRegistry.cs (.../MacroStabilityInwardsExportRegistry.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -32,19 +32,19 @@ internal class MacroStabilityInwardsExportRegistry { private readonly Dictionary settings; - private readonly Dictionary soils; + private readonly Dictionary soils; private readonly Dictionary geometries; - private readonly Dictionary> geometryLayers; + private readonly Dictionary> geometryLayers; /// /// Creates a new instance of . /// public MacroStabilityInwardsExportRegistry() { settings = new Dictionary(); - soils = new Dictionary(); + soils = new Dictionary(); geometries = new Dictionary(); - geometryLayers = new Dictionary>(); + geometryLayers = new Dictionary>(); } /// @@ -55,7 +55,7 @@ /// /// Gets the soils and their unique identifiers. /// - public IReadOnlyDictionary Soils => soils; + public IReadOnlyDictionary Soils => soils; /// /// Gets the geometries and their unique identifiers. @@ -65,7 +65,7 @@ /// /// Gets the geometry layers and their unique identifiers. /// - public IReadOnlyDictionary> GeometryLayers => geometryLayers; + public IReadOnlyDictionary> GeometryLayers => geometryLayers; /// /// Adds calculation settings to the registry. @@ -83,13 +83,13 @@ } /// - /// Adds an to the registry. + /// Adds an to the registry. /// /// The soil layer to register. /// The id of the settings. /// Thrown when /// is null. - public void AddSoil(IMacroStabilityInwardsSoilLayer soilLayer, string id) + public void AddSoil(MacroStabilityInwardsSoilLayer2D soilLayer, string id) { if (soilLayer == null) { @@ -110,7 +110,7 @@ /// has an invalid value. /// Thrown when /// is null. - public void AddGeometryLayer(MacroStabilityInwardsExportStageType stageType, IMacroStabilityInwardsSoilLayer geometryLayer, string id) + public void AddGeometryLayer(MacroStabilityInwardsExportStageType stageType, MacroStabilityInwardsSoilLayer2D geometryLayer, string id) { ValidateStageType(stageType); @@ -121,7 +121,7 @@ if (!geometryLayers.ContainsKey(stageType)) { - geometryLayers.Add(stageType, new Dictionary()); + geometryLayers.Add(stageType, new Dictionary()); } geometryLayers[stageType].Add(geometryLayer, id); Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableGeometryFactory.cs =================================================================== diff -u -r578294f216ecbdd1d6ef1ef8ec5914e793b919c0 -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableGeometryFactory.cs (.../PersistableGeometryFactory.cs) (revision 578294f216ecbdd1d6ef1ef8ec5914e793b919c0) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableGeometryFactory.cs (.../PersistableGeometryFactory.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -20,6 +20,8 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Linq; using Components.Persistence.Stability.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Primitives; @@ -37,10 +39,10 @@ /// The soil profile to use. /// The factory fo IDs. /// The persistence registry. - /// The created . + /// A collection of . /// Thrown when any parameter is null. - public static PersistableGeometry Create(IMacroStabilityInwardsSoilProfile soilProfile, - IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) + public static IEnumerable Create(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, + IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { if (soilProfile == null) { @@ -57,7 +59,41 @@ throw new ArgumentNullException(nameof(registry)); } - return null; + return new[] + { + CreateGeometry(soilProfile, MacroStabilityInwardsExportStageType.Daily, idFactory, registry), + CreateGeometry(soilProfile, MacroStabilityInwardsExportStageType.Extreme, idFactory, registry) + }; } + + private static PersistableGeometry CreateGeometry(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, MacroStabilityInwardsExportStageType stageType, + IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) + { + var geometry = new PersistableGeometry + { + Id = idFactory.Create(), + Layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers) + .Select(l => CreateLayer(l, stageType, idFactory, registry)) + .ToArray() + }; + + registry.AddGeometry(stageType, geometry.Id); + + return geometry; + } + + private static PersistableLayer CreateLayer(MacroStabilityInwardsSoilLayer2D layer, MacroStabilityInwardsExportStageType stageType, + IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) + { + var persistableLayer = new PersistableLayer + { + Id = idFactory.Create(), + Label = layer.Data.MaterialName, + Points = layer.OuterRing.Points.Select(p => new PersistablePoint(p.X, p.Y)).ToArray() + }; + + registry.AddGeometryLayer(stageType, layer, persistableLayer.Id); + return persistableLayer; + } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs =================================================================== diff -u -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs (.../PersistableSoilCollectionFactory.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs (.../PersistableSoilCollectionFactory.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -82,7 +82,7 @@ /// has an invalid value. /// Thrown when /// has a valid value but is not supported. - private static PersistableSoil Create(IMacroStabilityInwardsSoilLayer layer, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) + private static PersistableSoil Create(MacroStabilityInwardsSoilLayer2D layer, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { MacroStabilityInwardsSoilLayerData layerData = layer.Data; Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/MacroStabilityInwardsExportRegistryTest.cs =================================================================== diff -u -r88a3fe63295cecea82c45a8f3b8ec2c8736a8dd9 -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/MacroStabilityInwardsExportRegistryTest.cs (.../MacroStabilityInwardsExportRegistryTest.cs) (revision 88a3fe63295cecea82c45a8f3b8ec2c8736a8dd9) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/MacroStabilityInwardsExportRegistryTest.cs (.../MacroStabilityInwardsExportRegistryTest.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -25,7 +25,7 @@ using System.Linq; using Core.Common.TestUtil; using NUnit.Framework; -using Rhino.Mocks; +using Riskeer.MacroStabilityInwards.Data.TestUtil.SoilProfile; using Riskeer.MacroStabilityInwards.IO.Factories; using Riskeer.MacroStabilityInwards.Primitives; @@ -98,10 +98,8 @@ public void AddSoil_WithSoilLayer_AddsSoilLayer() { // Setup - var mocks = new MockRepository(); - var soilLayer = mocks.Stub(); - mocks.ReplayAll(); - + MacroStabilityInwardsSoilLayer2D soilLayer = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(); + var registry = new MacroStabilityInwardsExportRegistry(); const string id = "1"; @@ -110,7 +108,7 @@ // Assert Assert.AreEqual(1, registry.Soils.Count); - KeyValuePair registeredSoil = registry.Soils.Single(); + KeyValuePair registeredSoil = registry.Soils.Single(); Assert.AreSame(soilLayer, registeredSoil.Key); Assert.AreEqual(id, registeredSoil.Value); } @@ -152,9 +150,7 @@ public void AddGeometryLayer_InvalidStageType_ThrowsInvalidEnumArgumentException() { // Setup - var mocks = new MockRepository(); - var geometryLayer = mocks.Stub(); - mocks.ReplayAll(); + MacroStabilityInwardsSoilLayer2D geometryLayer = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(); var registry = new MacroStabilityInwardsExportRegistry(); const MacroStabilityInwardsExportStageType stageType = (MacroStabilityInwardsExportStageType) 99; @@ -165,7 +161,6 @@ // Assert string expectedMessage = $"The value of argument '{nameof(stageType)}' ({stageType}) is invalid for Enum type '{nameof(MacroStabilityInwardsExportStageType)}'."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); - mocks.VerifyAll(); } [Test] @@ -186,9 +181,7 @@ public void AddGeometryLayer_NewStageType_AddsStageTypeAndGeometryLayer() { // Setup - var mocks = new MockRepository(); - var geometryLayer = mocks.Stub(); - mocks.ReplayAll(); + MacroStabilityInwardsSoilLayer2D geometryLayer = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(); var registry = new MacroStabilityInwardsExportRegistry(); var stageType = new Random(21).NextEnumValue(); @@ -199,11 +192,11 @@ // Assert Assert.AreEqual(1, registry.GeometryLayers.Count); - KeyValuePair> registeredStorageTypeGeometry = registry.GeometryLayers.Single(); + KeyValuePair> registeredStorageTypeGeometry = registry.GeometryLayers.Single(); Assert.AreEqual(stageType, registeredStorageTypeGeometry.Key); Assert.AreEqual(1, registeredStorageTypeGeometry.Value.Count); - KeyValuePair registeredGeometry = registeredStorageTypeGeometry.Value.Single(); + KeyValuePair registeredGeometry = registeredStorageTypeGeometry.Value.Single(); Assert.AreSame(geometryLayer, registeredGeometry.Key); Assert.AreEqual(id, registeredGeometry.Value); @@ -213,10 +206,8 @@ public void AddGeometryLayer_StageTypeAlreadyRegistered_AddsGeometryLayer() { // Setup - var mocks = new MockRepository(); - var geometryLayer1 = mocks.Stub(); - var geometryLayer2 = mocks.Stub(); - mocks.ReplayAll(); + MacroStabilityInwardsSoilLayer2D geometryLayer1 = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(); + MacroStabilityInwardsSoilLayer2D geometryLayer2 = MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(); var registry = new MacroStabilityInwardsExportRegistry(); var stageType = new Random(21).NextEnumValue(); @@ -233,17 +224,17 @@ // Assert Assert.AreEqual(1, registry.GeometryLayers.Count); - KeyValuePair> registeredStageTypeGeometry = registry.GeometryLayers.Single(); + KeyValuePair> registeredStageTypeGeometry = registry.GeometryLayers.Single(); Assert.AreEqual(stageType, registeredStageTypeGeometry.Key); Assert.AreEqual(2, registeredStageTypeGeometry.Value.Count); - Dictionary registeredGeometries = registeredStageTypeGeometry.Value; + Dictionary registeredGeometries = registeredStageTypeGeometry.Value; - KeyValuePair registeredGeometry1 = registeredGeometries.First(); + KeyValuePair registeredGeometry1 = registeredGeometries.First(); Assert.AreSame(geometryLayer1, registeredGeometry1.Key); Assert.AreEqual(id1, registeredGeometry1.Value); - KeyValuePair registeredGeometry2 = registeredGeometries.Last(); + KeyValuePair registeredGeometry2 = registeredGeometries.Last(); Assert.AreSame(geometryLayer2, registeredGeometry2.Key); Assert.AreEqual(id2, registeredGeometry2.Value); } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableGeometryFactoryTest.cs =================================================================== diff -u -r578294f216ecbdd1d6ef1ef8ec5914e793b919c0 -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableGeometryFactoryTest.cs (.../PersistableGeometryFactoryTest.cs) (revision 578294f216ecbdd1d6ef1ef8ec5914e793b919c0) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableGeometryFactoryTest.cs (.../PersistableGeometryFactoryTest.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -20,10 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Linq; using Components.Persistence.Stability.Data; using NUnit.Framework; using Rhino.Mocks; using Riskeer.MacroStabilityInwards.Data.SoilProfile; +using Riskeer.MacroStabilityInwards.Data.TestUtil.SoilProfile; using Riskeer.MacroStabilityInwards.IO.Factories; using Riskeer.MacroStabilityInwards.Primitives; @@ -48,7 +51,7 @@ { // Setup var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); + var soilProfile = mocks.Stub(); mocks.ReplayAll(); // Call @@ -65,7 +68,7 @@ { // Setup var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); + var soilProfile = mocks.Stub(); mocks.ReplayAll(); // Call @@ -81,16 +84,73 @@ public void Create_WithValidData_ReturnsNull() { // Setup - var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); - mocks.ReplayAll(); + var soilProfile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine(new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D() + }) + }, Enumerable.Empty()); + var registry = new MacroStabilityInwardsExportRegistry(); + // Call - PersistableGeometry geometry = PersistableGeometryFactory.Create(soilProfile, new IdFactory(), new MacroStabilityInwardsExportRegistry()); + IEnumerable geometries = PersistableGeometryFactory.Create(soilProfile, new IdFactory(), registry); // Assert - Assert.IsNull(geometry); - mocks.VerifyAll(); + Assert.AreEqual(2, geometries.Count()); + + IEnumerable layersRecursively = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers); + + foreach (PersistableGeometry persistableGeometry in geometries) + { + Assert.IsNotNull(persistableGeometry.Id); + IEnumerable persistableGeometryLayers = persistableGeometry.Layers; + + Assert.AreEqual(layersRecursively.Count(), persistableGeometryLayers.Count()); + + for (int i = 0; i < layersRecursively.Count(); i++) + { + MacroStabilityInwardsSoilLayer2D soilLayer = layersRecursively.ElementAt(i); + PersistableLayer persistableLayer = persistableGeometryLayers.ElementAt(i); + + Assert.IsNotNull(persistableLayer.Id); + Assert.AreEqual(soilLayer.Data.MaterialName, persistableLayer.Label); + + CollectionAssert.AreEqual(soilLayer.OuterRing.Points.Select(p => new PersistablePoint(p.X, p.Y)), persistableLayer.Points); + } + } + + var stageTypes = new[] + { + MacroStabilityInwardsExportStageType.Daily, + MacroStabilityInwardsExportStageType.Extreme + }; + + Assert.AreEqual(stageTypes.Length, registry.Geometries.Count); + Assert.AreEqual(stageTypes.Length, registry.GeometryLayers.Count); + + for (int i = 0; i < stageTypes.Length; i++) + { + KeyValuePair storedGeometry = registry.Geometries.ElementAt(i); + Assert.AreEqual(stageTypes[i], storedGeometry.Key); + Assert.AreEqual(geometries.ElementAt(i).Id, storedGeometry.Value); + + KeyValuePair> storedGeometryLayers = registry.GeometryLayers.ElementAt(i); + + Assert.AreEqual(stageTypes[i], storedGeometryLayers.Key); + + IEnumerable persistableGeometryLayers = geometries.ElementAt(i).Layers; + Assert.AreEqual(persistableGeometryLayers.Count(), storedGeometryLayers.Value.Count); + + for (int j = 0; j < persistableGeometryLayers.Count(); j++) + { + KeyValuePair storedGeometryLayer = storedGeometryLayers.Value.ElementAt(j); + + Assert.AreSame(layersRecursively.ElementAt(j), storedGeometryLayer.Key); + Assert.AreEqual(persistableGeometryLayers.ElementAt(j).Id, storedGeometryLayer.Value); + } + } } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs =================================================================== diff -u -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa -r76b0441378930f0e6052aa3e65332dc23fe4b0be --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs (.../PersistableSoilCollectionFactoryTest.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs (.../PersistableSoilCollectionFactoryTest.cs) (revision 76b0441378930f0e6052aa3e65332dc23fe4b0be) @@ -116,7 +116,7 @@ Assert.AreEqual(actualSoils.Count(), registry.Soils.Count); for (var i = 0; i < originalLayers.Count(); i++) { - KeyValuePair registrySoil = registry.Soils.ElementAt(i); + KeyValuePair registrySoil = registry.Soils.ElementAt(i); Assert.AreSame(originalLayers.ElementAt(i), registrySoil.Key); Assert.AreEqual(actualSoils.ElementAt(i).Id, registrySoil.Value); }