Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -ra14245a5852a6fbbad03780a33599ff8e365f84b -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision a14245a5852a6fbbad03780a33599ff8e365f84b) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -72,7 +72,7 @@ - + Fisheye: Tag 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Application.Ringtoets.Storage.DbContext; +using Core.Common.Utils.Extensions; +using Ringtoets.Common.Data.IllustrationPoints; + +namespace Application.Ringtoets.Storage.Create.IllustrationPoints +{ + /// + /// Extension methods for + /// related to creating an instance of . + /// + internal static class IllustrationPointNodeCreateExtensions + { + /// + /// Creates a based on the information + /// of . + /// + /// The illustration point node to create a database + /// entity for. + /// The index at which + /// resides within its parent. + /// A new . + /// Thrown when + /// is null. + /// Thrown when + /// is not of type . + public static FaultTreeIllustrationPointEntity Create( + this IllustrationPointNode illustrationPointNode, + int order) + { + if (illustrationPointNode == null) + { + throw new ArgumentNullException(nameof(illustrationPointNode)); + } + + IllustrationPointBase illustrationPoint = illustrationPointNode.Data; + IllustrationPointNode[] children = illustrationPointNode.Children.ToArray(); + + var faultTreeIllustrationPoint = illustrationPoint as FaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint == null) + { + throw new InvalidOperationException($"Illustration point type '{illustrationPoint.GetType()}' is not supported."); + } + + FaultTreeIllustrationPointEntity entity = CreateFaultTreeIllustrationPoint(faultTreeIllustrationPoint, order); + CreateChildElements(children, entity); + return entity; + } + + private static FaultTreeIllustrationPointEntity CreateFaultTreeIllustrationPoint( + FaultTreeIllustrationPoint illustrationPoint, + int order) + { + var entity = new FaultTreeIllustrationPointEntity + { + Beta = illustrationPoint.Beta, + CombinationType = Convert.ToByte(illustrationPoint.CombinationType), + Name = illustrationPoint.Name.DeepClone(), + Order = order + }; + + return entity; + } + + private static void CreateChildElements(IllustrationPointNode[] illustrationPointNodes, + FaultTreeIllustrationPointEntity entity) + { + for (var i = 0; i < illustrationPointNodes.Length; i++) + { + IllustrationPointNode node = illustrationPointNodes[0]; + + var faultTreeIllustrationPoint = node.Data as FaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint != null) + { + entity.FaultTreeIllustrationPointEntity1.Add(node.Create(i + 1)); + } + + var subMechanismIllustrationPoint = node.Data as SubMechanismIllustrationPoint; + if (subMechanismIllustrationPoint != null) + { + entity.SubMechanismIllustrationPointEntities.Add(subMechanismIllustrationPoint.Create()); + } + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs =================================================================== diff -u -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs (.../TopLevelFaultTreeIllustrationPointCreateExtensions.cs) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs (.../TopLevelFaultTreeIllustrationPointCreateExtensions.cs) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -58,6 +58,8 @@ ClosingSituation = topLevelFaultTreeIllustrationPoint.ClosingSituation.DeepClone(), WindDirectionName = windDirection.Name.DeepClone(), WindDirectionAngle = windDirection.Angle, + FaultTreeIllustrationPointEntity = + topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot.Create(0), Order = order }; } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -90,7 +90,7 @@ - + Fisheye: Tag 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs =================================================================== diff -u -ra14245a5852a6fbbad03780a33599ff8e365f84b -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (.../GeneralResultCreateExtensionsTest.cs) (revision a14245a5852a6fbbad03780a33599ff8e365f84b) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (.../GeneralResultCreateExtensionsTest.cs) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -173,35 +173,6 @@ AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity); } - [Test] - public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralWithIllustrationPoints_ReturnsEntityWithTopLevelFaultTreeIllustrationPointEntities() - { - // Setup - var random = new Random(22); - - var generalResult = new GeneralResult( - new WindDirection("SSE", random.NextDouble()), - Enumerable.Empty(), - new[] - { - new TopLevelFaultTreeIllustrationPoint( - WindDirectionTestFactory.CreateTestWindDirection(), - "IllustrationPointOne", - new IllustrationPointNode(new TestIllustrationPoint())), - new TopLevelFaultTreeIllustrationPoint( - WindDirectionTestFactory.CreateTestWindDirection(), - "IllustrationPointTwo", - new IllustrationPointNode(new TestIllustrationPoint())) - }); - - // Call - GeneralResultFaultTreeIllustrationPointEntity entity = - generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); - - // Assert - AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity); - } - private static void AssertGeneralResultSubMechanismIllustrationPointEntity( GeneralResult generalResult, GeneralResultSubMechanismIllustrationPointEntity entity) Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -0,0 +1,92 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Application.Ringtoets.Storage.Create.IllustrationPoints; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Application.Ringtoets.Storage.Test.Create.IllustrationPoints +{ + [TestFixture] + public class IllustrationPointNodeCreateExtensionsTest + { + [Test] + public void Create_IllustrationPointNodeNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((IllustrationPointNode) null).Create(0); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("illustrationPointNode", exception.ParamName); + } + + [Test] + public void Create_IllustrationPointNodeWithFaultTreeIllustrationPoint_ReturnFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + random.NextEnumValue()); + int order = random.Next(); + + var node = new IllustrationPointNode(illustrationPoint); + + // Call + FaultTreeIllustrationPointEntity entity = node.Create(order); + + // Assert + Assert.IsNull(entity.ParentFaultTreeIllustrationPointEntityId); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, entity.Name); + Assert.AreEqual(illustrationPoint.Beta, entity.Beta, illustrationPoint.Beta.GetAccuracy()); + byte expectedCombinationType = Convert.ToByte(illustrationPoint.CombinationType); + Assert.AreEqual(expectedCombinationType, entity.CombinationType); + CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity1); + CollectionAssert.IsEmpty(entity.StochastEntities); + CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointEntities); + CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities); + Assert.AreEqual(order, entity.Order); + } + + [Test] + public void Create_IllustrationPointNodeWithSubMechanismIllustrationPoint_ThrowsInvalidOperationException() + { + // Setup + var node = new IllustrationPointNode(new TestSubMechanismIllustrationPoint()); + + // Call + TestDelegate call = () => node.Create(0); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual($"Illustration point type '{typeof(TestSubMechanismIllustrationPoint)}' is not supported.", message); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (.../TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (.../TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) @@ -21,12 +21,8 @@ using System; using Application.Ringtoets.Storage.Create.IllustrationPoints; -using Application.Ringtoets.Storage.DbContext; -using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.IllustrationPoints; -using Ringtoets.Common.Data.TestUtil; -using Ringtoets.Common.Data.TestUtil.IllustrationPoints; namespace Application.Ringtoets.Storage.Test.Create.IllustrationPoints { @@ -43,29 +39,5 @@ var exception = Assert.Throws(call); Assert.AreEqual("topLevelFaultTreeIllustrationPoint", exception.ParamName); } - - [Test] - public void Create_ValidTopLevelFaultTreeIllustrationPoint_ReturnsTopLevelFaultTreeIllustrationPointEntity() - { - // Setup - var random = new Random(21); - - var node = new IllustrationPointNode(new TestIllustrationPoint()); - - var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); - var illustrationPoint = new TopLevelFaultTreeIllustrationPoint(windDirection, - "Just a situation", - node); - int order = random.Next(); - - // Call - TopLevelFaultTreeIllustrationPointEntity entity = illustrationPoint.Create(order); - - // Assert - TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, entity.ClosingSituation); - TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); - Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); - Assert.AreEqual(order, entity.Order); - } } } \ No newline at end of file