Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8 -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -72,11 +72,13 @@ + + Code Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensions.cs (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -0,0 +1,62 @@ +// 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 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 FaultTreeIllustrationPointCreateExtensions + { + /// + /// Creates a based on the information + /// of . + /// + /// The fault tree illustration point to create + /// a database entity for. + /// A new . + /// Thrown when + /// is null. + public static FaultTreeIllustrationPointEntity Create( + this FaultTreeIllustrationPoint faultTreeIllustrationPoint) + { + if (faultTreeIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(faultTreeIllustrationPoint)); + } + + var entity = new FaultTreeIllustrationPointEntity + { + Beta = faultTreeIllustrationPoint.Beta, + CombinationType = Convert.ToByte(faultTreeIllustrationPoint.CombinationType), + Name = faultTreeIllustrationPoint.Name.DeepClone() + }; + + return entity; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/GeneralResultCreateExtensions.cs =================================================================== diff -u -ref5e8f54613f8dd00da958f15f730aa4a1899223 -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/GeneralResultCreateExtensions.cs (.../GeneralResultCreateExtensions.cs) (revision ef5e8f54613f8dd00da958f15f730aa4a1899223) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/GeneralResultCreateExtensions.cs (.../GeneralResultCreateExtensions.cs) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -42,7 +42,7 @@ /// A new . /// Thrown when /// is null. - internal static GeneralResultSubMechanismIllustrationPointEntity CreateGeneralResultSubMechanismIllustrationPointEntity( + public static GeneralResultSubMechanismIllustrationPointEntity CreateGeneralResultSubMechanismIllustrationPointEntity( this GeneralResult generalResultSubMechanismIllustrationPoint) { if (generalResultSubMechanismIllustrationPoint == null) @@ -65,6 +65,36 @@ return entity; } + /// + /// Creates a based on the + /// information of . + /// + /// The general result to create a database entity for. + /// A new . + /// Thrown when + /// is null. + public static GeneralResultFaultTreeIllustrationPointEntity CreateGeneralResultFaultTreeIllustrationPointEntity( + this GeneralResult generalResult) + { + if (generalResult == null) + { + throw new ArgumentNullException(nameof(generalResult)); + } + + WindDirection governingWindDirection = generalResult.GoverningWindDirection; + var entity = new GeneralResultFaultTreeIllustrationPointEntity + { + GoverningWindDirectionAngle = governingWindDirection.Angle, + GoverningWindDirectionName = governingWindDirection.Name.DeepClone() + }; + + AddEntitiesForStochasts(entity, generalResult.Stochasts); + AddEntitiesForTopLevelFaultTreeIllustrationPoints( + entity, generalResult.TopLevelIllustrationPoints); + + return entity; + } + private static void AddEntitiesForStochasts(GeneralResultSubMechanismIllustrationPointEntity entity, IEnumerable stochasts) { @@ -75,6 +105,16 @@ } } + private static void AddEntitiesForStochasts(GeneralResultFaultTreeIllustrationPointEntity entity, + IEnumerable stochasts) + { + var order = 0; + foreach (Stochast stochast in stochasts) + { + entity.StochastEntities.Add(stochast.Create(order++)); + } + } + private static void AddEntitiesForTopLevelSubMechanismIllustrationPoints( GeneralResultSubMechanismIllustrationPointEntity entity, IEnumerable illustrationPoints) @@ -86,5 +126,17 @@ illustrationPoint.Create(order++)); } } + + private static void AddEntitiesForTopLevelFaultTreeIllustrationPoints( + GeneralResultFaultTreeIllustrationPointEntity entity, + IEnumerable illustrationPoints) + { + var order = 0; + foreach (TopLevelFaultTreeIllustrationPoint illustrationPoint in illustrationPoints) + { + entity.TopLevelFaultTreeIllustrationPointEntities.Add( + illustrationPoint.Create(order++)); + } + } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensions.cs (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -0,0 +1,65 @@ +// 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 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 TopLevelFaultTreeIllustrationPointCreateExtensions + { + /// + /// Creates a + /// based on the information of . + /// + /// The illustration point to create + /// a database entity for. + /// The index at which + /// resides within its parent. + /// A . + /// Thrown when + /// is null. + public static TopLevelFaultTreeIllustrationPointEntity Create( + this TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint, + int order) + { + if (topLevelFaultTreeIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(topLevelFaultTreeIllustrationPoint)); + } + + WindDirection windDirection = topLevelFaultTreeIllustrationPoint.WindDirection; + return new TopLevelFaultTreeIllustrationPointEntity + { + ClosingSituation = topLevelFaultTreeIllustrationPoint.ClosingSituation.DeepClone(), + WindDirectionName = windDirection.Name.DeepClone(), + WindDirectionAngle = windDirection.Angle, + Order = order + }; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialRingtoetsEntities.cs =================================================================== diff -u -ra242528447c742f773b93459bd5114714820e6c6 -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 --- Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialRingtoetsEntities.cs (.../PartialRingtoetsEntities.cs) (revision a242528447c742f773b93459bd5114714820e6c6) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/DbContext/PartialRingtoetsEntities.cs (.../PartialRingtoetsEntities.cs) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -120,8 +120,11 @@ private void LoadIllustrationPointsIntoContext() { + FaultTreeIllustrationPointEntities.Load(); + GeneralResultFaultTreeIllustrationPointEntities.Include(gr=>gr.StochastEntities).Load(); GeneralResultSubMechanismIllustrationPointEntities.Include(grsm => grsm.StochastEntities).Load(); StochastEntities.Load(); + TopLevelFaultTreeIllustrationPointEntities.Load(); TopLevelSubMechanismIllustrationPointEntities.Load(); SubMechanismIllustrationPointEntities.Load(); SubMechanismIllustrationPointStochastEntities.Load(); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8 -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -90,11 +90,13 @@ + + Code Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/FaultTreeIllustrationPointCreateExtensionsTest.cs (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -0,0 +1,74 @@ +// 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; + +namespace Application.Ringtoets.Storage.Test.Create.IllustrationPoints +{ + [TestFixture] + public class FaultTreeIllustrationPointCreateExtensionsTest + { + [Test] + public void Create_IllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((FaultTreeIllustrationPoint) null).Create(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("faultTreeIllustrationPoint", exception.ParamName); + } + + [Test] + public void Create_FaultTreeIllustrationPointWithoutStochasts_ReturnFaultTreeIllustrationPointEntityWithoutStochasts() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name", + random.NextDouble(), + Enumerable.Empty(), + random.NextEnumValue()); + + // Call + FaultTreeIllustrationPointEntity entity = illustrationPoint.Create(); + + // 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(0, entity.Order); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs =================================================================== diff -u -ref5e8f54613f8dd00da958f15f730aa4a1899223 -r72915c82fc1b1222de1b88548f9c80c8d01a12b6 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (.../GeneralResultCreateExtensionsTest.cs) (revision ef5e8f54613f8dd00da958f15f730aa4a1899223) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/GeneralResultCreateExtensionsTest.cs (.../GeneralResultCreateExtensionsTest.cs) (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -152,6 +152,45 @@ } } + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_GeneralResultNull_ThrowsArgumentNullException() + { + // Setup + GeneralResult generalResult = null; + + // Call + TestDelegate call = () => generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("generalResult", exception.ParamName); + } + + [Test] + public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralResult_ReturnsExpectedGeneralResultFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + var governingWindDirection = new WindDirection("SSE", random.NextDouble()); + + var generalResult = new GeneralResult( + governingWindDirection, + Enumerable.Empty(), + Enumerable.Empty()); + + // Call + GeneralResultFaultTreeIllustrationPointEntity entity = + generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity(); + + // Assert + TestHelper.AssertAreEqualButNotSame(governingWindDirection.Name, entity.GoverningWindDirectionName); + Assert.AreEqual(governingWindDirection.Angle, entity.GoverningWindDirectionAngle, + governingWindDirection.Angle.GetAccuracy()); + + CollectionAssert.IsEmpty(entity.StochastEntities); + CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities); + } + private static void AssertWindDirection(WindDirection expectedWindDirection, GeneralResultSubMechanismIllustrationPointEntity entity) { Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/TopLevelFaultTreeIllustrationPointCreateExtensionsTest.cs (revision 72915c82fc1b1222de1b88548f9c80c8d01a12b6) @@ -0,0 +1,71 @@ +// 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 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 TopLevelFaultTreeIllustrationPointCreateExtensionsTest + { + [Test] + public void Create_TopLevelFaultTreeIllustrationPointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => ((TopLevelFaultTreeIllustrationPoint) null).Create(0); + + // Assert + 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