Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs =================================================================== diff -u -r30838125aace7156cc54dde0f78751a654bfe620 -rcd9917aa7aad303a58eae5ca1fac7e4ac7e54ded --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision 30838125aace7156cc54dde0f78751a654bfe620) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismEntityReadExtensions.cs (.../FailureMechanismEntityReadExtensions.cs) (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -77,6 +77,7 @@ failureMechanism.NotInAssemblyComments.Body = entity.NotInAssemblyComments; entity.ReadFailureMechanismSections(failureMechanism, collector); + entity.Read(failureMechanism.AssemblyResult); } private static void ReadFailureMechanismSections(this FailureMechanismEntity entity, Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailurePathAssemblyResultEntityReadExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailurePathAssemblyResultEntityReadExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailurePathAssemblyResultEntityReadExtensions.cs (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -0,0 +1,61 @@ +// Copyright (C) Stichting Deltares 2021. 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 Riskeer.Common.Data.FailurePath; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Read +{ + /// + /// This class defines extension methods for read operations for a based on the + /// + /// + internal static class FailurePathAssemblyResultEntityReadExtensions + { + /// + /// Reads the and uses the information to update the . + /// + /// The to update + /// for. + /// The to update. + /// Thrown when any argument is null. + internal static void Read(this IHasFailurePathAssemblyResultEntity entity, + FailurePathAssemblyResult assemblyResult) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (assemblyResult == null) + { + throw new ArgumentNullException(nameof(assemblyResult)); + } + + assemblyResult.ProbabilityResultType = (FailurePathAssemblyProbabilityResultType) entity.FailurePathAssemblyProbabilityResultType; + if (entity.ManualFailurePathAssemblyProbability != null) + { + assemblyResult.ManualFailurePathAssemblyProbability = entity.ManualFailurePathAssemblyProbability.ToNullAsNaN(); + } + } + } +} \ No newline at end of file Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs =================================================================== diff -u -r01121f7e340c29f7a9fab9e02c8a368ad8717ea5 -rcd9917aa7aad303a58eae5ca1fac7e4ac7e54ded --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs (.../SpecificFailurePathEntityReadExtensions.cs) (revision 01121f7e340c29f7a9fab9e02c8a368ad8717ea5) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs (.../SpecificFailurePathEntityReadExtensions.cs) (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -71,6 +71,7 @@ entity.ReadFailureMechanismSections(specificFailurePath, collector); entity.ReadGeneralInput(specificFailurePath); + entity.Read(specificFailurePath.AssemblyResult); return specificFailurePath; } Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs =================================================================== diff -u -rdb15bf304b75a679169834c323cd2cbc97eaf83f -rcd9917aa7aad303a58eae5ca1fac7e4ac7e54ded --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (.../FailureMechanismEntityReadExtensionsTest.cs) (revision db15bf304b75a679169834c323cd2cbc97eaf83f) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismEntityReadExtensionsTest.cs (.../FailureMechanismEntityReadExtensionsTest.cs) (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -31,6 +31,7 @@ using Riskeer.Common.Data; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailurePath; using Riskeer.Common.Data.Structures; using Riskeer.Common.Data.TestUtil; using Riskeer.DuneErosion.Data; @@ -60,16 +61,21 @@ [Test] [TestCase(true)] [TestCase(false)] - public void ReadAsStandAloneFailureMechanism_WithoutSectionsSet_ReturnsNewStandAloneFailureMechanism(bool inAssembly) + public void ReadCommonFailureMechanismProperties_WithoutSectionsSet_ReturnsNewStandAloneFailureMechanism(bool inAssembly) { // Setup + var random = new Random(21); + var assemblyResultType = random.NextEnumValue(); + var entity = new FailureMechanismEntity { InAssembly = Convert.ToByte(inAssembly), InAssemblyInputComments = "Some input text", InAssemblyOutputComments = "Some output text", CalculationsInputComments = "Some calculation text", - NotInAssemblyComments = "Really not in assembly" + NotInAssemblyComments = "Really not in assembly", + FailurePathAssemblyProbabilityResultType = Convert.ToByte(assemblyResultType), + ManualFailurePathAssemblyProbability = random.NextDouble() }; var collector = new ReadConversionCollector(); var failureMechanism = new TestFailureMechanism(); @@ -86,12 +92,38 @@ Assert.AreEqual(entity.CalculationsInputComments, failureMechanism.CalculationsInputComments.Body); CollectionAssert.IsEmpty(failureMechanism.Sections); Assert.IsNull(failureMechanism.FailureMechanismSectionSourcePath); + + FailurePathAssemblyResult assemblyResult = failureMechanism.AssemblyResult; + Assert.AreEqual(assemblyResultType, assemblyResult.ProbabilityResultType); + Assert.AreEqual(entity.ManualFailurePathAssemblyProbability, assemblyResult.ManualFailurePathAssemblyProbability); } [Test] - public void ReadAsStandAloneFailureMechanism_WithSectionsSet_ReturnsNewStandAloneFailureMechanismWithFailureMechanismSections() + public void ReadCommonFailureMechanismProperties_WithNullValues_ReturnsNewStandAloneFailureMechanism() { // Setup + var entity = new FailureMechanismEntity(); + var collector = new ReadConversionCollector(); + var failureMechanism = new TestFailureMechanism(); + + // Call + entity.ReadCommonFailureMechanismProperties(failureMechanism, collector); + + // Assert + Assert.IsNull(failureMechanism.InAssemblyInputComments.Body); + Assert.IsNull(failureMechanism.InAssemblyOutputComments.Body); + Assert.IsNull(failureMechanism.NotInAssemblyComments.Body); + Assert.IsNull(failureMechanism.CalculationsInputComments.Body); + CollectionAssert.IsEmpty(failureMechanism.Sections); + Assert.IsNull(failureMechanism.FailureMechanismSectionSourcePath); + + Assert.IsNaN(failureMechanism.AssemblyResult.ManualFailurePathAssemblyProbability); + } + + [Test] + public void ReadCommonFailureMechanismProperties_WithSectionsSet_ReturnsNewStandAloneFailureMechanismWithFailureMechanismSections() + { + // Setup const string filePath = "failureMechanismSections/File/Path"; var entity = new FailureMechanismEntity { Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailurePathAssemblyResultEntityReadExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailurePathAssemblyResultEntityReadExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailurePathAssemblyResultEntityReadExtensionsTest.cs (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -0,0 +1,92 @@ +// Copyright (C) Stichting Deltares 2021. 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 Rhino.Mocks; +using Riskeer.Common.Data.FailurePath; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; + +namespace Riskeer.Storage.Core.Test.Read +{ + [TestFixture] + public class FailurePathAssemblyResultEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Setup + var assemblyResult = new FailurePathAssemblyResult(); + + // Call + void Call() => ((IHasFailurePathAssemblyResultEntity) null).Read(assemblyResult); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_AssemblyResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => entity.Read(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assemblyResult", exception.ParamName); + + mocks.VerifyAll(); + } + + [Test] + public void Read_EntityWithValues_SetsAssemblyResult() + { + // Setup + var random = new Random(21); + var resultType = random.NextEnumValue(); + double probability = random.NextDouble(); + + var mocks = new MockRepository(); + var entity = mocks.Stub(); + mocks.ReplayAll(); + + entity.FailurePathAssemblyProbabilityResultType = Convert.ToByte(resultType); + entity.ManualFailurePathAssemblyProbability = probability; + + var assemblyResult = new FailurePathAssemblyResult(); + + // Call + entity.Read(assemblyResult); + + // Assert + Assert.AreEqual(resultType, assemblyResult.ProbabilityResultType); + Assert.AreEqual(probability, assemblyResult.ManualFailurePathAssemblyProbability); + } + } +} \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs =================================================================== diff -u -r29a2a01ec27ecb60b080d13dd73f53c7a31563d6 -rcd9917aa7aad303a58eae5ca1fac7e4ac7e54ded --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs (.../SpecificFailurePathEntityReadExtensionsTest.cs) (revision 29a2a01ec27ecb60b080d13dd73f53c7a31563d6) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs (.../SpecificFailurePathEntityReadExtensionsTest.cs) (revision cd9917aa7aad303a58eae5ca1fac7e4ac7e54ded) @@ -24,6 +24,7 @@ using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; +using Riskeer.Common.Data.FailurePath; using Riskeer.Common.Data.TestUtil; using Riskeer.Integration.Data.FailurePath; using Riskeer.Storage.Core.DbContext; @@ -56,6 +57,8 @@ // Setup var random = new Random(21); bool inAssembly = random.NextBoolean(); + var probabilityResultType = random.NextEnumValue(); + const string filePath = "failureMechanismSections/File/Path"; var entity = new SpecificFailurePathEntity { @@ -66,6 +69,8 @@ InAssemblyOutputComments = "Some output text", NotInAssemblyComments = "Some not in assembly text", FailureMechanismSectionCollectionSourcePath = filePath, + FailurePathAssemblyProbabilityResultType = Convert.ToByte(probabilityResultType), + ManualFailurePathAssemblyProbability = random.NextDouble(), FailureMechanismSectionEntities = { CreateSimpleFailureMechanismSectionEntity() @@ -87,9 +92,31 @@ Assert.AreEqual(filePath, specificFailurePath.FailureMechanismSectionSourcePath); Assert.AreEqual(entity.N, specificFailurePath.Input.N, specificFailurePath.Input.N.GetAccuracy()); + + FailurePathAssemblyResult assemblyResult = specificFailurePath.AssemblyResult; + Assert.AreEqual(probabilityResultType, assemblyResult.ProbabilityResultType); + Assert.AreEqual(entity.ManualFailurePathAssemblyProbability, assemblyResult.ManualFailurePathAssemblyProbability); } [Test] + public void Read_EntityWithNullValues_ReturnSpecificFailurePath() + { + // Setup + var entity = new SpecificFailurePathEntity + { + N = 1.1 + }; + var collector = new ReadConversionCollector(); + + // Call + SpecificFailurePath specificFailurePath = entity.Read(collector); + + // Assert + FailurePathAssemblyResult assemblyResult = specificFailurePath.AssemblyResult; + Assert.IsNaN(assemblyResult.ManualFailurePathAssemblyProbability); + } + + [Test] public void Read_ValidEntityWithoutSections_ReturnSpecificFailurePath() { // Setup