Exemplo n.º 1
0
        public void Create_GroupWithChildHeightStructuresCalculationsAndChildCalculationGroups_CreateEntities()
        {
            // Setup
            var group = new CalculationGroup
            {
                Children =
                {
                    new CalculationGroup
                    {
                        Name = "A"
                    },
                    new StructuresCalculationScenario <HeightStructuresInput>
                    {
                        Name = "B"
                    },
                    new CalculationGroup
                    {
                        Name = "C"
                    },
                    new StructuresCalculationScenario <HeightStructuresInput>
                    {
                        Name = "D"
                    }
                }
            };

            var registry = new PersistenceRegistry();

            // Call
            CalculationGroupEntity entity = group.Create(registry, 0);

            // Assert
            CalculationGroupEntity[]            childGroupEntities       = entity.CalculationGroupEntity1.ToArray();
            HeightStructuresCalculationEntity[] childCalculationEntities = entity.HeightStructuresCalculationEntities.ToArray();
            Assert.AreEqual(2, childGroupEntities.Length);
            Assert.AreEqual(2, childCalculationEntities.Length);

            CalculationGroupEntity childEntity1 = childGroupEntities[0];

            Assert.AreEqual("A", childEntity1.Name);
            Assert.AreEqual(0, childEntity1.Order);
            CollectionAssert.IsEmpty(childEntity1.CalculationGroupEntity1);

            HeightStructuresCalculationEntity childEntity2 = childCalculationEntities[0];

            Assert.AreEqual("B", childEntity2.Name);
            Assert.AreEqual(1, childEntity2.Order);

            CalculationGroupEntity childEntity3 = childGroupEntities[1];

            Assert.AreEqual("C", childEntity3.Name);
            Assert.AreEqual(2, childEntity3.Order);
            CollectionAssert.IsEmpty(childEntity3.CalculationGroupEntity1);

            HeightStructuresCalculationEntity childEntity4 = childCalculationEntities[1];

            Assert.AreEqual("D", childEntity4.Name);
            Assert.AreEqual(3, childEntity4.Order);
        }
