Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -rd8f1b2efefe34de39d22a8e7cadbe1953b918c89 -raf9fbea5862083169fd7cf0215b5f10d3cdf57f5 --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision d8f1b2efefe34de39d22a8e7cadbe1953b918c89) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision af9fbea5862083169fd7cf0215b5f10d3cdf57f5) @@ -39,7 +39,6 @@ using Riskeer.Storage.Core.Create.Microstability; using Riskeer.Storage.Core.Create.Piping; using Riskeer.Storage.Core.Create.PipingStructure; -using Riskeer.Storage.Core.Create.SpecificFailurePaths; using Riskeer.Storage.Core.Create.StabilityPointStructures; using Riskeer.Storage.Core.Create.StabilityStoneCover; using Riskeer.Storage.Core.Create.StrengthStabilityLengthwise; Fisheye: Tag af9fbea5862083169fd7cf0215b5f10d3cdf57f5 refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailureMechanismCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailurePathCreateExtensions.cs =================================================================== diff -u --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailurePathCreateExtensions.cs (revision 0) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/FailurePathCreateExtensions.cs (revision af9fbea5862083169fd7cf0215b5f10d3cdf57f5) @@ -0,0 +1,111 @@ +// 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.Util.Extensions; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.FailurePath; +using Riskeer.Integration.Data.FailurePath; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Create +{ + /// + /// Extension methods for related to creating a . + /// + internal static class FailurePathCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The failure mechanism to create a database entity for. + /// The type of the failure mechanism that is being created. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + internal static FailureMechanismEntity Create(this IFailureMechanism mechanism, FailureMechanismType type, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + var entity = Create(mechanism, registry); + entity.FailureMechanismType = (short) type; + entity.CalculationsInputComments = mechanism.CalculationsInputComments.Body.DeepClone(); + + return entity; + } + + /// + /// Creates a based on the information of the . + /// + /// The structure to create a database entity for. + /// The object keeping track of create operations. + /// The index at which resides within its parent. + /// A new . + /// Thrown when is null. + internal static SpecificFailurePathEntity Create(this SpecificFailurePath specificFailurePath, PersistenceRegistry registry, int order) + { + if (registry == null) + { + throw new ArgumentNullException(nameof(registry)); + } + + var entity = Create(specificFailurePath, registry); + entity.Name = specificFailurePath.Name.DeepClone(); + entity.Order = order; + entity.N = specificFailurePath.Input.N; + + return entity; + } + + private static T Create(this IFailurePath failurePath, PersistenceRegistry registry) + where T : IFailurePathEntity, new() + { + FailurePathAssemblyResult assemblyResult = failurePath.AssemblyResult; + var entity = new T + { + InAssembly = Convert.ToByte(failurePath.InAssembly), + InAssemblyInputComments = failurePath.InAssemblyInputComments.Body.DeepClone(), + InAssemblyOutputComments = failurePath.InAssemblyOutputComments.Body.DeepClone(), + NotInAssemblyComments = failurePath.NotInAssemblyComments.Body.DeepClone(), + FailureMechanismSectionCollectionSourcePath = failurePath.FailureMechanismSectionSourcePath.DeepClone(), + FailurePathAssemblyProbabilityResultType = Convert.ToByte(assemblyResult.ProbabilityResultType), + ManualFailurePathAssemblyProbability = assemblyResult.ManualFailurePathAssemblyProbability.ToNaNAsNull() + }; + + AddEntitiesForFailureMechanismSections(failurePath, registry, entity); + + return entity; + } + + private static void AddEntitiesForFailureMechanismSections(this IFailurePath specificFailurePath, + PersistenceRegistry registry, + IFailurePathEntity entity) + { + foreach (FailureMechanismSection failureMechanismSection in specificFailurePath.Sections) + { + entity.FailureMechanismSectionEntities.Add(failureMechanismSection.Create(registry)); + } + } + } +} \ No newline at end of file Fisheye: Tag af9fbea5862083169fd7cf0215b5f10d3cdf57f5 refers to a dead (removed) revision in file `Riskeer/Storage/src/Riskeer.Storage.Core/Create/SpecificFailurePaths/SpecificFailurePathCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag af9fbea5862083169fd7cf0215b5f10d3cdf57f5 refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailureMechanismCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailurePathCreateExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailurePathCreateExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/FailurePathCreateExtensionsTest.cs (revision af9fbea5862083169fd7cf0215b5f10d3cdf57f5) @@ -0,0 +1,313 @@ +// 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 System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.FailurePath; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Integration.Data.FailurePath; +using Riskeer.Storage.Core.Create; +using Riskeer.Storage.Core.DbContext; + +namespace Riskeer.Storage.Core.Test.Create +{ + [TestFixture] + public class FailurePathCreateExtensionsTest + { + # region FailureMechanism + + [Test] + public void CreateForFailureMechanism_PropertiesSet_ReturnExpectedEntity() + { + // Setup + var random = new Random(21); + var failureMechanismType = random.NextEnumValue(); + + var failureMechanism = new TestFailureMechanism + { + InAssembly = random.NextBoolean(), + AssemblyResult = + { + ProbabilityResultType = random.NextEnumValue(), + ManualFailurePathAssemblyProbability = random.NextDouble() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(failureMechanismType, registry); + + // Assert + Assert.AreEqual(Convert.ToByte(failureMechanismType), entity.FailureMechanismType); + + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + + Assert.AreEqual(Convert.ToByte(failureMechanism.InAssembly), entity.InAssembly); + + Assert.IsNull(entity.InAssemblyInputComments); + Assert.IsNull(entity.InAssemblyOutputComments); + Assert.IsNull(entity.NotInAssemblyComments); + + FailurePathAssemblyResult assemblyResult = failureMechanism.AssemblyResult; + Assert.AreEqual(Convert.ToByte(assemblyResult.ProbabilityResultType), entity.FailurePathAssemblyProbabilityResultType); + Assert.AreEqual(assemblyResult.ManualFailurePathAssemblyProbability, entity.ManualFailurePathAssemblyProbability); + } + + [Test] + public void CreateForFailureMechanism_WithNaNValues_ReturnExpectedEntity() + { + // Setup + var random = new Random(21); + var failureMechanismType = random.NextEnumValue(); + + var failureMechanism = new TestFailureMechanism(); + var registry = new PersistenceRegistry(); + + // Precondition + FailurePathAssemblyResult assemblyResult = failureMechanism.AssemblyResult; + Assert.IsNaN(assemblyResult.ManualFailurePathAssemblyProbability); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(failureMechanismType, registry); + + // Assert + Assert.IsNull(entity.ManualFailurePathAssemblyProbability); + } + + [Test] + public void CreateForFailureMechanism_WithSections_ReturnsExpectedEntity() + { + // Setup + var random = new Random(21); + var failureMechanismType = random.NextEnumValue(); + + const string specificFailurePathSectionsSourcePath = "File\\Path"; + var failureMechanism = new TestFailureMechanism(); + + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(0, 0), + new Point2D(1, 0) + }), + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(1, 0), + new Point2D(2, 0) + }) + }, specificFailurePathSectionsSourcePath); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(failureMechanismType, registry); + + // Assert + Assert.AreEqual(failureMechanism.Sections.Count(), entity.FailureMechanismSectionEntities.Count); + } + + [Test] + public void CreateForFailureMechanism_StringPropertiesDoNotShareReference() + { + // Setup + var random = new Random(21); + var failureMechanismType = random.NextEnumValue(); + IFailureMechanism failureMechanism = new TestFailureMechanism("a", "cool") + { + InAssemblyInputComments = + { + Body = "Some input text" + }, + InAssemblyOutputComments = + { + Body = "Some output text" + }, + NotInAssemblyComments = + { + Body = "Really not in assembly" + }, + CalculationsInputComments = + { + Body = "Some calculation text" + } + }; + failureMechanism.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, "File\\Path"); + + var registry = new PersistenceRegistry(); + + // Call + FailureMechanismEntity entity = failureMechanism.Create(failureMechanismType, registry); + + // Assert + TestHelper.AssertAreEqualButNotSame(failureMechanism.InAssemblyInputComments.Body, entity.InAssemblyInputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.InAssemblyOutputComments.Body, entity.InAssemblyOutputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.NotInAssemblyComments.Body, entity.NotInAssemblyComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.CalculationsInputComments.Body, entity.CalculationsInputComments); + TestHelper.AssertAreEqualButNotSame(failureMechanism.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + #endregion + + #region FailurePath + + [Test] + public void CreateForFailurePath_PropertiesSet_ReturnExpectedEntity() + { + // Setup + var random = new Random(21); + int order = random.Next(); + + var failurePath = new SpecificFailurePath + { + Input = + { + N = random.NextRoundedDouble(1, 20) + }, + InAssembly = random.NextBoolean(), + AssemblyResult = + { + ProbabilityResultType = random.NextEnumValue(), + ManualFailurePathAssemblyProbability = random.NextDouble() + } + }; + + var registry = new PersistenceRegistry(); + + // Call + SpecificFailurePathEntity entity = failurePath.Create(registry, order); + + // Assert + Assert.AreEqual(order, entity.Order); + Assert.AreEqual(failurePath.Input.N, entity.N); + + Assert.IsNull(entity.FailureMechanismSectionCollectionSourcePath); + CollectionAssert.IsEmpty(entity.FailureMechanismSectionEntities); + + Assert.AreEqual(Convert.ToByte(failurePath.InAssembly), entity.InAssembly); + + Assert.IsNull(entity.InAssemblyInputComments); + Assert.IsNull(entity.InAssemblyOutputComments); + Assert.IsNull(entity.NotInAssemblyComments); + + FailurePathAssemblyResult assemblyResult = failurePath.AssemblyResult; + Assert.AreEqual(Convert.ToByte(assemblyResult.ProbabilityResultType), entity.FailurePathAssemblyProbabilityResultType); + Assert.AreEqual(assemblyResult.ManualFailurePathAssemblyProbability, entity.ManualFailurePathAssemblyProbability); + } + + [Test] + public void CreateForFailurePath_WithNaNValues_ReturnExpectedEntity() + { + // Setup + var failurePath = new SpecificFailurePath(); + var registry = new PersistenceRegistry(); + + // Precondition + FailurePathAssemblyResult assemblyResult = failurePath.AssemblyResult; + Assert.IsNaN(assemblyResult.ManualFailurePathAssemblyProbability); + + // Call + SpecificFailurePathEntity entity = failurePath.Create(registry, 0); + + // Assert + Assert.IsNull(entity.ManualFailurePathAssemblyProbability); + } + + [Test] + public void CreateForFailurePath_WithSections_ReturnsExpectedEntity() + { + // Setup + const string specificFailurePathSectionsSourcePath = "File\\Path"; + var failurePath = new SpecificFailurePath(); + + failurePath.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(0, 0), + new Point2D(1, 0) + }), + FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] + { + new Point2D(1, 0), + new Point2D(2, 0) + }) + }, specificFailurePathSectionsSourcePath); + + var registry = new PersistenceRegistry(); + + // Call + SpecificFailurePathEntity entity = failurePath.Create(registry, 0); + + // Assert + Assert.AreEqual(failurePath.Sections.Count(), entity.FailureMechanismSectionEntities.Count); + } + + [Test] + public void CreateForFailurePath_StringPropertiesDoNotShareReference() + { + // Setup + var failurePath = new SpecificFailurePath + { + Name = "Just a Name", + InAssemblyInputComments = + { + Body = "Some input text" + }, + InAssemblyOutputComments = + { + Body = "Some output text" + }, + NotInAssemblyComments = + { + Body = "Really not in assembly" + } + }; + failurePath.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, "File\\Path"); + + var registry = new PersistenceRegistry(); + + // Call + SpecificFailurePathEntity entity = failurePath.Create(registry, 0); + + // Assert + TestHelper.AssertAreEqualButNotSame(failurePath.Name, entity.Name); + TestHelper.AssertAreEqualButNotSame(failurePath.InAssemblyInputComments.Body, entity.InAssemblyInputComments); + TestHelper.AssertAreEqualButNotSame(failurePath.InAssemblyOutputComments.Body, entity.InAssemblyOutputComments); + TestHelper.AssertAreEqualButNotSame(failurePath.NotInAssemblyComments.Body, entity.NotInAssemblyComments); + TestHelper.AssertAreEqualButNotSame(failurePath.FailureMechanismSectionSourcePath, entity.FailureMechanismSectionCollectionSourcePath); + } + + #endregion + } +} \ No newline at end of file Fisheye: Tag af9fbea5862083169fd7cf0215b5f10d3cdf57f5 refers to a dead (removed) revision in file `Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/SpecificFailurePaths/SpecificFailurePathCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff?