Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r691d05e8ca094b05af1ec8aed83b8376051f7052 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 691d05e8ca094b05af1ec8aed83b8376051f7052) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -368,6 +368,7 @@ + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensions.cs (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -0,0 +1,75 @@ +// 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.Collections.Generic; +using System.Linq; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Common.Data.IllustrationPoints; + +namespace Application.Ringtoets.Storage.Read.IllustrationPoints +{ + /// + /// Extension methods for + /// related to creating a . + /// + internal static class FaultTreeIllustrationPointEntityReadExtensions + { + /// + /// Reads the and uses + /// the information to construct a . + /// + /// The + /// to create a for. + /// A new . + /// Thrown when + /// is null. + public static IllustrationPointNode Read(this FaultTreeIllustrationPointEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + return new IllustrationPointNode(GetFaultTreeIllustrationPoint(entity)); + } + + private static FaultTreeIllustrationPoint GetFaultTreeIllustrationPoint(FaultTreeIllustrationPointEntity entity) + { + IEnumerable stochasts = GetReadStochasts(entity.StochastEntities); + + return new FaultTreeIllustrationPoint(entity.Name, entity.Beta, stochasts, GetCombinationType(entity)); + } + + private static CombinationType GetCombinationType(FaultTreeIllustrationPointEntity entity) + { + return entity.CombinationType == (byte) CombinationType.And + ? CombinationType.And + : CombinationType.Or; + } + + private static IEnumerable GetReadStochasts(IEnumerable stochastEntities) + { + return stochastEntities.OrderBy(st => st.Order) + .Select(st => st.Read()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensions.cs =================================================================== diff -u -r691d05e8ca094b05af1ec8aed83b8376051f7052 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensions.cs (.../GeneralResultFaultTreeIllustrationPointEntityReadExtensions.cs) (revision 691d05e8ca094b05af1ec8aed83b8376051f7052) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensions.cs (.../GeneralResultFaultTreeIllustrationPointEntityReadExtensions.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -77,7 +77,8 @@ private static IEnumerable GetReadTopLevelFaultTreeIllustrationPoint( IEnumerable illustrationPointEntities) { - return new List(); + return illustrationPointEntities.OrderBy(ip => ip.Order) + .Select(ip => ip.Read()); } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensions.cs =================================================================== diff -u -r691d05e8ca094b05af1ec8aed83b8376051f7052 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensions.cs (.../GeneralResultSubMechanismIllustrationPointEntityReadExtensions.cs) (revision 691d05e8ca094b05af1ec8aed83b8376051f7052) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensions.cs (.../GeneralResultSubMechanismIllustrationPointEntityReadExtensions.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -78,10 +78,8 @@ private static IEnumerable GetReadTopLevelSubMechanismIllustrationPoint( IEnumerable illustrationPointEntities) { - var stochasts = new List(); - stochasts.AddRange(illustrationPointEntities.OrderBy(st => st.Order) - .Select(st => st.Read())); - return stochasts; + return illustrationPointEntities.OrderBy(ip => ip.Order) + .Select(ip => ip.Read()); } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensions.cs =================================================================== diff -u -r1f8455066f5be4241f587c34283f1d7f8a85f78e -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensions.cs (.../SubMechanismIllustrationPointEntityReadExtensions.cs) (revision 1f8455066f5be4241f587c34283f1d7f8a85f78e) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/SubMechanismIllustrationPointEntityReadExtensions.cs (.../SubMechanismIllustrationPointEntityReadExtensions.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -64,19 +64,15 @@ private static IEnumerable GetReadSubMechanismIllustrationPointStochasts( IEnumerable stochastEntities) { - var stochasts = new List(); - stochasts.AddRange(stochastEntities.OrderBy(st => st.Order) - .Select(st => st.Read())); - return stochasts; + return stochastEntities.OrderBy(st => st.Order) + .Select(st => st.Read()); } private static IEnumerable GetReadIllustrationPointResults( IEnumerable illustrationPointResultEntities) { - var illustrationPointResults = new List(); - illustrationPointResults.AddRange(illustrationPointResultEntities.OrderBy(ipr => ipr.Order) - .Select(ipr => ipr.Read())); - return illustrationPointResults; + return illustrationPointResultEntities.OrderBy(ipr => ipr.Order) + .Select(ipr => ipr.Read()); } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensions.cs =================================================================== diff -u -r691d05e8ca094b05af1ec8aed83b8376051f7052 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensions.cs (.../TopLevelFaultTreeIllustrationPointEntityReadExtensions.cs) (revision 691d05e8ca094b05af1ec8aed83b8376051f7052) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/IllustrationPoints/TopLevelFaultTreeIllustrationPointEntityReadExtensions.cs (.../TopLevelFaultTreeIllustrationPointEntityReadExtensions.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -20,8 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; -using System.Linq; using Application.Ringtoets.Storage.DbContext; using Ringtoets.Common.Data.IllustrationPoints; @@ -51,7 +49,7 @@ WindDirection windDirection = GetWindDirection(entity); - IllustrationPointNode node = CreateIllustrationPointRootNode(entity.FaultTreeIllustrationPointEntity); + IllustrationPointNode node = entity.FaultTreeIllustrationPointEntity.Read(); return new TopLevelFaultTreeIllustrationPoint(windDirection, entity.ClosingSituation, node); } @@ -61,26 +59,5 @@ return new WindDirection(entity.WindDirectionName, entity.WindDirectionAngle); } - - private static IllustrationPointNode CreateIllustrationPointRootNode(FaultTreeIllustrationPointEntity entity) - { - IEnumerable stochasts = GetReadStochasts(entity.StochastEntities); - - return new IllustrationPointNode( - new FaultTreeIllustrationPoint(entity.Name, entity.Beta, stochasts, GetCombinationType(entity))); - } - - private static CombinationType GetCombinationType(FaultTreeIllustrationPointEntity entity) - { - return entity.CombinationType == (byte) CombinationType.And - ? CombinationType.And - : CombinationType.Or; - } - - private static IEnumerable GetReadStochasts(IEnumerable stochastEntities) - { - return stochastEntities.OrderBy(st => st.Order) - .Select(st => st.Read()); - } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r691d05e8ca094b05af1ec8aed83b8376051f7052 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 691d05e8ca094b05af1ec8aed83b8376051f7052) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -129,6 +129,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/FaultTreeIllustrationPointEntityReadExtensionsTest.cs (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -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 System.Linq; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read.IllustrationPoints; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read.IllustrationPoints +{ + [TestFixture] + public class FaultTreeIllustrationPointEntityReadExtensionsTest + { + [Test] + public void Read_EntityNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((FaultTreeIllustrationPointEntity) null).Read(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("entity", exception.ParamName); + } + + [Test] + public void Read_ValidEntity_ReturnsIllustrationPointNode() + { + // Setup + var random = new Random(21); + + var combinationType = random.NextEnumValue(); + var entity = new FaultTreeIllustrationPointEntity + { + Name = "FaultTreeIllustrationPointEntity", + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(combinationType), + StochastEntities = + { + new StochastEntity + { + Alpha = random.NextDouble(), + Duration = random.NextDouble(), + Name = "StochastEntity" + } + } + }; + + // Call + IllustrationPointNode node = entity.Read(); + + // Assert + var illustrationPoint = node.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(illustrationPoint); + Assert.AreEqual(entity.Name, illustrationPoint.Name); + Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); + Assert.AreEqual(combinationType, illustrationPoint.CombinationType); + + AssertStochasts(entity.StochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray()); + + CollectionAssert.IsEmpty(node.Children); + } + + private static void AssertStochasts(StochastEntity[] stochastEntities, Stochast[] stochasts) + { + Assert.AreEqual(stochastEntities.Length, stochasts.Length); + for (var i = 0; i < stochasts.Length; i++) + { + AssertStochast(stochastEntities[i], stochasts[i]); + } + } + + private static void AssertStochast(StochastEntity stochastEntity, Stochast readStochast) + { + Assert.AreEqual(stochastEntity.Name, readStochast.Name); + Assert.AreEqual(stochastEntity.Alpha, readStochast.Alpha, readStochast.Alpha.GetAccuracy()); + Assert.AreEqual(stochastEntity.Duration, readStochast.Duration, readStochast.Duration.GetAccuracy()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u -r392407315592d8c1db8f42185af9883b5319feb3 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs (.../GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs) (revision 392407315592d8c1db8f42185af9883b5319feb3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs (.../GeneralResultFaultTreeIllustrationPointEntityReadExtensionsTest.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -24,6 +24,7 @@ using System.Linq; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Read.IllustrationPoints; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Data.TestUtil; @@ -64,7 +65,7 @@ } [Test] - public void Read_ValidEntityWithStochasts_ReturnsGeneralResultSubMechanismIllustrationPoint() + public void Read_ValidEntityWithStochasts_ReturnsGeneralResultFaultTreeIllustrationPoint() { // Setup var random = new Random(21); @@ -100,6 +101,58 @@ AssertStochasts(entity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray()); } + [Test] + public void Read_ValidEntityWithIllustrationPoints_ReturnsGeneralResultFaultTreeIllustrationPoint() + { + // Setup + var random = new Random(210); + + var topLevelFaultTreeIllustrationPointEntities = new[] + { + new TopLevelFaultTreeIllustrationPointEntity + { + WindDirectionName = "WindDirectionOne", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationOne", + FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity + { + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Name = "IllustrationPointOne" + }, + Order = 0 + }, + new TopLevelFaultTreeIllustrationPointEntity + { + WindDirectionName = "WindDirectionTwo", + WindDirectionAngle = random.NextDouble(), + ClosingSituation = "ClosingSituationTwo", + FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity + { + Beta = random.NextDouble(), + CombinationType = Convert.ToByte(random.NextEnumValue()), + Name = "IllustrationPointTwo" + }, + Order = 1 + } + }; + + var entity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionName = "SSE", + GoverningWindDirectionAngle = random.NextDouble(), + TopLevelFaultTreeIllustrationPointEntities = topLevelFaultTreeIllustrationPointEntities + }; + + // Call + GeneralResult generalResult = entity.Read(); + + // Assert + AssertWindDirection(entity, generalResult.GoverningWindDirection); + AssertIllustrationPoints(entity.TopLevelFaultTreeIllustrationPointEntities.ToArray(), + generalResult.TopLevelIllustrationPoints.ToArray()); + } + private static void AssertWindDirection(IGeneralResultEntity entity, WindDirection windDirection) { Assert.AreEqual(entity.GoverningWindDirectionName, windDirection.Name); @@ -123,5 +176,29 @@ Assert.AreEqual(stochastEntity.Alpha, readStochast.Alpha, readStochast.Alpha.GetAccuracy()); Assert.AreEqual(stochastEntity.Duration, readStochast.Duration, readStochast.Duration.GetAccuracy()); } + + private static void AssertIllustrationPoints( + IList entities, + IList illustrationPoints) + { + Assert.AreEqual(entities.Count, illustrationPoints.Count); + for (var i = 0; i < entities.Count; i++) + { + TopLevelFaultTreeIllustrationPoint(entities[i], illustrationPoints[i]); + } + } + + private static void TopLevelFaultTreeIllustrationPoint( + TopLevelFaultTreeIllustrationPointEntity illustrationPointEntity, + TopLevelFaultTreeIllustrationPoint illustrationPoint) + { + Assert.AreEqual(illustrationPointEntity.ClosingSituation, illustrationPoint.ClosingSituation); + + WindDirection actualWindDirection = illustrationPoint.WindDirection; + Assert.AreEqual(illustrationPointEntity.WindDirectionName, actualWindDirection.Name); + Assert.AreEqual(illustrationPointEntity.WindDirectionAngle, actualWindDirection.Angle, actualWindDirection.Angle); + + Assert.IsNotNull(illustrationPoint.FaultTreeNodeRoot); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs =================================================================== diff -u -r392407315592d8c1db8f42185af9883b5319feb3 -r283d7e09d084caafac590fdf96bfc6a264604016 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs (.../GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs) (revision 392407315592d8c1db8f42185af9883b5319feb3) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/IllustrationPoints/GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs (.../GeneralResultSubMechanismIllustrationPointEntityReadExtensionsTest.cs) (revision 283d7e09d084caafac590fdf96bfc6a264604016) @@ -146,11 +146,11 @@ // Assert AssertWindDirection(entity, generalResult.GoverningWindDirection); - AssertAssertIllustrationPoints(entity.TopLevelSubMechanismIllustrationPointEntities.ToArray(), - generalResult.TopLevelIllustrationPoints.ToArray()); + AssertIllustrationPoints(entity.TopLevelSubMechanismIllustrationPointEntities.ToArray(), + generalResult.TopLevelIllustrationPoints.ToArray()); } - private static void AssertAssertIllustrationPoints( + private static void AssertIllustrationPoints( IList entities, IList illustrationPoints) {