Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs =================================================================== diff -u -r7885455b0db0c345ed798e8b8ca29158a93fcc5a -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (.../IllustrationPointNodeCreateExtensions.cs) (revision 7885455b0db0c345ed798e8b8ca29158a93fcc5a) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (.../IllustrationPointNodeCreateExtensions.cs) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -55,17 +55,16 @@ throw new ArgumentNullException(nameof(illustrationPointNode)); } - IllustrationPointBase illustrationPoint = illustrationPointNode.Data; - IllustrationPointNode[] children = illustrationPointNode.Children.ToArray(); - - var faultTreeIllustrationPoint = illustrationPoint as FaultTreeIllustrationPoint; + var faultTreeIllustrationPoint = illustrationPointNode.Data as FaultTreeIllustrationPoint; if (faultTreeIllustrationPoint == null) { - throw new InvalidOperationException($"Illustration point type '{illustrationPoint.GetType()}' is not supported."); + throw new InvalidOperationException($"Illustration point type '{illustrationPointNode.Data.GetType()}' is not supported."); } - FaultTreeIllustrationPointEntity entity = CreateFaultTreeIllustrationPoint(faultTreeIllustrationPoint, order); - CreateChildElements(children, entity); + FaultTreeIllustrationPointEntity entity = CreateFaultTreeIllustrationPoint(faultTreeIllustrationPoint, + order); + + CreateChildElements(illustrationPointNode.Children.ToArray(), entity); return entity; } @@ -89,18 +88,18 @@ { for (var i = 0; i < illustrationPointNodes.Length; i++) { - IllustrationPointNode node = illustrationPointNodes[0]; + IllustrationPointNode node = illustrationPointNodes[i]; var faultTreeIllustrationPoint = node.Data as FaultTreeIllustrationPoint; if (faultTreeIllustrationPoint != null) { - entity.FaultTreeIllustrationPointEntity1.Add(node.Create(i + 1)); + entity.FaultTreeIllustrationPointEntity1.Add(node.Create(i)); } var subMechanismIllustrationPoint = node.Data as SubMechanismIllustrationPoint; if (subMechanismIllustrationPoint != null) { - entity.SubMechanismIllustrationPointEntities.Add(subMechanismIllustrationPoint.Create(i + 1)); + entity.SubMechanismIllustrationPointEntities.Add(subMechanismIllustrationPoint.Create(i)); } } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs =================================================================== diff -u -r20a1edec7117a9cfee64e29c5eb7f00f4375e9c5 -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (.../IllustrationPointNodeCreateExtensionsTest.cs) (revision 20a1edec7117a9cfee64e29c5eb7f00f4375e9c5) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (.../IllustrationPointNodeCreateExtensionsTest.cs) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.Create.IllustrationPoints; using Application.Ringtoets.Storage.DbContext; @@ -88,5 +89,116 @@ string message = Assert.Throws(call).Message; Assert.AreEqual($"Illustration point type '{typeof(TestSubMechanismIllustrationPoint)}' is not supported.", message); } + + [Test] + [TestCaseSource(nameof(GetValidIllustrationPointNodes))] + public void Create_IllustrationPointNodeWithSubMechanismIllustrationPointChildren_ReturnFaultTreeIllustrationPointEntity( + IEnumerable children) + { + // 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); + node.SetChildren(children.ToArray()); + + // Call + FaultTreeIllustrationPointEntity entity = node.Create(order); + + // Assert + AssertFaultTreeIllustrationPointEntity(illustrationPoint, entity); + AssertIllustrationPointEntities(node.Children.ToArray(), + entity.SubMechanismIllustrationPointEntities.ToArray(), + entity.FaultTreeIllustrationPointEntity1.ToArray()); + + Assert.AreEqual(order, entity.Order); + } + + private static IEnumerable GetValidIllustrationPointNodes() + { + yield return new TestCaseData(new List + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint()), + new IllustrationPointNode(new TestSubMechanismIllustrationPoint()) + }).SetName("SubMechanismIllustrationPoints"); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint()), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()) + }).SetName("SubMechanismAndFaultTreeIllustrationPoints"); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()) + }).SetName("FaultTreeIllustrationPoints"); + + var node = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()); + node.SetChildren(new[] + { + new IllustrationPointNode(new TestSubMechanismIllustrationPoint()), + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()) + }); + + yield return new TestCaseData(new List + { + new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()), + node + }).SetName("IllustrationPointsWithChildren"); + } + + private static void AssertIllustrationPointEntities( + IllustrationPointNode[] children, + IList subMechanismIllustrationPointEntities, + IList faultTreeIllustrationPointEntity + ) + { + for (var i = 0; i < children.Length; i++) + { + IllustrationPointNode child = children[i]; + + var subMechanismIllustrationPoint = child.Data as SubMechanismIllustrationPoint; + if (subMechanismIllustrationPoint != null) + { + SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities.Single(s => s.Order == i); + AssertSubMechanismIllustrationPointEntity(subMechanismIllustrationPoint, illustrationPointEntity); + } + + var faultTreeIllustrationPoint = child.Data as FaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint != null) + { + FaultTreeIllustrationPointEntity illustrationPointEntity = faultTreeIllustrationPointEntity.Single(f => f.Order == i); + AssertFaultTreeIllustrationPointEntity(faultTreeIllustrationPoint, illustrationPointEntity); + + AssertIllustrationPointEntities(child.Children.ToArray(), + illustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray(), + illustrationPointEntity.FaultTreeIllustrationPointEntity1.ToArray()); + } + } + } + + private static void AssertSubMechanismIllustrationPointEntity(IllustrationPointBase illustrationPoint, + SubMechanismIllustrationPointEntity illustrationPointEntity) + { + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(illustrationPoint.Beta, illustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy()); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, illustrationPointEntity.Name); + } + + private static void AssertFaultTreeIllustrationPointEntity(FaultTreeIllustrationPoint illustrationPoint, + FaultTreeIllustrationPointEntity illustrationPointEntity) + { + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(illustrationPoint.Beta, illustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(Convert.ToByte(illustrationPoint.CombinationType), illustrationPointEntity.CombinationType); + TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, illustrationPointEntity.Name); + CollectionAssert.IsEmpty(illustrationPointEntity.StochastEntities); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/IllustrationPoints/FaultTreeIllustrationPointTestFactoryTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/IllustrationPoints/FaultTreeIllustrationPointTestFactoryTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/IllustrationPoints/FaultTreeIllustrationPointTestFactoryTest.cs (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -0,0 +1,101 @@ +// 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 NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; + +namespace Ringtoets.Common.Data.TestUtil.Test.IllustrationPoints +{ + [TestFixture] + public class FaultTreeIllustrationPointTestFactoryTest + { + [Test] + public void CreateTestFaultTreeIllustrationPoint_ReturnsExpectedProperties() + { + // Call + FaultTreeIllustrationPoint illustrationPoint = FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint(); + + // Assert + Assert.IsInstanceOf(illustrationPoint); + + Assert.AreEqual("Illustration point", illustrationPoint.Name); + Assert.AreEqual(1.23, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(CombinationType.And, illustrationPoint.CombinationType); + Assert.IsEmpty(illustrationPoint.Stochasts); + } + + [Test] + public void CreateTestFaultTreeIllustrationPoint_ValidParameter_ReturnsExpectedProperties() + { + // Setup + double beta = new Random().NextDouble(); + + // Call + FaultTreeIllustrationPoint illustrationPoint = FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint(beta); + + // Assert + Assert.IsInstanceOf(illustrationPoint); + + Assert.AreEqual("Illustration point", illustrationPoint.Name); + Assert.AreEqual(beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(CombinationType.And, illustrationPoint.CombinationType); + Assert.IsEmpty(illustrationPoint.Stochasts); + } + + [Test] + public void CreateTestFaultTreeIllustrationPointCombinationTypeAnd_ValidParameter_ReturnsExpectedProperties() + { + // Setup + double beta = new Random().NextDouble(); + + // Call + FaultTreeIllustrationPoint illustrationPoint = FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd(beta); + + // Assert + Assert.IsInstanceOf(illustrationPoint); + + Assert.AreEqual("Illustration point", illustrationPoint.Name); + Assert.AreEqual(beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(CombinationType.And, illustrationPoint.CombinationType); + Assert.IsEmpty(illustrationPoint.Stochasts); + } + + [Test] + public void CreateTestFaultTreeIllustrationPointCombinationTypeOr_ValidParameter_ReturnsExpectedProperties() + { + // Setup + double beta = new Random().NextDouble(); + + // Call + FaultTreeIllustrationPoint illustrationPoint = FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeOr(beta); + + // Assert + Assert.IsInstanceOf(illustrationPoint); + + Assert.AreEqual("Illustration point", illustrationPoint.Name); + Assert.AreEqual(beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(CombinationType.Or, illustrationPoint.CombinationType); + Assert.IsEmpty(illustrationPoint.Stochasts); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/Ringtoets.Common.Data.TestUtil.Test.csproj =================================================================== diff -u -rb980005d38347be63445eae4223e5d9fa2dc0395 -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/Ringtoets.Common.Data.TestUtil.Test.csproj (.../Ringtoets.Common.Data.TestUtil.Test.csproj) (revision b980005d38347be63445eae4223e5d9fa2dc0395) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/Ringtoets.Common.Data.TestUtil.Test.csproj (.../Ringtoets.Common.Data.TestUtil.Test.csproj) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -55,6 +55,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/IllustrationPoints/FaultTreeIllustrationPointTestFactory.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/IllustrationPoints/FaultTreeIllustrationPointTestFactory.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/IllustrationPoints/FaultTreeIllustrationPointTestFactory.cs (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -0,0 +1,81 @@ +// 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.Linq; +using Ringtoets.Common.Data.IllustrationPoints; + +namespace Ringtoets.Common.Data.TestUtil.IllustrationPoints +{ + /// + /// Factory to create simple instances that can be used for testing. + /// + public static class FaultTreeIllustrationPointTestFactory + { + /// + /// Creates a new instance of with arbitrary value + /// for and beta. + /// + /// The created . + public static FaultTreeIllustrationPoint CreateTestFaultTreeIllustrationPoint() + { + return CreateTestFaultTreeIllustrationPoint(1.23); + } + + /// + /// Creates a new instance of with arbitrary value + /// for . + /// + /// The beta value of the illustration point. + /// The created . + public static FaultTreeIllustrationPoint CreateTestFaultTreeIllustrationPoint(double beta) + { + return CreateTestFaultTreeIllustrationPointCombinationTypeAnd(beta); + } + + /// + /// Creates a new instance of with + /// set to . + /// + /// The beta value of the illustration point. + /// The created . + public static FaultTreeIllustrationPoint CreateTestFaultTreeIllustrationPointCombinationTypeAnd(double beta) + { + return new FaultTreeIllustrationPoint("Illustration point", + beta, + Enumerable.Empty(), + CombinationType.And); + } + + /// + /// Creates a new instance of with + /// set to . + /// + /// The beta value of the illustration point. + /// The created . + public static FaultTreeIllustrationPoint CreateTestFaultTreeIllustrationPointCombinationTypeOr(double beta) + { + return new FaultTreeIllustrationPoint("Illustration point", + beta, + Enumerable.Empty(), + CombinationType.Or); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/Ringtoets.Common.Data.TestUtil.csproj =================================================================== diff -u -rb980005d38347be63445eae4223e5d9fa2dc0395 -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/Ringtoets.Common.Data.TestUtil.csproj (.../Ringtoets.Common.Data.TestUtil.csproj) (revision b980005d38347be63445eae4223e5d9fa2dc0395) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/Ringtoets.Common.Data.TestUtil.csproj (.../Ringtoets.Common.Data.TestUtil.csproj) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) @@ -58,6 +58,7 @@ +