Exemplo n.º 1
0
        public void Read_ValidEntityWithStochasts_ReturnsGeneralResultSubMechanismIllustrationPoint()
        {
            // Setup
            var random = new Random(21);

            var entity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble(),
                StochastEntities            = new[]
                {
                    new StochastEntity
                    {
                        Name     = "stochastEntityOne",
                        Duration = random.NextDouble(),
                        Alpha    = random.NextDouble(),
                        Order    = 0
                    },
                    new StochastEntity
                    {
                        Name     = "stochastEntityTwo",
                        Duration = random.NextDouble(),
                        Alpha    = random.NextDouble(),
                        Order    = 1
                    }
                }
            };

            // Call
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = entity.Read();

            // Assert
            AssertWindDirection(entity, generalResult.GoverningWindDirection);
            AssertStochasts(entity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray());
        }
        public void CreateGeneralResultSubMechanismIllustrationPointEntity_ValidGeneralResultWithIllustrationPoints_ReturnsEntityWithTopLevelSubMechanismIllustrationPointEntities()
        {
            // Setup
            var random = new Random(21);

            var generalResult = new GeneralResult <TopLevelSubMechanismIllustrationPoint>(
                new WindDirection("SSE", random.NextDouble()),
                Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                new[]
            {
                new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(),
                                                          "IllustrationPointOne",
                                                          new TestSubMechanismIllustrationPoint()),
                new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(),
                                                          "IllustrationPointTwo",
                                                          new TestSubMechanismIllustrationPoint())
            });

            // Call
            GeneralResultSubMechanismIllustrationPointEntity entity =
                generalResult.CreateGeneralResultSubMechanismIllustrationPointEntity();

            // Assert
            AssertGeneralResultSubMechanismIllustrationPointEntity(generalResult, entity);
        }
        private static void AssertGeneralResultSubMechanismIllustrationPointEntity(
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult,
            GeneralResultSubMechanismIllustrationPointEntity entity)
        {
            AssertWindDirection(generalResult.GoverningWindDirection, entity);

            AssertStochastEntities(generalResult.Stochasts.ToArray(), entity.StochastEntities.ToArray());

            AssertTopLevelIllustrationPointEntities(generalResult.TopLevelIllustrationPoints.ToArray(),
                                                    entity.TopLevelSubMechanismIllustrationPointEntities.ToArray());
        }
        private static void AddEntitiesForTopLevelSubMechanismIllustrationPoints(
            GeneralResultSubMechanismIllustrationPointEntity entity,
            IEnumerable <TopLevelSubMechanismIllustrationPoint> illustrationPoints)
        {
            var order = 0;

            foreach (TopLevelSubMechanismIllustrationPoint illustrationPoint in illustrationPoints)
            {
                entity.TopLevelSubMechanismIllustrationPointEntities.Add(
                    illustrationPoint.Create(order++));
            }
        }
Exemplo n.º 5
0
        public void Read_ValidEntityWithIllustrationPoints_ReturnsGeneralResultSubMechanismIllustrationPoint()
        {
            // Setup
            var random = new Random(210);

            var topLevelSubMechanismIllustrationPointEntities = new[]
            {
                new TopLevelSubMechanismIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionOne",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationOne",
                    SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity
                    {
                        Beta = random.NextDouble(),
                        Name = "IllustrationPointOne"
                    },
                    Order = 0
                },
                new TopLevelSubMechanismIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionTwo",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationTwo",
                    SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity
                    {
                        Beta = random.NextDouble(),
                        Name = "IllustrationPointTwo"
                    },
                    Order = 1
                }
            };

            var entity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble(),
                TopLevelSubMechanismIllustrationPointEntities = topLevelSubMechanismIllustrationPointEntities
            };

            // Call
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = entity.Read();

            // Assert
            AssertWindDirection(entity, generalResult.GoverningWindDirection);
            AssertTopLevelSubMechanismIllustrationPoints(entity.TopLevelSubMechanismIllustrationPointEntities.ToArray(),
                                                         generalResult.TopLevelIllustrationPoints.ToArray());
        }
        public void CreateGeneralResultSubMechanismIllustrationPointEntity_ValidGeneralResult_ReturnsEntityWithoutStochastsAndTopLevelSubMechanismIllustrationPointEntities()
        {
            // Setup
            var random = new Random(21);

            var generalResult = new GeneralResult <TopLevelSubMechanismIllustrationPoint>(
                new WindDirection("SSE", random.NextDouble()),
                Enumerable.Empty <Stochast>(),
                Enumerable.Empty <TopLevelSubMechanismIllustrationPoint>());

            // Call
            GeneralResultSubMechanismIllustrationPointEntity entity =
                generalResult.CreateGeneralResultSubMechanismIllustrationPointEntity();

            // Assert
            AssertGeneralResultSubMechanismIllustrationPointEntity(generalResult, entity);
        }
