Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs =================================================================== diff -u -r8baf1e4a72fd086748259c63e6f40f5d8de021e0 -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision 8baf1e4a72fd086748259c63e6f40f5d8de021e0) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) @@ -59,7 +59,7 @@ { Info = PersistableProjectInfoFactory.Create(calculation, filePath), CalculationSettings = PersistableCalculationSettingsFactory.Create(calculation.Output.SlidingCurve, idFactory, registry), - Soils = PersistableSoilCollectionFactory.Create(calculation.InputParameters.StochasticSoilProfile.SoilProfile, idFactory, registry), + Soils = PersistableSoilCollectionFactory.Create(calculation.InputParameters.SoilProfileUnderSurfaceLine, idFactory, registry), Stages = PersistableStageFactory.Create(idFactory, registry) }; } Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs =================================================================== diff -u -ra0c97ea29e472f4e4cdba4100ed2190f97fbb236 -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs (.../PersistableSoilCollectionFactory.cs) (revision a0c97ea29e472f4e4cdba4100ed2190f97fbb236) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableSoilCollectionFactory.cs (.../PersistableSoilCollectionFactory.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Components.Persistence.Stability.Data; @@ -46,13 +45,9 @@ /// Thrown when any parameter is null. /// Thrown when /// has an invalid value. - /// Thrown when: - /// - /// has a valid value but is not supported; - /// The given type is not supported. - /// - /// - public static PersistableSoilCollection Create(IMacroStabilityInwardsSoilProfile soilProfile, + /// Thrown when + /// has a valid value but is not supported. + public static PersistableSoilCollection Create(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { if (soilProfile == null) @@ -72,35 +67,11 @@ return new PersistableSoilCollection { - Soils = GetLayers(soilProfile).Select(l => Create(l, idFactory, registry)).ToArray() + Soils = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers).Select(l => Create(l, idFactory, registry)).ToArray() }; } /// - /// Gets all the layers within . - /// - /// The to get the layers from. - /// All layers from . - /// Thrown when the given type - /// is not supported. - private static IEnumerable GetLayers(IMacroStabilityInwardsSoilProfile soilProfile) - { - if (soilProfile is MacroStabilityInwardsSoilProfile1D soilProfile1D) - { - return soilProfile1D.Layers; - } - - if (soilProfile is MacroStabilityInwardsSoilProfile2D soilProfile2D) - { - return MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile2D.Layers); - } - - throw new NotSupportedException($"{soilProfile.GetType().Name} is not supported. " + - $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} " + - $"and {nameof(MacroStabilityInwardsSoilProfile2D)}."); - } - - /// /// Creates a new instance of . /// /// The layer to use. Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs =================================================================== diff -u -r8baf1e4a72fd086748259c63e6f40f5d8de021e0 -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs (.../PersistableSoilCollectionFactoryTest.cs) (revision 8baf1e4a72fd086748259c63e6f40f5d8de021e0) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableSoilCollectionFactoryTest.cs (.../PersistableSoilCollectionFactoryTest.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) @@ -55,7 +55,7 @@ { // Setup var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); + var soilProfile = mocks.Stub(); mocks.ReplayAll(); // Call @@ -72,7 +72,7 @@ { // Setup var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); + var soilProfile = mocks.Stub(); mocks.ReplayAll(); // Call @@ -85,62 +85,22 @@ } [Test] - public void Create_WithISoilProfile_ThrowsNotSupportedException() - { - // Setup - var mocks = new MockRepository(); - var soilProfile = mocks.Stub>(); - mocks.ReplayAll(); - - // Call - void Call() => PersistableSoilCollectionFactory.Create(soilProfile, new IdFactory(), new MacroStabilityInwardsExportRegistry()); - - // Assert - var exception = Assert.Throws(Call); - string expectedMessage = $"{soilProfile.GetType().Name} is not supported. " + - $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} " + - $"and {nameof(MacroStabilityInwardsSoilProfile2D)}."; - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] [TestCase(MacroStabilityInwardsShearStrengthModel.CPhi)] [TestCase(MacroStabilityInwardsShearStrengthModel.SuCalculated)] [TestCase(MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)] - public void Create_WithSoilProfile1D_ReturnsPersistableSoilCollection(MacroStabilityInwardsShearStrengthModel shearStrengthModel) + public void Create_WithSoilProfile_ReturnsPersistableSoilCollection(MacroStabilityInwardsShearStrengthModel shearStrengthModel) { // Setup - MacroStabilityInwardsSoilProfile1D soilProfile = MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(); - var registry = new MacroStabilityInwardsExportRegistry(); + var soilProfile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine( + new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D() + }) + }, + Enumerable.Empty()); - IEnumerable originalLayers = soilProfile.Layers; - originalLayers.ForEachElementDo(layer => layer.Data.ShearStrengthModel = shearStrengthModel); - - // Call - PersistableSoilCollection soilCollection = PersistableSoilCollectionFactory.Create(soilProfile, new IdFactory(), registry); - - // Assert - IEnumerable actualSoils = soilCollection.Soils; - PersistableDataModelTestHelper.AssertPersistableSoils(originalLayers, actualSoils); - - Assert.AreEqual(actualSoils.Count(), registry.Soils.Count); - for (var i = 0; i < originalLayers.Count(); i++) - { - KeyValuePair registrySoil = registry.Soils.ElementAt(i); - Assert.AreSame(originalLayers.ElementAt(i), registrySoil.Key); - Assert.AreEqual(actualSoils.ElementAt(i).Id, registrySoil.Value); - } - } - - [Test] - [TestCase(MacroStabilityInwardsShearStrengthModel.CPhi)] - [TestCase(MacroStabilityInwardsShearStrengthModel.SuCalculated)] - [TestCase(MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)] - public void Create_WithSoilProfile2D_ReturnsPersistableSoilCollection(MacroStabilityInwardsShearStrengthModel shearStrengthModel) - { - // Setup - MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(); - var soilProfile = (MacroStabilityInwardsSoilProfile2D) stochasticSoilProfile.SoilProfile; var registry = new MacroStabilityInwardsExportRegistry(); IEnumerable originalLayers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers); @@ -166,9 +126,13 @@ public void Create_InvalidShearStrengthType_ThrowsInvalidEnumArgumentException() { // Setup - MacroStabilityInwardsSoilProfile2D soilProfile = MacroStabilityInwardsSoilProfile2DTestFactory.CreateMacroStabilityInwardsSoilProfile2D(); var registry = new MacroStabilityInwardsExportRegistry(); - + var soilProfile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine( + new[] + { + MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D() + }, + Enumerable.Empty()); const MacroStabilityInwardsShearStrengthModel shearStrengthModel = (MacroStabilityInwardsShearStrengthModel) 99; soilProfile.Layers.First().Data.ShearStrengthModel = shearStrengthModel; Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs =================================================================== diff -u -rc00ecb71ceaf0b272b37a785749105fbb5e69512 -r6f35b734a38f9ef796e4a85d0ac37f5e319013fa --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs (.../PersistableDataModelTestHelper.cs) (revision c00ecb71ceaf0b272b37a785749105fbb5e69512) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs (.../PersistableDataModelTestHelper.cs) (revision 6f35b734a38f9ef796e4a85d0ac37f5e319013fa) @@ -29,6 +29,7 @@ using NUnit.Framework; using Riskeer.Common.Data.Probabilistics; using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Primitives; namespace Riskeer.MacroStabilityInwards.IO.TestUtil @@ -52,7 +53,7 @@ { AssertProjectInfo(calculation, filePath, persistableDataModel.Info); AssertCalculationSettings(calculation.Output.SlidingCurve, persistableDataModel.CalculationSettings); - AssertPersistableSoils(calculation.InputParameters.StochasticSoilProfile.SoilProfile.Layers, persistableDataModel.Soils.Soils); + AssertPersistableSoils(MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(calculation.InputParameters.SoilProfileUnderSurfaceLine.Layers), persistableDataModel.Soils.Soils); Assert.IsNull(persistableDataModel.AssessmentResults); Assert.IsNull(persistableDataModel.Decorations);