Exemplo n.º 2
0
 private static void SetHeightStructuresOutputEntity(StructuresCalculation <HeightStructuresInput> calculation,
                                                     HeightStructuresCalculationEntity entity)
 {
     if (calculation.HasOutput)
     {
         entity.HeightStructuresOutputEntities.Add(calculation
                                                   .Output
                                                   .Create <HeightStructuresOutputEntity>());
     }
 }
        public void Read_ReadConversionCollectorNull_ThrowArgumentNullException()
        {
            // Setup
            var entity = new HeightStructuresCalculationEntity();

            // Call
            void Call() => entity.Read(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("collector", exception.ParamName);
        }
        private static void ReadOutput(StructuresCalculation <HeightStructuresInput> calculation,
                                       HeightStructuresCalculationEntity entity)
        {
            HeightStructuresOutputEntity outputEntity = entity.HeightStructuresOutputEntities.SingleOrDefault();

            if (outputEntity == null)
            {
                return;
            }

            var output = new StructuresOutput(outputEntity.Reliability.ToNullAsNaN(),
                                              outputEntity.GeneralResultFaultTreeIllustrationPointEntity?.Read());

            calculation.Output = output;
        }
        private static void ReadInputParameters(HeightStructuresInput inputParameters,
                                                HeightStructuresCalculationEntity entity,
                                                ReadConversionCollector collector)
        {
            if (entity.HeightStructureEntity != null)
            {
                inputParameters.Structure = entity.HeightStructureEntity.Read(collector);
            }

            entity.Read(inputParameters, collector);

            inputParameters.DeviationWaveDirection                = (RoundedDouble)entity.DeviationWaveDirection.ToNullAsNaN();
            inputParameters.ModelFactorSuperCriticalFlow.Mean     = (RoundedDouble)entity.ModelFactorSuperCriticalFlowMean.ToNullAsNaN();
            inputParameters.LevelCrestStructure.Mean              = (RoundedDouble)entity.LevelCrestStructureMean.ToNullAsNaN();
            inputParameters.LevelCrestStructure.StandardDeviation = (RoundedDouble)entity.LevelCrestStructureStandardDeviation.ToNullAsNaN();
        }
Exemplo n.º 6
0
        private static void SetHeightStructuresInputValues(HeightStructuresCalculationEntity entity, HeightStructuresInput input,
                                                           PersistenceRegistry registry)
        {
            input.Create(entity, registry);

            if (input.Structure != null)
            {
                entity.HeightStructureEntity = registry.Get(input.Structure);
            }

            entity.DeviationWaveDirection = input.DeviationWaveDirection.ToNaNAsNull();

            entity.ModelFactorSuperCriticalFlowMean = input.ModelFactorSuperCriticalFlow.Mean.ToNaNAsNull();

            entity.LevelCrestStructureMean = input.LevelCrestStructure.Mean.ToNaNAsNull();
            entity.LevelCrestStructureStandardDeviation = input.LevelCrestStructure.StandardDeviation.ToNaNAsNull();
        }
        public void Read_EntityWithForeshoreProfile_ReturnCalculation(bool flagUsage, BreakWaterType type, int randomSeed)
        {
            // Setup
            var random = new Random(randomSeed);

            double breakWaterHeight = random.NextDouble();
            var    points           = new[]
            {
                new Point2D(0, 0)
            };
            string pointXml        = new Point2DCollectionXmlSerializer().ToXml(points);
            var    foreshoreEntity = new ForeshoreProfileEntity
            {
                Id = "id",
                BreakWaterHeight = breakWaterHeight,
                BreakWaterType   = Convert.ToByte(type),
                GeometryXml      = pointXml
            };

            var entity = new HeightStructuresCalculationEntity
            {
                UseForeshore           = Convert.ToByte(flagUsage),
                UseBreakWater          = Convert.ToByte(!flagUsage),
                ForeshoreProfileEntity = foreshoreEntity,
                BreakWaterType         = Convert.ToByte(type),
                BreakWaterHeight       = breakWaterHeight,
                ScenarioContribution   = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            HeightStructuresInput input = calculation.InputParameters;

            Assert.AreEqual(flagUsage, input.UseForeshore);
            Assert.AreEqual(!flagUsage, input.UseBreakWater);
            Assert.AreEqual(type, input.BreakWater.Type);
            Assert.AreEqual(breakWaterHeight, input.BreakWater.Height, input.BreakWater.Height.GetAccuracy());
            CollectionAssert.AreEqual(points, input.ForeshoreProfile.Geometry);
            Assert.IsNotNull(input.ForeshoreProfile);
        }
        public void Read_EntityWithNullParameters_ReturnHeightStructuresCalculationWithInputParametersNaN()
        {
            // Setup
            var entity = new HeightStructuresCalculationEntity
            {
                ScenarioContribution                               = 0,
                StructureNormalOrientation                         = null,
                ModelFactorSuperCriticalFlowMean                   = null,
                AllowedLevelIncreaseStorageMean                    = null,
                AllowedLevelIncreaseStorageStandardDeviation       = null,
                FlowWidthAtBottomProtectionMean                    = null,
                FlowWidthAtBottomProtectionStandardDeviation       = null,
                CriticalOvertoppingDischargeMean                   = null,
                CriticalOvertoppingDischargeCoefficientOfVariation = null,
                WidthFlowAperturesMean                             = null,
                WidthFlowAperturesStandardDeviation                = null,
                StormDurationMean       = null,
                LevelCrestStructureMean = null,
                LevelCrestStructureStandardDeviation = null,
                DeviationWaveDirection = null
            };
            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            HeightStructuresInput inputParameters = calculation.InputParameters;

            Assert.IsNaN(inputParameters.StructureNormalOrientation);
            Assert.IsNaN(inputParameters.ModelFactorSuperCriticalFlow.Mean);
            Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.Mean);
            Assert.IsNaN(inputParameters.AllowedLevelIncreaseStorage.StandardDeviation);
            Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.Mean);
            Assert.IsNaN(inputParameters.FlowWidthAtBottomProtection.StandardDeviation);
            Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.Mean);
            Assert.IsNaN(inputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation);
            Assert.IsNaN(inputParameters.WidthFlowApertures.Mean);
            Assert.IsNaN(inputParameters.WidthFlowApertures.StandardDeviation);
            Assert.IsNaN(inputParameters.StormDuration.Mean);
            Assert.IsNaN(inputParameters.LevelCrestStructure.Mean);
            Assert.IsNaN(inputParameters.LevelCrestStructure.StandardDeviation);
            Assert.IsNaN(inputParameters.DeviationWaveDirection);
        }
        public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities()
        {
            // Setup
            StructuresCalculationScenario <HeightStructuresInput> calculation = new TestHeightStructuresCalculationScenario();

            calculation.InputParameters.Structure = null;
            calculation.InputParameters.HydraulicBoundaryLocation = null;

            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new CalculationGroup
            {
                Name = "A"
            });
            failureMechanism.CalculationsGroup.Children.Add(calculation);

            var registry = new PersistenceRegistry();

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name);
            Assert.AreEqual(0, entity.CalculationGroupEntity.Order);

            CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1
                                                          .OrderBy(cge => cge.Order)
                                                          .ToArray();
            Assert.AreEqual(1, childGroupEntities.Length);
            CalculationGroupEntity childGroupEntity = childGroupEntities[0];

            Assert.AreEqual("A", childGroupEntity.Name);
            Assert.AreEqual(0, childGroupEntity.Order);

            HeightStructuresCalculationEntity[] calculationEntities = entity.CalculationGroupEntity.HeightStructuresCalculationEntities
                                                                      .OrderBy(ce => ce.Order)
                                                                      .ToArray();
            HeightStructuresCalculationEntity calculationEntity = calculationEntities[0];

            Assert.AreEqual("Nieuwe berekening", calculationEntity.Name);
            Assert.AreEqual(1, calculationEntity.Order);
        }
        public void Read_EntityWithStructureEntity_ReturnCalculationWithStructure()
        {
            // Setup
            HeightStructure structure       = new TestHeightStructure();
            var             structureEntity = new HeightStructureEntity();
            var             entity          = new HeightStructuresCalculationEntity
            {
                HeightStructureEntity = structureEntity,
                ScenarioContribution  = 0
            };
            var collector = new ReadConversionCollector();

            collector.Read(structureEntity, structure);

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(structure, calculation.InputParameters.Structure);
        }
        public void Read_EntityWithHydraulicLocationEntity_ReturnCalculationWithHydraulicBoundaryLocation()
        {
            // Setup
            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 2, 3);
            var hydraulicLocationEntity   = new HydraulicLocationEntity();
            var entity = new HeightStructuresCalculationEntity
            {
                HydraulicLocationEntity = hydraulicLocationEntity,
                ScenarioContribution    = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation);

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a <see cref="HeightStructuresCalculationEntity"/> based
        /// on the information of the <see cref="StructuresCalculationScenario{T}"/>.
        /// </summary>
        /// <param name="calculation">The calculation to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <param name="order">The index at where <paramref name="calculation"/> resides
        /// in its parent container.</param>
        /// <returns>A new <see cref="HeightStructuresCalculationEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static HeightStructuresCalculationEntity CreateForHeightStructures(this StructuresCalculationScenario <HeightStructuresInput> calculation,
                                                                                    PersistenceRegistry registry, int order)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            var entity = new HeightStructuresCalculationEntity
            {
                Name = calculation.Name.DeepClone(),
                RelevantForScenario  = Convert.ToByte(calculation.IsRelevant),
                ScenarioContribution = calculation.Contribution,
                Comments             = calculation.Comments.Body.DeepClone(),
                Order = order
            };

            SetHeightStructuresInputValues(entity, calculation.InputParameters, registry);
            SetHeightStructuresOutputEntity(calculation, entity);

            return(entity);
        }
        public void Read_ValidEntityWithOutputEntity_ReturnCalculationWithOutput()
        {
            // Setup
            var entity = new HeightStructuresCalculationEntity
            {
                HeightStructuresOutputEntities =
                {
                    new HeightStructuresOutputEntity()
                },
                ScenarioContribution = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            StructuresOutput calculationOutput = calculation.Output;

            Assert.IsNaN(calculationOutput.Reliability);
            Assert.IsFalse(calculationOutput.HasGeneralResult);
        }
        /// <summary>
        /// Reads the <see cref="HeightStructuresCalculationEntity"/> and use the
        /// information to update a <see cref="StructuresCalculationScenario{T}"/>.
        /// </summary>
        /// <param name="entity">The <see cref="HeightStructuresCalculationEntity"/>
        /// to create <see cref="StructuresCalculationScenario{T}"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="StructuresCalculationScenario{T}"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        internal static StructuresCalculationScenario <HeightStructuresInput> Read(this HeightStructuresCalculationEntity entity,
                                                                                   ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            var calculation = new StructuresCalculationScenario <HeightStructuresInput>
            {
                Name         = entity.Name,
                IsRelevant   = Convert.ToBoolean(entity.RelevantForScenario),
                Contribution = (RoundedDouble)entity.ScenarioContribution,
                Comments     =
                {
                    Body = entity.Comments
                }
            };

            ReadInputParameters(calculation.InputParameters, entity, collector);
            ReadOutput(calculation, entity);

            return(calculation);
        }
        public void Read_ValidEntity_ReturnCalculation(string name, string comments, int randomSeed)
        {
            // Setup
            var random = new Random(randomSeed);
            var entity = new HeightStructuresCalculationEntity
            {
                Name = name,
                RelevantForScenario                                = Convert.ToByte(true),
                ScenarioContribution                               = random.NextDouble(),
                Comments                                           = comments,
                UseForeshore                                       = Convert.ToByte(false),
                UseBreakWater                                      = Convert.ToByte(false),
                StructureNormalOrientation                         = random.NextDouble(0, 360),
                ModelFactorSuperCriticalFlowMean                   = random.NextDouble(-9999.9999, 9999.9999),
                AllowedLevelIncreaseStorageMean                    = random.NextDouble(1e-6, 9999.9999),
                AllowedLevelIncreaseStorageStandardDeviation       = random.NextDouble(1e-6, 9999.9999),
                FlowWidthAtBottomProtectionMean                    = random.NextDouble(1e-6, 9999.9999),
                FlowWidthAtBottomProtectionStandardDeviation       = random.NextDouble(1e-6, 9999.9999),
                CriticalOvertoppingDischargeMean                   = random.NextDouble(1e-6, 9999.9999),
                CriticalOvertoppingDischargeCoefficientOfVariation = random.NextDouble(1e-6, 9999.9999),
                FailureProbabilityStructureWithErosion             = random.NextDouble(),
                WidthFlowAperturesMean                             = random.NextDouble(1e-6, 9999.9999),
                WidthFlowAperturesStandardDeviation                = random.NextDouble(1e-6, 9999.9999),
                StormDurationMean                                  = random.NextDouble(1e-6, 9999.9999),
                LevelCrestStructureMean                            = random.NextDouble(1e-6, 9999.9999),
                LevelCrestStructureStandardDeviation               = random.NextDouble(1e-6, 9999.9999),
                DeviationWaveDirection                             = random.NextDouble(-360, 360)
            };

            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            Assert.AreEqual(name, calculation.Name);
            Assert.AreEqual(Convert.ToBoolean(entity.RelevantForScenario), calculation.IsRelevant);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.ScenarioContribution, calculation.Contribution);
            Assert.AreEqual(comments, calculation.Comments.Body);

            HeightStructuresInput input = calculation.InputParameters;

            Assert.IsFalse(input.UseForeshore);
            Assert.IsFalse(input.UseBreakWater);

            RoundedDoubleTestHelper.AssertRoundedDouble(entity.StructureNormalOrientation, input.StructureNormalOrientation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.ModelFactorSuperCriticalFlowMean, input.ModelFactorSuperCriticalFlow.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.AllowedLevelIncreaseStorageMean, input.AllowedLevelIncreaseStorage.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.AllowedLevelIncreaseStorageStandardDeviation, input.AllowedLevelIncreaseStorage.StandardDeviation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.FlowWidthAtBottomProtectionMean, input.FlowWidthAtBottomProtection.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.FlowWidthAtBottomProtectionStandardDeviation, input.FlowWidthAtBottomProtection.StandardDeviation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.CriticalOvertoppingDischargeMean, input.CriticalOvertoppingDischarge.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.CriticalOvertoppingDischargeCoefficientOfVariation, input.CriticalOvertoppingDischarge.CoefficientOfVariation);
            Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, input.FailureProbabilityStructureWithErosion);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.WidthFlowAperturesMean, input.WidthFlowApertures.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.WidthFlowAperturesStandardDeviation, input.WidthFlowApertures.StandardDeviation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.StormDurationMean, input.StormDuration.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.LevelCrestStructureMean, input.LevelCrestStructure.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.LevelCrestStructureStandardDeviation, input.LevelCrestStructure.StandardDeviation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.DeviationWaveDirection, input.DeviationWaveDirection);

            CollectionAssert.IsEmpty(input.ForeshoreGeometry);
            Assert.IsNull(input.ForeshoreProfile);
            Assert.IsNull(input.HydraulicBoundaryLocation);
            Assert.IsNull(input.Structure);
            Assert.IsFalse(calculation.HasOutput);
        }