Exemplo n.º 7
0
        public void Read_ValidEntityWithoutStochastsAndIllustrationPoints_ReturnsGeneralResultSubMechanismIllustrationPoint()
        {
            // Setup
            var entity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = new Random(21).NextDouble()
            };

            // Call
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = entity.Read();

            // Assert
            AssertWindDirection(entity, generalResult.GoverningWindDirection);
            CollectionAssert.IsEmpty(generalResult.Stochasts);
            CollectionAssert.IsEmpty(generalResult.TopLevelIllustrationPoints);
        }
Exemplo n.º 8
0
        private static void AssertGeneralResult(GeneralResultSubMechanismIllustrationPointEntity expected,
                                                GeneralResult <TopLevelSubMechanismIllustrationPoint> illustrationPoint)
        {
            if (expected == null)
            {
                Assert.IsNull(illustrationPoint);
                return;
            }

            WindDirection actualGoverningWindDirection = illustrationPoint.GoverningWindDirection;

            Assert.AreEqual(expected.GoverningWindDirectionName, actualGoverningWindDirection.Name);
            Assert.AreEqual(expected.GoverningWindDirectionAngle, actualGoverningWindDirection.Angle,
                            actualGoverningWindDirection.Angle.GetAccuracy());

            Assert.AreEqual(expected.TopLevelSubMechanismIllustrationPointEntities.Count,
                            illustrationPoint.TopLevelIllustrationPoints.Count());
            Assert.AreEqual(expected.StochastEntities.Count, illustrationPoint.Stochasts.Count());
        }
