Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs =================================================================== diff -u -re8c997cca0dcf343c4560301921c37791775d88f -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableDataModelFactory.cs (.../PersistableDataModelFactory.cs) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2019. All rights reserved. +// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // @@ -74,8 +74,19 @@ Soils = PersistableSoilCollectionFactory.Create(soilProfile, idFactory, registry), Geometry = PersistableGeometryFactory.Create(soilProfile, idFactory, registry), SoilLayers = PersistableSoilLayerCollectionFactory.Create(soilProfile, idFactory, registry), + Waternets = PersistableWaternetFactory.Create( + DerivedMacroStabilityInwardsInput.GetWaternetDaily(calculation.InputParameters), + DerivedMacroStabilityInwardsInput.GetWaternetExtreme(calculation.InputParameters, GetAssessmentLevel(calculation.InputParameters, getNormativeAssessmentLevelFunc)), + idFactory, registry), Stages = PersistableStageFactory.Create(idFactory, registry) }; } + + private static RoundedDouble GetAssessmentLevel(MacroStabilityInwardsInput input, Func getNormativeAssessmentLevelFunc) + { + return input.UseAssessmentLevelManualInput + ? input.AssessmentLevel + : getNormativeAssessmentLevelFunc(); + } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs =================================================================== diff -u -re8c997cca0dcf343c4560301921c37791775d88f -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs (.../MacroStabilityInwardsCalculationExporterTest.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationExporterTest.cs (.../MacroStabilityInwardsCalculationExporterTest.cs) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -30,6 +30,7 @@ using Riskeer.MacroStabilityInwards.Data.TestUtil; using Riskeer.MacroStabilityInwards.IO.Exporters; using Riskeer.MacroStabilityInwards.IO.TestUtil; +using Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators; namespace Riskeer.MacroStabilityInwards.IO.Test.Exporters { @@ -151,17 +152,20 @@ var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath, AssessmentSectionTestHelper.GetTestAssessmentLevel); - // Call - bool exportResult = exporter.Export(); + using (new MacroStabilityInwardsCalculatorFactoryConfig()) + { + // Call + bool exportResult = exporter.Export(); - // Assert - PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistenceFactory.PersistableDataModel); - Assert.AreEqual(filePath, persistenceFactory.FilePath); + // Assert + PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistenceFactory.PersistableDataModel); + Assert.AreEqual(filePath, persistenceFactory.FilePath); - var persister = (MacroStabilityInwardsTestPersister) persistenceFactory.CreatedPersister; - Assert.IsTrue(persister.PersistCalled); + var persister = (MacroStabilityInwardsTestPersister) persistenceFactory.CreatedPersister; + Assert.IsTrue(persister.PersistCalled); - Assert.IsTrue(exportResult); + Assert.IsTrue(exportResult); + } } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs =================================================================== diff -u -re8c997cca0dcf343c4560301921c37791775d88f -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs (.../PersistableDataModelFactoryTest.cs) (revision e8c997cca0dcf343c4560301921c37791775d88f) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableDataModelFactoryTest.cs (.../PersistableDataModelFactoryTest.cs) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -27,6 +27,7 @@ using Riskeer.MacroStabilityInwards.Data.TestUtil; using Riskeer.MacroStabilityInwards.IO.Factories; using Riskeer.MacroStabilityInwards.IO.TestUtil; +using Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators; namespace Riskeer.MacroStabilityInwards.IO.Test.Factories { @@ -77,11 +78,14 @@ MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput(); - // Call - PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath); + using (new MacroStabilityInwardsCalculatorFactoryConfig()) + { + // Call + PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath); - // Assert - PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel); + // Assert + PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel); + } } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableWaternetFactoryTest.cs =================================================================== diff -u -rd786814eb47687382a96e596b2fc8fa04ccb22f6 -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableWaternetFactoryTest.cs (.../PersistableWaternetFactoryTest.cs) (revision d786814eb47687382a96e596b2fc8fa04ccb22f6) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableWaternetFactoryTest.cs (.../PersistableWaternetFactoryTest.cs) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -26,6 +26,7 @@ using Core.Common.Base.Geometry; using NUnit.Framework; using Riskeer.MacroStabilityInwards.IO.Factories; +using Riskeer.MacroStabilityInwards.IO.TestUtil; using Riskeer.MacroStabilityInwards.Primitives; namespace Riskeer.MacroStabilityInwards.IO.Test.Factories @@ -44,6 +45,7 @@ var exception = Assert.Throws(Call); Assert.AreEqual("dailyWaternet", exception.ParamName); } + [Test] public void Create_ExtremeWaternetNull_ThrowsArgumentNullException() { @@ -100,7 +102,7 @@ { waternetLine1 }); - + var extremeWaternet = new MacroStabilityInwardsWaternet(new[] { phreaticLine2 @@ -116,7 +118,7 @@ IEnumerable persistableWaternets = PersistableWaternetFactory.Create(dailyWaternet, extremeWaternet, idFactory, registry); // Assert - AssertWaternets(new[] + PersistableDataModelTestHelper.AssertWaternets(new[] { dailyWaternet, extremeWaternet @@ -135,49 +137,5 @@ Assert.AreEqual(registry.Waternets[stages[i]], persistableWaternets.ElementAt(i).Id); } } - - private static void AssertWaternets(IEnumerable originalWaternets, IEnumerable actualWaternets) - { - Assert.AreEqual(originalWaternets.Count(), actualWaternets.Count()); - - for (var i = 0; i < originalWaternets.Count(); i++) - { - MacroStabilityInwardsWaternet originalWaternet = originalWaternets.ElementAt(i); - PersistableWaternet actualWaternet = actualWaternets.ElementAt(i); - - Assert.IsNotNull(actualWaternet.Id); - Assert.AreEqual(9.81, actualWaternet.UnitWeightWater); - - PersistableHeadLine firstHeadLine = actualWaternet.HeadLines.First(); - Assert.AreEqual(actualWaternet.PhreaticLineId, firstHeadLine.Id); - - Assert.AreEqual(originalWaternet.PhreaticLines.Count(), actualWaternet.HeadLines.Count()); - - for (var j = 0; j < originalWaternet.PhreaticLines.Count(); j++) - { - MacroStabilityInwardsPhreaticLine phreaticLine = originalWaternet.PhreaticLines.ElementAt(j); - PersistableHeadLine headLine = actualWaternet.HeadLines.ElementAt(j); - - Assert.IsNotNull(headLine.Id); - Assert.AreEqual(phreaticLine.Name, headLine.Label); - CollectionAssert.AreEqual(phreaticLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), headLine.Points); - } - - Assert.AreEqual(originalWaternet.WaternetLines.Count(), actualWaternet.ReferenceLines.Count()); - - for (var j = 0; j < originalWaternet.WaternetLines.Count(); j++) - { - MacroStabilityInwardsWaternetLine waternetLine = originalWaternet.WaternetLines.ElementAt(j); - PersistableReferenceLine referenceLine = actualWaternet.ReferenceLines.ElementAt(j); - - Assert.IsNotNull(referenceLine.Id); - Assert.AreEqual(waternetLine.Name, referenceLine.Label); - CollectionAssert.AreEqual(waternetLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), referenceLine.Points); - - Assert.AreEqual(firstHeadLine.Id, referenceLine.TopHeadLineId); - Assert.AreEqual(firstHeadLine.Id, referenceLine.BottomHeadLineId); - } - } - } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj =================================================================== diff -u -rd786814eb47687382a96e596b2fc8fa04ccb22f6 -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj (.../Riskeer.MacroStabilityInwards.IO.Test.csproj) (revision d786814eb47687382a96e596b2fc8fa04ccb22f6) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Riskeer.MacroStabilityInwards.IO.Test.csproj (.../Riskeer.MacroStabilityInwards.IO.Test.csproj) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -32,6 +32,7 @@ + Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs =================================================================== diff -u -r447cc6c0cd43f48004d67c0ff9e2b7d0bb5a17a4 -rab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs (.../PersistableDataModelTestHelper.cs) (revision 447cc6c0cd43f48004d67c0ff9e2b7d0bb5a17a4) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.TestUtil/PersistableDataModelTestHelper.cs (.../PersistableDataModelTestHelper.cs) (revision ab88ba7ce55a0b63a76889cd3c8fbc133b0d23f6) @@ -27,7 +27,6 @@ using Core.Common.Base.Data; using Core.Common.Util.Reflection; using NUnit.Framework; -using Rhino.Mocks; using Riskeer.Common.Data.Probabilistics; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.SoilProfile; @@ -59,6 +58,11 @@ AssertPersistableSoils(layers, persistableDataModel.Soils.Soils); AssertPersistableGeometry(layers, persistableDataModel.Geometry); AssertPersistableSoilLayers(layers, persistableDataModel.SoilLayers, persistableDataModel.Soils.Soils, persistableDataModel.Geometry); + AssertWaternets(new[] + { + DerivedMacroStabilityInwardsInput.GetWaternetDaily(calculation.InputParameters), + DerivedMacroStabilityInwardsInput.GetWaternetExtreme(calculation.InputParameters, RoundedDouble.NaN) + }, persistableDataModel.Waternets); Assert.IsNull(persistableDataModel.AssessmentResults); Assert.IsNull(persistableDataModel.Decorations); @@ -68,7 +72,6 @@ Assert.IsNull(persistableDataModel.SoilCorrelations); Assert.IsNull(persistableDataModel.SoilVisualizations); Assert.IsNull(persistableDataModel.WaternetCreatorSettings); - Assert.IsNull(persistableDataModel.Waternets); Assert.IsNull(persistableDataModel.StateCorrelations); Assert.IsNull(persistableDataModel.States); @@ -270,6 +273,59 @@ } /// + /// Asserts whether the contains the data + /// that is representative for the . + /// + /// The waternets that contain the original data. + /// The + /// that needs to be asserted. + /// Thrown when the data in + /// is not correct. + public static void AssertWaternets(IEnumerable originalWaternets, IEnumerable actualWaternets) + { + Assert.AreEqual(originalWaternets.Count(), actualWaternets.Count()); + + for (var i = 0; i < originalWaternets.Count(); i++) + { + MacroStabilityInwardsWaternet originalWaternet = originalWaternets.ElementAt(i); + PersistableWaternet actualWaternet = actualWaternets.ElementAt(i); + + Assert.IsNotNull(actualWaternet.Id); + Assert.AreEqual(9.81, actualWaternet.UnitWeightWater); + + PersistableHeadLine firstHeadLine = actualWaternet.HeadLines.First(); + Assert.AreEqual(actualWaternet.PhreaticLineId, firstHeadLine.Id); + + Assert.AreEqual(originalWaternet.PhreaticLines.Count(), actualWaternet.HeadLines.Count()); + + for (var j = 0; j < originalWaternet.PhreaticLines.Count(); j++) + { + MacroStabilityInwardsPhreaticLine phreaticLine = originalWaternet.PhreaticLines.ElementAt(j); + PersistableHeadLine headLine = actualWaternet.HeadLines.ElementAt(j); + + Assert.IsNotNull(headLine.Id); + Assert.AreEqual(phreaticLine.Name, headLine.Label); + CollectionAssert.AreEqual(phreaticLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), headLine.Points); + } + + Assert.AreEqual(originalWaternet.WaternetLines.Count(), actualWaternet.ReferenceLines.Count()); + + for (var j = 0; j < originalWaternet.WaternetLines.Count(); j++) + { + MacroStabilityInwardsWaternetLine waternetLine = originalWaternet.WaternetLines.ElementAt(j); + PersistableReferenceLine referenceLine = actualWaternet.ReferenceLines.ElementAt(j); + + Assert.IsNotNull(referenceLine.Id); + Assert.AreEqual(waternetLine.Name, referenceLine.Label); + CollectionAssert.AreEqual(waternetLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), referenceLine.Points); + + Assert.AreEqual(firstHeadLine.Id, referenceLine.TopHeadLineId); + Assert.AreEqual(firstHeadLine.Id, referenceLine.BottomHeadLineId); + } + } + } + + /// /// Asserts whether the contains the correct data. /// /// The stages that needs to be asserted.