Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensions.cs
===================================================================
diff -u
--- Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensions.cs (revision 0)
+++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensions.cs (revision ce5758827ba1ce9f9aac02ea53d1c6d831d48450)
@@ -0,0 +1,59 @@
+// 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.FailureMechanism;
+using Riskeer.Storage.Core.DbContext;
+
+namespace Riskeer.Storage.Core.Create.FailureMechanismSectionResults
+{
+ ///
+ /// Extension methods for related to creating an
+ /// instance of .
+ ///
+ internal static class NonAdoptableFailureMechanismSectionResultCreateExtensions
+ {
+ ///
+ /// Creates an instance of
+ /// based on the information of the .
+ ///
+ /// The type of to create.
+ /// The result to create a database entity for.
+ /// An instance of .
+ /// Thrown when is null.
+ internal static T Create(this NonAdoptableFailureMechanismSectionResult result) where T : INonAdoptableFailureMechanismSectionResultEntity, new()
+ {
+ if (result == null)
+ {
+ throw new ArgumentNullException(nameof(result));
+ }
+
+ return new T
+ {
+ IsRelevant = Convert.ToByte(result.IsRelevant),
+ NonAdoptableInitialFailureMechanismResultType = Convert.ToByte(result.InitialFailureMechanismResult),
+ ManualInitialFailureMechanismResultSectionProbability = result.ManualInitialFailureMechanismResultSectionProbability.ToNaNAsNull(),
+ FurtherAnalysisNeeded = Convert.ToByte(result.FurtherAnalysisNeeded),
+ RefinedSectionProbability = result.RefinedSectionProbability.ToNaNAsNull()
+ };
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensions.cs
===================================================================
diff -u
--- Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensions.cs (revision 0)
+++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensions.cs (revision ce5758827ba1ce9f9aac02ea53d1c6d831d48450)
@@ -0,0 +1,62 @@
+// 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.FailureMechanism;
+using Riskeer.Storage.Core.DbContext;
+
+namespace Riskeer.Storage.Core.Read.FailureMechanismSectionResults
+{
+ ///
+ /// This class defines extension methods for read operations for an
+ /// based on the .
+ ///
+ internal static class NonAdoptableFailureMechanismSectionResultEntityReadExtensions
+ {
+ ///
+ /// Reads the and use the information
+ /// to update an .
+ ///
+ /// The used to update
+ /// the .
+ /// The target of the read operation.
+ /// Thrown when any input parameter is null.
+ internal static void Read(this INonAdoptableFailureMechanismSectionResultEntity entity,
+ NonAdoptableFailureMechanismSectionResult sectionResult)
+ {
+ if (entity == null)
+ {
+ throw new ArgumentNullException(nameof(entity));
+ }
+
+ if (sectionResult == null)
+ {
+ throw new ArgumentNullException(nameof(sectionResult));
+ }
+
+ sectionResult.IsRelevant = Convert.ToBoolean(entity.IsRelevant);
+ sectionResult.InitialFailureMechanismResult = (NonAdoptableInitialFailureMechanismResultType) entity.NonAdoptableInitialFailureMechanismResultType;
+ sectionResult.ManualInitialFailureMechanismResultSectionProbability = entity.ManualInitialFailureMechanismResultSectionProbability.ToNullAsNaN();
+ sectionResult.FurtherAnalysisNeeded = Convert.ToBoolean(entity.FurtherAnalysisNeeded);
+ sectionResult.RefinedSectionProbability = entity.RefinedSectionProbability.ToNullAsNaN();
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensionsTest.cs
===================================================================
diff -u
--- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensionsTest.cs (revision 0)
+++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultCreateExtensionsTest.cs (revision ce5758827ba1ce9f9aac02ea53d1c6d831d48450)
@@ -0,0 +1,95 @@
+// 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 Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Storage.Core.Create.FailureMechanismSectionResults;
+using Riskeer.Storage.Core.TestUtil.FailureMechanismResults;
+
+namespace Riskeer.Storage.Core.Test.Create.FailureMechanismSectionResults
+{
+ [TestFixture]
+ public class NonAdoptableFailureMechanismSectionResultCreateExtensionsTest
+ {
+ [Test]
+ public void Create_FailureMechanismSectionResultNull_ThrowsArgumentNullException()
+ {
+ // Call
+ void Call() => ((NonAdoptableFailureMechanismSectionResult) null).Create();
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("result", exception.ParamName);
+ }
+
+ [Test]
+ public void Create_SectionResultWithValues_ReturnsEntityWithExpectedValues()
+ {
+ // Setup
+ var random = new Random(21);
+ bool isRelevant = random.NextBoolean();
+ var initialFailureMechanismResultType = random.NextEnumValue();
+ double manualSectionProbability = random.NextDouble();
+ bool furtherAnalysisNeeded = random.NextBoolean();
+ double refinedSectionProbability = random.NextDouble();
+
+ var sectionResult = new NonAdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ {
+ IsRelevant = isRelevant,
+ InitialFailureMechanismResult = initialFailureMechanismResultType,
+ ManualInitialFailureMechanismResultSectionProbability = manualSectionProbability,
+ FurtherAnalysisNeeded = furtherAnalysisNeeded,
+ RefinedSectionProbability = refinedSectionProbability
+ };
+
+ // Call
+ var entity = sectionResult.Create();
+
+ // Assert
+ Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant);
+ Assert.AreEqual(Convert.ToByte(initialFailureMechanismResultType), entity.NonAdoptableInitialFailureMechanismResultType);
+ Assert.AreEqual(manualSectionProbability, entity.ManualInitialFailureMechanismResultSectionProbability);
+ Assert.AreEqual(Convert.ToByte(furtherAnalysisNeeded), entity.FurtherAnalysisNeeded);
+ Assert.AreEqual(refinedSectionProbability, entity.RefinedSectionProbability);
+ }
+
+ [Test]
+ public void Create_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults()
+ {
+ // Setup
+ var sectionResult = new NonAdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
+ {
+ ManualInitialFailureMechanismResultSectionProbability = double.NaN,
+ RefinedSectionProbability = double.NaN
+ };
+
+ // Call
+ var entity = sectionResult.Create();
+
+ // Assert
+ Assert.IsNull(entity.ManualInitialFailureMechanismResultSectionProbability);
+ Assert.IsNull(entity.RefinedSectionProbability);
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensionsTest.cs
===================================================================
diff -u
--- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensionsTest.cs (revision 0)
+++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/FailureMechanismSectionResults/NonAdoptableFailureMechanismSectionResultEntityReadExtensionsTest.cs (revision ce5758827ba1ce9f9aac02ea53d1c6d831d48450)
@@ -0,0 +1,108 @@
+// 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 Riskeer.Common.Data.FailureMechanism;
+using Riskeer.Common.Data.TestUtil;
+using Riskeer.Storage.Core.Read.FailureMechanismSectionResults;
+using Riskeer.Storage.Core.TestUtil.FailureMechanismResults;
+
+namespace Riskeer.Storage.Core.Test.Read.FailureMechanismSectionResults
+{
+ [TestFixture]
+ public class NonAdoptableFailureMechanismSectionResultEntityReadExtensionsTest
+ {
+ [Test]
+ public void Read_EntityNull_ThrowsArgumentNullException()
+ {
+ // Call
+ void Call() => ((TestNonAdoptableFailureMechanismSectionResultEntity) null).Read(new NonAdoptableFailureMechanismSectionResult(
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()));
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("entity", exception.ParamName);
+ }
+
+ [Test]
+ public void Read_SectionResultNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var entity = new TestNonAdoptableFailureMechanismSectionResultEntity();
+
+ // Call
+ void Call() => entity.Read(null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("sectionResult", exception.ParamName);
+ }
+
+ [Test]
+ public void Read_ParameterValues_SectionResultWithParameterValues()
+ {
+ // Setup
+ var random = new Random(21);
+ bool isRelevant = random.NextBoolean();
+ var initialFailureMechanismResultType = random.NextEnumValue();
+ double manualSectionProbability = random.NextDouble();
+ bool furtherAnalysisNeeded = random.NextBoolean();
+ double refinedSectionProbability = random.NextDouble();
+
+ var entity = new TestNonAdoptableFailureMechanismSectionResultEntity
+ {
+ IsRelevant = Convert.ToByte(isRelevant),
+ NonAdoptableInitialFailureMechanismResultType = Convert.ToByte(initialFailureMechanismResultType),
+ ManualInitialFailureMechanismResultSectionProbability = manualSectionProbability,
+ FurtherAnalysisNeeded = Convert.ToByte(furtherAnalysisNeeded),
+ RefinedSectionProbability = refinedSectionProbability
+ };
+ var sectionResult = new NonAdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());
+
+ // Call
+ entity.Read(sectionResult);
+
+ // Assert
+ Assert.AreEqual(isRelevant, sectionResult.IsRelevant);
+ Assert.AreEqual(initialFailureMechanismResultType, sectionResult.InitialFailureMechanismResult);
+ Assert.AreEqual(manualSectionProbability, sectionResult.ManualInitialFailureMechanismResultSectionProbability);
+ Assert.AreEqual(furtherAnalysisNeeded, sectionResult.FurtherAnalysisNeeded);
+ Assert.AreEqual(refinedSectionProbability, sectionResult.RefinedSectionProbability);
+ }
+
+ [Test]
+ public void Read_EntityWithNullValues_SectionResultWithNaNValues()
+ {
+ // Setup
+ var entity = new TestNonAdoptableFailureMechanismSectionResultEntity();
+ var sectionResult = new NonAdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());
+
+ // Call
+ entity.Read(sectionResult);
+
+ // Assert
+ Assert.IsNaN(sectionResult.ManualInitialFailureMechanismResultSectionProbability);
+ Assert.IsNaN(sectionResult.RefinedSectionProbability);
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/FailureMechanismResults/TestNonAdoptableFailureMechanismSectionResultEntity.cs
===================================================================
diff -u
--- Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/FailureMechanismResults/TestNonAdoptableFailureMechanismSectionResultEntity.cs (revision 0)
+++ Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/FailureMechanismResults/TestNonAdoptableFailureMechanismSectionResultEntity.cs (revision ce5758827ba1ce9f9aac02ea53d1c6d831d48450)
@@ -0,0 +1,37 @@
+// 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 Riskeer.Storage.Core.DbContext;
+
+namespace Riskeer.Storage.Core.TestUtil.FailureMechanismResults
+{
+ ///
+ /// Simple implementation of that can be used in tests.
+ ///
+ public class TestNonAdoptableFailureMechanismSectionResultEntity : INonAdoptableFailureMechanismSectionResultEntity
+ {
+ public byte IsRelevant { get; set; }
+ public byte NonAdoptableInitialFailureMechanismResultType { get; set; }
+ public double? ManualInitialFailureMechanismResultSectionProbability { get; set; }
+ public byte FurtherAnalysisNeeded { get; set; }
+ public double? RefinedSectionProbability { get; set; }
+ }
+}
\ No newline at end of file