Exemplo n.º 9
0
        private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputAndGeneralResultEntity(int seed)
        {
            var random = new Random(seed);
            var generalResultEntity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "A wind direction",
                GoverningWindDirectionAngle = random.NextDouble()
            };

            HydraulicLocationOutputEntity hydraulicLocationOutputEntity = CreateHydraulicOutputEntity(seed);

            hydraulicLocationOutputEntity.GeneralResultSubMechanismIllustrationPointEntity = generalResultEntity;

            HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed);

            calculationEntity.HydraulicLocationOutputEntities.Add(hydraulicLocationOutputEntity);

            return(calculationEntity);
        }
        /// <summary>
        /// Creates a <see cref="GeneralResultSubMechanismIllustrationPointEntity"/> based on
        /// the information of <paramref name="generalResult"/>.
        /// </summary>
        /// <param name="generalResult">The general result sub mechanism to create a database
        /// entity for.</param>
        /// <returns>A new <see cref="GeneralResultSubMechanismIllustrationPointEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="generalResult"/>
        /// is <c>null</c>.</exception>
        public static GeneralResultSubMechanismIllustrationPointEntity CreateGeneralResultSubMechanismIllustrationPointEntity(
            this GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult)
        {
            if (generalResult == null)
            {
                throw new ArgumentNullException(nameof(generalResult));
            }

            var entity = new GeneralResultSubMechanismIllustrationPointEntity();

            SetGoverningWindDirection(entity, generalResult.GoverningWindDirection);

            AddEntitiesForStochasts(entity, generalResult.Stochasts);
            AddEntitiesForTopLevelSubMechanismIllustrationPoints(
                entity,
                generalResult.TopLevelIllustrationPoints);

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

            WindDirection governingWindDirection = GetGoverningWindDirection(entity);

            IEnumerable <Stochast> stochasts = GetReadStochasts(entity.StochastEntities);

            IEnumerable <TopLevelSubMechanismIllustrationPoint> topLevelIllustrationPoints =
                GetReadTopLevelSubMechanismIllustrationPoint(entity.TopLevelSubMechanismIllustrationPointEntities);

            return(new GeneralResult <TopLevelSubMechanismIllustrationPoint>(governingWindDirection,
                                                                             stochasts,
                                                                             topLevelIllustrationPoints));
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Determines for each property of <paramref name="generalResultEntity"/> whether the matching
        /// property of <paramref name="generalResult"/> has an equal value.
        /// </summary>
        /// <param name="generalResult">The <see cref="GeneralResult{T}"/> to compare.</param>
        /// <param name="generalResultEntity">The <see cref="GeneralResultSubMechanismIllustrationPointEntity"/>
        /// to compare.</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the argument is <c>null</c>.</exception>
        /// <exception cref="AssertionException">Thrown when:
        /// <list type="bullet">
        /// <item>The values of the governing wind direction name and angles do not match.</item>
        /// <item>The count of the stochasts do not match.</item>
        /// <item>The count of the top level illustration points do not match.</item>
        /// </list></exception>
        /// <remarks>This only asserts the properties of the <see cref="GeneralResultSubMechanismIllustrationPointEntity"/>
        /// that are directly associated with it, but not the values of the items it is composed of.</remarks>
        public static void AssertGeneralResultPropertyValues(GeneralResult <TopLevelSubMechanismIllustrationPoint> 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;

            Assert.AreEqual(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);
        }
Exemplo n.º 14
0
        public void Read_EntityWithIllustrationPoints_ReturnsHydraulicBoundaryLocationCalculationOutputWithGeneralResult()
        {
            // Setup
            var random = new Random(21);

            var stochastEntities = new[]
            {
                new StochastEntity
                {
                    Name     = "stochastEntityOne",
                    Duration = random.NextDouble(),
                    Alpha    = random.NextDouble(),
                    Order    = 0
                }
            };
            var topLevelIllustrationPointEntities = new[]
            {
                new TopLevelSubMechanismIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionTwo",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationTwo",
                    SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity
                    {
                        Beta = random.NextDouble(),
                        Name = "IllustrationPointTwo"
                    },
                    Order = 0
                }
            };

            var entity = new HydraulicLocationOutputEntity
            {
                Result                 = double.NaN,
                TargetProbability      = double.NaN,
                TargetReliability      = double.NaN,
                CalculatedProbability  = double.NaN,
                CalculatedReliability  = double.NaN,
                CalculationConvergence = Convert.ToByte(random.NextEnumValue <CalculationConvergence>()),
                GeneralResultSubMechanismIllustrationPointEntity = new GeneralResultSubMechanismIllustrationPointEntity
                {
                    GoverningWindDirectionName  = "SSE",
                    GoverningWindDirectionAngle = random.NextDouble(),
                    StochastEntities            = stochastEntities,
                    TopLevelSubMechanismIllustrationPointEntities = topLevelIllustrationPointEntities
                }
            };

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

            // Assert
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult       = output.GeneralResult;
            GeneralResultSubMechanismIllustrationPointEntity      generalResultEntity =
                entity.GeneralResultSubMechanismIllustrationPointEntity;

            AssertWindDirection(generalResultEntity, generalResult.GoverningWindDirection);
            AssertStochasts(generalResultEntity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray());
            AssertIllustrationPoints(generalResultEntity.TopLevelSubMechanismIllustrationPointEntities.ToArray(),
                                     generalResult.TopLevelIllustrationPoints.ToArray());
        }