Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs =================================================================== diff -u -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 -r79565e60750c8a6c33847cd94d5c5910b77542b1 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (.../IllustrationPointNodeCreateExtensions.cs) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/IllustrationPoints/IllustrationPointNodeCreateExtensions.cs (.../IllustrationPointNodeCreateExtensions.cs) (revision 79565e60750c8a6c33847cd94d5c5910b77542b1) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.DbContext; using Core.Common.Utils.Extensions; @@ -79,10 +80,21 @@ Name = illustrationPoint.Name.DeepClone(), Order = order }; + AddEntitiesForStochasts(entity, illustrationPoint.Stochasts); return entity; } + private static void AddEntitiesForStochasts(FaultTreeIllustrationPointEntity entity, + IEnumerable stochasts) + { + var order = 0; + foreach (Stochast stochast in stochasts) + { + entity.StochastEntities.Add(stochast.Create(order++)); + } + } + private static void CreateChildElements(IllustrationPointNode[] illustrationPointNodes, FaultTreeIllustrationPointEntity entity) { Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs =================================================================== diff -u -r355b0e8dff79cfc8a42cf598f24a753ba5f57083 -r79565e60750c8a6c33847cd94d5c5910b77542b1 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (.../IllustrationPointNodeCreateExtensionsTest.cs) (revision 355b0e8dff79cfc8a42cf598f24a753ba5f57083) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/IllustrationPoints/IllustrationPointNodeCreateExtensionsTest.cs (.../IllustrationPointNodeCreateExtensionsTest.cs) (revision 79565e60750c8a6c33847cd94d5c5910b77542b1) @@ -77,6 +77,48 @@ } [Test] + public void Create_IllustrationPointNodeWithFaultTreeIllustrationPointAndStochast_ReturnFaultTreeIllustrationPointEntity() + { + // Setup + var random = new Random(21); + + var illustrationPoint = new FaultTreeIllustrationPoint( + "Illustration point name", + random.NextDouble(), + new[] + { + new Stochast("Stochast", + random.NextDouble(), + random.NextDouble()) + }, + 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.SubMechanismIllustrationPointEntities); + CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities); + Assert.AreEqual(order, entity.Order); + + StochastEntity entityStochastEntity = entity.StochastEntities.FirstOrDefault(); + Assert.IsNotNull(entityStochastEntity); + Stochast stochast = illustrationPoint.Stochasts.First(); + Assert.AreEqual(stochast.Name, entityStochastEntity.Name); + Assert.AreEqual(stochast.Alpha, entityStochastEntity.Alpha); + Assert.AreEqual(stochast.Duration, entityStochastEntity.Duration); + } + + [Test] public void Create_IllustrationPointNodeWithSubMechanismIllustrationPoint_ThrowsInvalidOperationException() { // Setup @@ -92,7 +134,7 @@ [Test] [TestCaseSource(nameof(GetValidIllustrationPointNodes))] - public void Create_IllustrationPointNodeWithSubMechanismIllustrationPointChildren_ReturnFaultTreeIllustrationPointEntity( + public void Create_IllustrationPointNodeWithValidChildren_ReturnFaultTreeIllustrationPointEntity( IEnumerable children) { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -rcde6520ef77032269df8ca97685df3109f0205b1 -r79565e60750c8a6c33847cd94d5c5910b77542b1 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision cde6520ef77032269df8ca97685df3109f0205b1) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 79565e60750c8a6c33847cd94d5c5910b77542b1) @@ -939,15 +939,20 @@ AssertStabilityPointStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); - if (expectedCalculation.HasOutput) + if (!expectedCalculation.HasOutput) { - AssertProbabilityAssessmentOutput(expectedCalculation.Output.ProbabilityAssessmentOutput, - actualCalculation.Output.ProbabilityAssessmentOutput); - } - else - { Assert.IsFalse(actualCalculation.HasOutput); + return; } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + AssertProbabilityAssessmentOutput(expectedOutput.ProbabilityAssessmentOutput, + actualOutput.ProbabilityAssessmentOutput); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralFaultTreeIllustrationPoint, + actualOutput.GeneralFaultTreeIllustrationPoint); } private static void AssertStabilityPointStructuresInput(StabilityPointStructuresInput expectedInput, @@ -1069,15 +1074,20 @@ AssertClosingStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); - if (expectedCalculation.HasOutput) + if (!expectedCalculation.HasOutput) { - AssertProbabilityAssessmentOutput(expectedCalculation.Output.ProbabilityAssessmentOutput, - actualCalculation.Output.ProbabilityAssessmentOutput); - } - else - { Assert.IsFalse(actualCalculation.HasOutput); + return; } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + AssertProbabilityAssessmentOutput(expectedOutput.ProbabilityAssessmentOutput, + actualOutput.ProbabilityAssessmentOutput); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralFaultTreeIllustrationPoint, + actualOutput.GeneralFaultTreeIllustrationPoint); } private static void AssertClosingStructuresInput(ClosingStructuresInput expectedInput, @@ -1246,15 +1256,20 @@ AssertHeightStructuresInput(expectedCalculation.InputParameters, actualCalculation.InputParameters); - if (expectedCalculation.HasOutput) + if (!expectedCalculation.HasOutput) { - AssertProbabilityAssessmentOutput(expectedCalculation.Output.ProbabilityAssessmentOutput, - actualCalculation.Output.ProbabilityAssessmentOutput); - } - else - { Assert.IsFalse(actualCalculation.HasOutput); + return; } + + StructuresOutput expectedOutput = expectedCalculation.Output; + StructuresOutput actualOutput = actualCalculation.Output; + AssertProbabilityAssessmentOutput(expectedOutput.ProbabilityAssessmentOutput, + actualOutput.ProbabilityAssessmentOutput); + + AssertGeneralResultTopLevelFaultTreeIllustrationPoint( + expectedOutput.GeneralFaultTreeIllustrationPoint, + actualOutput.GeneralFaultTreeIllustrationPoint); } private static void AssertHeightStructuresInput(HeightStructuresInput expectedInput, @@ -1724,17 +1739,87 @@ Assert.AreEqual(expectedOutput.CalculatedReliability, actualOutput.CalculatedReliability); Assert.AreEqual(CalculationConvergence.NotCalculated, actualOutput.CalculationConvergence); - AssertGeneralResultSubMechanismIllustrationPoint(expectedOutput.GeneralResultSubMechanismIllustrationPoint, - actualOutput.GeneralResultSubMechanismIllustrationPoint); + AssertGeneralResultTopLevelSubMechanismIllustrationPoint(expectedOutput.GeneralResultSubMechanismIllustrationPoint, + actualOutput.GeneralResultSubMechanismIllustrationPoint); } #endregion #region IllustrationPoints - private static void AssertGeneralResultSubMechanismIllustrationPoint(GeneralResult expectedGeneralResult, - GeneralResult actualGeneralResult) + private static void AssertGeneralResultTopLevelFaultTreeIllustrationPoint(GeneralResult expected, + GeneralResult actual) { + if (expected == null) + { + Assert.IsNull(actual); + return; + } + + AssertWindDirection(expected.GoverningWindDirection, + actual.GoverningWindDirection); + + AssertCollectionAndItems(expected.Stochasts, + actual.Stochasts, + AssertStochast); + + AssertCollectionAndItems(expected.TopLevelIllustrationPoints, + actual.TopLevelIllustrationPoints, + AssertTopLevelFaultTreeIllustrationPoint); + } + + private static void AssertTopLevelFaultTreeIllustrationPoint(TopLevelFaultTreeIllustrationPoint expected, + TopLevelFaultTreeIllustrationPoint actual) + { + AssertWindDirection(expected.WindDirection, actual.WindDirection); + + Assert.AreEqual(expected.ClosingSituation, actual.ClosingSituation); + + AssertIllustrationPointNode(expected.FaultTreeNodeRoot, actual.FaultTreeNodeRoot); + } + + private static void AssertIllustrationPointNode(IllustrationPointNode expected, IllustrationPointNode actual) + { + var expectedFaultTreeIllustrationPoint = expected.Data as FaultTreeIllustrationPoint; + if (expectedFaultTreeIllustrationPoint != null) + { + var actualFaultTreeIllustrationPoint = actual.Data as FaultTreeIllustrationPoint; + Assert.IsNotNull(actualFaultTreeIllustrationPoint); + + AssertFaultTreeIllustrationPoint(expectedFaultTreeIllustrationPoint, + actualFaultTreeIllustrationPoint); + + AssertCollectionAndItems(expected.Children, + actual.Children, + AssertIllustrationPointNode); + return; + } + + var expectedSubMechanismIllustrationPoint = expected.Data as SubMechanismIllustrationPoint; + if (expectedSubMechanismIllustrationPoint != null) + { + var actualSubMechanismIllustrationPoint = actual.Data as SubMechanismIllustrationPoint; + Assert.IsNotNull(actualSubMechanismIllustrationPoint); + + AssertSubMechanismIllustrationPoint(expectedSubMechanismIllustrationPoint, + actualSubMechanismIllustrationPoint); + } + } + + private static void AssertFaultTreeIllustrationPoint(FaultTreeIllustrationPoint expected, + FaultTreeIllustrationPoint actual) + { + Assert.AreEqual(expected.Name, actual.Name); + Assert.AreEqual(expected.Beta, actual.Beta); + Assert.AreEqual(expected.CombinationType, actual.CombinationType); + + AssertCollectionAndItems(expected.Stochasts, actual.Stochasts, AssertStochast); + } + + private static void AssertGeneralResultTopLevelSubMechanismIllustrationPoint( + GeneralResult expectedGeneralResult, + GeneralResult actualGeneralResult) + { if (expectedGeneralResult == null) { Assert.IsNull(actualGeneralResult);