Example #1
0
        public void Read_WithGeneralResultEntity_ReturnsDikeHeightOutputWithGeneralResult()
        {
            // Setup
            var random = new Random(22);

            var generalResultEntity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble()
            };

            var convergence = random.NextEnumValue <CalculationConvergence>();
            var entity      = new GrassCoverErosionInwardsDikeHeightOutputEntity
            {
                CalculationConvergence = Convert.ToByte(convergence),
                GeneralResultFaultTreeIllustrationPointEntity = generalResultEntity
            };

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

            // Assert
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult,
                                                                            generalResultEntity);
        }
        public void Read_ValidEntityWithStochasts_ReturnsGeneralResultFaultTreeIllustrationPoint()
        {
            // Setup
            var random = new Random(21);

            var entity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                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 <TopLevelFaultTreeIllustrationPoint> generalResult = entity.Read();

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

            var generalResult = new GeneralResult <TopLevelFaultTreeIllustrationPoint>(
                new WindDirection("SSE", random.NextDouble()),
                Enumerable.Empty <Stochast>(),
                new[]
            {
                new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "IllustrationPointOne",
                    new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint())),
                new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "IllustrationPointTwo",
                    new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()))
            });

            // Call
            GeneralResultFaultTreeIllustrationPointEntity entity =
                generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity();

            // Assert
            AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity);
        }
        public void Read_ValidEntityWithGeneralResultEntity_ReturnsGrassCoverErosionInwardsOutputWithGeneralResult()
        {
            // Setup
            var generalResultEntity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionAngle = 10,
                GoverningWindDirectionName  = "SSE"
            };
            var entity = new GrassCoverErosionInwardsOutputEntity
            {
                WaveHeight            = null,
                IsOvertoppingDominant = Convert.ToByte(true),
                Reliability           = null,
                GeneralResultFaultTreeIllustrationPointEntity = generalResultEntity
            };

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

            // Assert
            OvertoppingOutput overtoppingOutput = output.OvertoppingOutput;

            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(overtoppingOutput.GeneralResult,
                                                                            generalResultEntity);
        }
        private static void AssertGeneralResultFaultTreeIllustrationPointEntity(
            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult,
            GeneralResultFaultTreeIllustrationPointEntity entity)
        {
            AssertWindDirection(generalResult.GoverningWindDirection, entity);

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

            AssertTopLevelIllustrationPointEntities(generalResult.TopLevelIllustrationPoints.ToArray(),
                                                    entity.TopLevelFaultTreeIllustrationPointEntities.ToArray());
        }
        private static void AddEntitiesForTopLevelFaultTreeIllustrationPoints(
            GeneralResultFaultTreeIllustrationPointEntity entity,
            IEnumerable <TopLevelFaultTreeIllustrationPoint> illustrationPoints)
        {
            var order = 0;

            foreach (TopLevelFaultTreeIllustrationPoint illustrationPoint in illustrationPoints)
            {
                entity.TopLevelFaultTreeIllustrationPointEntities.Add(
                    illustrationPoint.Create(order++));
            }
        }
        public void Read_ValidEntityWithIllustrationPoints_ReturnsGeneralResultFaultTreeIllustrationPoint()
        {
            // Setup
            var random = new Random(210);

            var topLevelFaultTreeIllustrationPointEntities = new[]
            {
                new TopLevelFaultTreeIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionOne",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationOne",
                    FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity
                    {
                        Beta            = random.NextDouble(),
                        CombinationType = Convert.ToByte(random.NextEnumValue <CombinationType>()),
                        Name            = "IllustrationPointOne"
                    },
                    Order = 0
                },
                new TopLevelFaultTreeIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionTwo",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationTwo",
                    FaultTreeIllustrationPointEntity = new FaultTreeIllustrationPointEntity
                    {
                        Beta            = random.NextDouble(),
                        CombinationType = Convert.ToByte(random.NextEnumValue <CombinationType>()),
                        Name            = "IllustrationPointTwo"
                    },
                    Order = 1
                }
            };

            var entity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble(),
                TopLevelFaultTreeIllustrationPointEntities = topLevelFaultTreeIllustrationPointEntities
            };

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

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

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

            // Call
            GeneralResultFaultTreeIllustrationPointEntity entity =
                generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity();

            // Assert
            AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity);
        }
        public void Read_ValidEntity_ReturnsGeneralResult()
        {
            // Setup
            var entity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = new Random(213).NextDouble()
            };

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

            // Assert
            AssertWindDirection(entity, generalResult.GoverningWindDirection);
            CollectionAssert.IsEmpty(generalResult.Stochasts);
            CollectionAssert.IsEmpty(generalResult.TopLevelIllustrationPoints);
        }
        /// <summary>
        /// Creates a <see cref="GeneralResultFaultTreeIllustrationPointEntity"/> based on the
        /// information of <paramref name="generalResult"/>.
        /// </summary>
        /// <param name="generalResult">The general result to create a database entity for.</param>
        /// <returns>A new <see cref="GeneralResultFaultTreeIllustrationPointEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="generalResult"/>
        /// is <c>null</c>.</exception>
        public static GeneralResultFaultTreeIllustrationPointEntity CreateGeneralResultFaultTreeIllustrationPointEntity(
            this GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult)
        {
            if (generalResult == null)
            {
                throw new ArgumentNullException(nameof(generalResult));
            }

            var entity = new GeneralResultFaultTreeIllustrationPointEntity();

            SetGoverningWindDirection(entity, generalResult.GoverningWindDirection);

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

            return(entity);
        }
        /// <summary>
        /// Reads the <see cref="GeneralResultFaultTreeIllustrationPointEntity"/> and uses
        /// the information to construct a <see cref="GeneralResult{T}"/>.
        /// </summary>
        /// <param name="entity">The <see cref="GeneralResultFaultTreeIllustrationPointEntity"/>
        /// 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 <TopLevelFaultTreeIllustrationPoint> Read(
            this GeneralResultFaultTreeIllustrationPointEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            WindDirection governingWindDirection = GetGoverningWindDirection(entity);

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

            IEnumerable <TopLevelFaultTreeIllustrationPoint> topLevelIllustrationPoints =
                GetReadTopLevelFaultTreeIllustrationPoint(entity.TopLevelFaultTreeIllustrationPointEntities);

            return(new GeneralResult <TopLevelFaultTreeIllustrationPoint>(governingWindDirection,
                                                                          stochasts,
                                                                          topLevelIllustrationPoints));
        }
        public void CreateGeneralResultFaultTreeIllustrationPointEntity_ValidGeneralResultWithStochasts_ReturnsEntityWithStochastsEntities()
        {
            // Setup
            var random = new Random(22);

            var generalResult = new GeneralResult <TopLevelFaultTreeIllustrationPoint>(
                new WindDirection("SSE", random.NextDouble()),
                new[]
            {
                new Stochast("stochastOne", random.NextDouble(), random.NextDouble()),
                new Stochast("stochastTwo", random.NextDouble(), random.NextDouble())
            },
                Enumerable.Empty <TopLevelFaultTreeIllustrationPoint>());

            // Call
            GeneralResultFaultTreeIllustrationPointEntity entity =
                generalResult.CreateGeneralResultFaultTreeIllustrationPointEntity();

            // Assert
            AssertGeneralResultFaultTreeIllustrationPointEntity(generalResult, entity);
        }
