/// <summary>
        /// Read the <see cref="ProbabilisticPipingCalculationOutputEntity"/> and use the information to
        /// construct a <see cref="ProbabilisticPipingOutput"/>.
        /// </summary>
        /// <param name="entity">The <see cref="ProbabilisticPipingCalculationOutputEntity"/> to create
        /// <see cref="ProbabilisticPipingOutput"/> for.</param>
        /// <returns>A new <see cref="ProbabilisticPipingOutput"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/>
        /// is <c>null</c>.</exception>
        public static ProbabilisticPipingOutput Read(this ProbabilisticPipingCalculationOutputEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            double sectionSpecificReliability = entity.SectionSpecificReliability.ToNullAsNaN();
            double profileSpecificReliability = entity.ProfileSpecificReliability.ToNullAsNaN();

            if (entity.GeneralResultSubMechanismIllustrationPointEntity != null || entity.GeneralResultSubMechanismIllustrationPointEntity1 != null)
            {
                return(new ProbabilisticPipingOutput(
                           new PartialProbabilisticSubMechanismPipingOutput(
                               sectionSpecificReliability,
                               entity.GeneralResultSubMechanismIllustrationPointEntity1?.Read()),
                           new PartialProbabilisticSubMechanismPipingOutput(
                               profileSpecificReliability,
                               entity.GeneralResultSubMechanismIllustrationPointEntity?.Read())));
            }

            return(new ProbabilisticPipingOutput(
                       new PartialProbabilisticFaultTreePipingOutput(
                           sectionSpecificReliability,
                           entity.GeneralResultFaultTreeIllustrationPointEntity1?.Read()),
                       new PartialProbabilisticFaultTreePipingOutput(
                           profileSpecificReliability,
                           entity.GeneralResultFaultTreeIllustrationPointEntity?.Read())));
        }
Пример #2
0
        public void Create_HasCalculationOutput_EntityHasPipingCalculationOutputEntity()
        {
            // Setup
            var registry = new PersistenceRegistry();

            var output = new ProbabilisticPipingOutput(PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(),
                                                       PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput());

            var calculation = new ProbabilisticPipingCalculationScenario
            {
                Output = output
            };

            // Call
            ProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            ProbabilisticPipingCalculationOutputEntity outputEntity = entity.ProbabilisticPipingCalculationOutputEntities.SingleOrDefault();

            Assert.IsNotNull(outputEntity);
            Assert.AreEqual(output.ProfileSpecificOutput.Reliability, outputEntity.ProfileSpecificReliability);
            Assert.AreEqual(output.SectionSpecificOutput.Reliability, outputEntity.SectionSpecificReliability);
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(((PartialProbabilisticFaultTreePipingOutput)output.ProfileSpecificOutput).GeneralResult,
                                                                            outputEntity.GeneralResultFaultTreeIllustrationPointEntity);
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(((PartialProbabilisticFaultTreePipingOutput)output.SectionSpecificOutput).GeneralResult,
                                                                            outputEntity.GeneralResultFaultTreeIllustrationPointEntity1);
        }
        /// <summary>
        /// Creates a <see cref="ProbabilisticPipingCalculationOutputEntity"/> based on the information
        /// of the <see cref="ProbabilisticPipingOutput"/>.
        /// </summary>
        /// <param name="output">The calculation output for piping failure mechanism to
        /// create a database entity for.</param>
        /// <returns>A new <see cref="ProbabilisticPipingCalculationOutputEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="output"/>
        /// is <c>null</c>.</exception>
        public static ProbabilisticPipingCalculationOutputEntity Create(this ProbabilisticPipingOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var outputEntity = new ProbabilisticPipingCalculationOutputEntity
            {
                ProfileSpecificReliability = output.ProfileSpecificOutput.Reliability.ToNaNAsNull(),
                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);
        }
