Index: Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensions.cs =================================================================== diff -u -rea609f4592fa0a0df54670689af45c1c6462816d -r8f813f8a94050f65846c119b2b0084007df6a86a --- Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensions.cs (.../ProbabilisticPipingOutputCreateExtensions.cs) (revision ea609f4592fa0a0df54670689af45c1c6462816d) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensions.cs (.../ProbabilisticPipingOutputCreateExtensions.cs) (revision 8f813f8a94050f65846c119b2b0084007df6a86a) @@ -49,13 +49,27 @@ throw new ArgumentNullException(nameof(output)); } - return new ProbabilisticPipingCalculationOutputEntity + var outputEntity = new ProbabilisticPipingCalculationOutputEntity { ProfileSpecificReliability = output.ProfileSpecificOutput.Reliability.ToNaNAsNull(), - SectionSpecificReliability = output.SectionSpecificOutput.Reliability.ToNaNAsNull(), - GeneralResultFaultTreeIllustrationPointEntity = ((PartialProbabilisticPipingOutput)output.ProfileSpecificOutput).GeneralResult?.CreateGeneralResultFaultTreeIllustrationPointEntity(), - GeneralResultFaultTreeIllustrationPointEntity1 = ((PartialProbabilisticPipingOutput)output.SectionSpecificOutput).GeneralResult?.CreateGeneralResultFaultTreeIllustrationPointEntity() + SectionSpecificReliability = output.SectionSpecificOutput.Reliability.ToNaNAsNull() }; + + if (output.ProfileSpecificOutput is PartialProbabilisticFaultTreePipingOutput profileSpecificFaultTreePipingOutput + && output.SectionSpecificOutput is PartialProbabilisticFaultTreePipingOutput sectionSpecificFaultTreePipingOutput) + { + outputEntity.GeneralResultFaultTreeIllustrationPointEntity = profileSpecificFaultTreePipingOutput.GeneralResult?.CreateGeneralResultFaultTreeIllustrationPointEntity(); + outputEntity.GeneralResultFaultTreeIllustrationPointEntity1 = sectionSpecificFaultTreePipingOutput.GeneralResult?.CreateGeneralResultFaultTreeIllustrationPointEntity(); + } + + if (output.ProfileSpecificOutput is PartialProbabilisticSubMechanismPipingOutput profileSpecificSubMechanismPipingOutput + && output.SectionSpecificOutput is PartialProbabilisticSubMechanismPipingOutput sectionSpecificSubMechanismPipingOutput) + { + outputEntity.GeneralResultSubMechanismIllustrationPointEntity = profileSpecificSubMechanismPipingOutput.GeneralResult?.CreateGeneralResultSubMechanismIllustrationPointEntity(); + outputEntity.GeneralResultSubMechanismIllustrationPointEntity1 = sectionSpecificSubMechanismPipingOutput.GeneralResult?.CreateGeneralResultSubMechanismIllustrationPointEntity(); + } + + return outputEntity; } } } \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8f813f8a94050f65846c119b2b0084007df6a86a --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs (.../HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs (.../HydraulicBoundaryLocationCalculationOutputCreateExtensionsTest.cs) (revision 8f813f8a94050f65846c119b2b0084007df6a86a) @@ -29,6 +29,7 @@ using Riskeer.Common.Data.TestUtil.IllustrationPoints; using Riskeer.Storage.Core.Create; using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.TestUtil.IllustrationPoints; namespace Riskeer.Storage.Core.Test.Create { @@ -67,7 +68,7 @@ Assert.AreEqual(output.CalculatedReliability, entity.CalculatedReliability, output.CalculatedReliability.GetAccuracy()); Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); - AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity); } [Test] @@ -90,7 +91,7 @@ Assert.IsNull(entity.CalculatedReliability); Assert.AreEqual((byte) output.CalculationConvergence, entity.CalculationConvergence); - AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity); } [Test] @@ -106,7 +107,7 @@ HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity(); // Assert - AssertGeneralResult(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity); } private static GeneralResult GetGeneralResult() @@ -127,25 +128,5 @@ return generalResult; } - - private static void AssertGeneralResult(GeneralResult illustrationPoint, - GeneralResultSubMechanismIllustrationPointEntity entity) - { - if (illustrationPoint == null) - { - Assert.IsNull(entity); - return; - } - - Assert.IsNotNull(entity); - WindDirection governingWindDirection = illustrationPoint.GoverningWindDirection; - TestHelper.AssertAreEqualButNotSame(governingWindDirection.Name, entity.GoverningWindDirectionName); - Assert.AreEqual(governingWindDirection.Angle, entity.GoverningWindDirectionAngle, - governingWindDirection.Angle.GetAccuracy()); - - Assert.AreEqual(illustrationPoint.Stochasts.Count(), entity.StochastEntities.Count); - Assert.AreEqual(illustrationPoint.TopLevelIllustrationPoints.Count(), - entity.TopLevelSubMechanismIllustrationPointEntities.Count); - } } } \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensionsTest.cs =================================================================== diff -u -rb8563cf263a8359d84834e4546d7741beed15118 -r8f813f8a94050f65846c119b2b0084007df6a86a --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensionsTest.cs (.../ProbabilisticPipingOutputCreateExtensionsTest.cs) (revision b8563cf263a8359d84834e4546d7741beed15118) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Create/Piping/Probabilistic/ProbabilisticPipingOutputCreateExtensionsTest.cs (.../ProbabilisticPipingOutputCreateExtensionsTest.cs) (revision 8f813f8a94050f65846c119b2b0084007df6a86a) @@ -58,6 +58,8 @@ Assert.AreEqual(output.SectionSpecificOutput.Reliability, entity.SectionSpecificReliability); Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity1); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1); } [Test] @@ -76,25 +78,56 @@ Assert.IsNull(entity.SectionSpecificReliability); Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity1); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1); } [Test] - public void Create_CalculationWithOutputAndGeneralResult_ReturnEntityWithOutputAndGeneralResult() + public void Create_CalculationWithOutputWithFaultTreeIllustrationPoints_ReturnEntityWithOutputAndGeneralResult() { // Setup - var output = new ProbabilisticPipingOutput(PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(), - PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput()); + PartialProbabilisticFaultTreePipingOutput profileSpecificOutput = PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(); + PartialProbabilisticFaultTreePipingOutput sectionSpecificOutput = PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(); + var output = new ProbabilisticPipingOutput(profileSpecificOutput, sectionSpecificOutput); // Call ProbabilisticPipingCalculationOutputEntity entity = output.Create(); // Assert Assert.AreEqual(output.ProfileSpecificOutput.Reliability, entity.ProfileSpecificReliability); Assert.AreEqual(output.SectionSpecificOutput.Reliability, entity.SectionSpecificReliability); - GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(((PartialProbabilisticFaultTreePipingOutput) output.ProfileSpecificOutput).GeneralResult, - entity.GeneralResultFaultTreeIllustrationPointEntity); - GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(((PartialProbabilisticFaultTreePipingOutput) output.SectionSpecificOutput).GeneralResult, - entity.GeneralResultFaultTreeIllustrationPointEntity1); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues( + profileSpecificOutput.GeneralResult, + entity.GeneralResultFaultTreeIllustrationPointEntity); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues( + sectionSpecificOutput.GeneralResult, + entity.GeneralResultFaultTreeIllustrationPointEntity1); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1); } + + [Test] + public void Create_CalculationWithOutputWithSubMechanismIllustrationPoints_ReturnEntityWithOutputAndGeneralResult() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput profileSpecificOutput = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(); + PartialProbabilisticSubMechanismPipingOutput sectionSpecificOutput = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(); + var output = new ProbabilisticPipingOutput(profileSpecificOutput, sectionSpecificOutput); + + // Call + ProbabilisticPipingCalculationOutputEntity entity = output.Create(); + + // Assert + Assert.AreEqual(output.ProfileSpecificOutput.Reliability, entity.ProfileSpecificReliability); + Assert.AreEqual(output.SectionSpecificOutput.Reliability, entity.SectionSpecificReliability); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues( + profileSpecificOutput.GeneralResult, + entity.GeneralResultSubMechanismIllustrationPointEntity); + GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues( + sectionSpecificOutput.GeneralResult, + entity.GeneralResultSubMechanismIllustrationPointEntity1); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity); + Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity1); + } } } \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/IllustrationPoints/GeneralResultEntityTestHelper.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r8f813f8a94050f65846c119b2b0084007df6a86a --- Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/IllustrationPoints/GeneralResultEntityTestHelper.cs (.../GeneralResultEntityTestHelper.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Storage/test/Riskeer.Storage.Core.TestUtil/IllustrationPoints/GeneralResultEntityTestHelper.cs (.../GeneralResultEntityTestHelper.cs) (revision 8f813f8a94050f65846c119b2b0084007df6a86a) @@ -21,6 +21,7 @@ using System; using System.Linq; +using Core.Common.TestUtil; using NUnit.Framework; using Riskeer.Common.Data.IllustrationPoints; using Riskeer.Common.Data.TestUtil; @@ -70,5 +71,45 @@ Assert.AreEqual(generalResult.Stochasts.Count(), generalResultEntity.StochastEntities.Count); Assert.AreEqual(generalResult.TopLevelIllustrationPoints.Count(), generalResultEntity.TopLevelFaultTreeIllustrationPointEntities.Count); } + + /// + /// Determines for each property of whether the matching + /// property of has an equal value. + /// + /// The to compare. + /// The + /// to compare. + /// Thrown if any of the argument is null. + /// Thrown when: + /// + /// The values of the governing wind direction name and angles do not match. + /// The count of the stochasts do not match. + /// The count of the top level illustration points do not match. + /// + /// This only asserts the properties of the + /// that are directly associated with it, but not the values of the items it is composed of. + public static void AssertGeneralResultPropertyValues(GeneralResult generalResult, + GeneralResultSubMechanismIllustrationPointEntity generalResultEntity) + { + if (generalResult == null) + { + throw new ArgumentNullException(nameof(generalResult)); + } + + if (generalResultEntity == null) + { + throw new ArgumentNullException(nameof(generalResultEntity)); + } + + Assert.IsNotNull(generalResultEntity); + WindDirection governingWindDirection = generalResult.GoverningWindDirection; + TestHelper.AssertAreEqualButNotSame(governingWindDirection.Name, generalResultEntity.GoverningWindDirectionName); + Assert.AreEqual(governingWindDirection.Angle, generalResultEntity.GoverningWindDirectionAngle, + governingWindDirection.Angle.GetAccuracy()); + + Assert.AreEqual(generalResult.Stochasts.Count(), generalResultEntity.StochastEntities.Count); + Assert.AreEqual(generalResult.TopLevelIllustrationPoints.Count(), + generalResultEntity.TopLevelSubMechanismIllustrationPointEntities.Count); + } } } \ No newline at end of file