Example #13
0
        public void Read_EntityWithFaultTreeIllustrationPoints_ReturnProbabilisticPipingOutput()
        {
            // Setup
            var random = new Random(21);
            var profileSpecificGeneralResultEntity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSE",
                GoverningWindDirectionAngle = random.NextDouble()
            };
            var sectionSpecificGeneralResultEntity = new GeneralResultFaultTreeIllustrationPointEntity
            {
                GoverningWindDirectionName  = "SSW",
                GoverningWindDirectionAngle = random.NextDouble()
            };

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

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

            // Assert
            var profileSpecificOutput = (PartialProbabilisticFaultTreePipingOutput)output.ProfileSpecificOutput;
            var sectionSpecificOutput = (PartialProbabilisticFaultTreePipingOutput)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);
        }
Example #14
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="GeneralResultFaultTreeIllustrationPointEntity"/>
        /// 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="GeneralResultFaultTreeIllustrationPointEntity"/>
        /// that are directly associated with it, but not the values of the items it is composed of.</remarks>
        public static void AssertGeneralResultPropertyValues(GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult,
                                                             GeneralResultFaultTreeIllustrationPointEntity generalResultEntity)
        {
            if (generalResult == null)
            {
                throw new ArgumentNullException(nameof(generalResult));
            }

            if (generalResultEntity == null)
            {
                throw new ArgumentNullException(nameof(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.TopLevelFaultTreeIllustrationPointEntities.Count);
        }