Пример #4
0
        private static void ReadCalculationOutputs(ProbabilisticPipingCalculationScenario calculation,
                                                   ProbabilisticPipingCalculationEntity entity)
        {
            ProbabilisticPipingCalculationOutputEntity calculationOutputEntity = entity.ProbabilisticPipingCalculationOutputEntities.SingleOrDefault();

            if (calculationOutputEntity != null)
            {
                calculation.Output = calculationOutputEntity.Read();
            }
        }
        public void Create_CalculationWithOutput_ReturnEntityWithOutput()
        {
            // Setup
            var output = new ProbabilisticPipingOutput(PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(null),
                                                       PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput(null));

            // Call
            ProbabilisticPipingCalculationOutputEntity entity = output.Create();

            // Assert
            Assert.AreEqual(output.ProfileSpecificOutput.Reliability, entity.ProfileSpecificReliability);
            Assert.AreEqual(output.SectionSpecificOutput.Reliability, entity.SectionSpecificReliability);
            Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity);
            Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity1);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1);
        }
        public void Create_CalculationWithNaNOutput_ReturnEntityWithNullOutput()
        {
            // Setup
            var output = new ProbabilisticPipingOutput(
                new PartialProbabilisticFaultTreePipingOutput(double.NaN, null),
                new PartialProbabilisticFaultTreePipingOutput(double.NaN, null));

            // Call
            ProbabilisticPipingCalculationOutputEntity entity = output.Create();

            // Assert
            Assert.IsNull(entity.ProfileSpecificReliability);
            Assert.IsNull(entity.SectionSpecificReliability);
            Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity);
            Assert.IsNull(entity.GeneralResultFaultTreeIllustrationPointEntity1);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1);
        }
Пример #7
0
        public void Read_EntityWithSubMechanismIllustrationPoints_ReturnProbabilisticPipingOutput()
        {
            // Setup
            var random = new Random(21);
            var profileSpecificGeneralResultEntity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble()
            };
            var sectionSpecificGeneralResultEntity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSW",
                GoverningWindDirectionAngle = random.NextDouble()
            };

            var entity = new ProbabilisticPipingCalculationOutputEntity
            {
                ProfileSpecificReliability = random.NextDouble(),
                SectionSpecificReliability = random.NextDouble(),
                GeneralResultFaultTreeIllustrationPointEntity     = null,
                GeneralResultFaultTreeIllustrationPointEntity1    = null,
                GeneralResultSubMechanismIllustrationPointEntity  = profileSpecificGeneralResultEntity,
                GeneralResultSubMechanismIllustrationPointEntity1 = sectionSpecificGeneralResultEntity
            };

            // Call
            ProbabilisticPipingOutput output = entity.Read();

            // Assert
            var profileSpecificOutput = (PartialProbabilisticSubMechanismPipingOutput)output.ProfileSpecificOutput;
            var sectionSpecificOutput = (PartialProbabilisticSubMechanismPipingOutput)output.SectionSpecificOutput;

            Assert.AreEqual(entity.ProfileSpecificReliability, output.ProfileSpecificOutput.Reliability);
            Assert.AreEqual(entity.SectionSpecificReliability, output.SectionSpecificOutput.Reliability);

            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(
                profileSpecificOutput.GeneralResult, profileSpecificGeneralResultEntity);
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(
                sectionSpecificOutput.GeneralResult, sectionSpecificGeneralResultEntity);
        }
Пример #8
0
        public void Read_ValidEntityWithNullParameterValues_ReturnProbabilisticPipingOutput()
        {
            // Setup
            var entity = new ProbabilisticPipingCalculationOutputEntity
            {
                ProfileSpecificReliability = null,
                SectionSpecificReliability = null,
                GeneralResultFaultTreeIllustrationPointEntity     = null,
                GeneralResultFaultTreeIllustrationPointEntity1    = null,
                GeneralResultSubMechanismIllustrationPointEntity  = null,
                GeneralResultSubMechanismIllustrationPointEntity1 = null
            };

            // Call
            ProbabilisticPipingOutput output = entity.Read();

            // Assert
            Assert.IsNaN(output.ProfileSpecificOutput.Reliability);
            Assert.IsNull(((PartialProbabilisticFaultTreePipingOutput)output.ProfileSpecificOutput).GeneralResult);
            Assert.IsNaN(output.SectionSpecificOutput.Reliability);
            Assert.IsNull(((PartialProbabilisticFaultTreePipingOutput)output.ProfileSpecificOutput).GeneralResult);
        }
        public void Create_CalculationWithOutputWithFaultTreeIllustrationPoints_ReturnEntityWithOutputAndGeneralResult()
        {
            // Setup
            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(
                profileSpecificOutput.GeneralResult,
                entity.GeneralResultFaultTreeIllustrationPointEntity);
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(
                sectionSpecificOutput.GeneralResult,
                entity.GeneralResultFaultTreeIllustrationPointEntity1);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity);
            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity1);
        }