Exemple #1
0
        /// <summary>
        /// Read the <see cref="ForeshoreProfileEntity"/> and use the information to construct a <see cref="ForeshoreProfile"/>.
        /// </summary>
        /// <param name="entity">The <see cref="ForeshoreProfileEntity"/> to create <see cref="ForeshoreProfile"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="ForeshoreProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="ForeshoreProfileEntity.GeometryXml"/>
        /// of <paramref name="entity"/> is <c>null</c> or empty.</exception>
        internal static ForeshoreProfile Read(this ForeshoreProfileEntity entity, ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            if (collector.Contains(entity))
            {
                return(collector.Get(entity));
            }

            Point2D[] points = new Point2DCollectionXmlSerializer().FromXml(entity.GeometryXml);

            var foreshoreProfile = new ForeshoreProfile(new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()),
                                                        points,
                                                        CreateBreakWater(entity.BreakWaterType, entity.BreakWaterHeight),
                                                        new ForeshoreProfile.ConstructionProperties
            {
                Id          = entity.Id.DeepClone(),
                Name        = entity.Name.DeepClone(),
                Orientation = entity.Orientation.ToNullAsNaN(),
                X0          = entity.X0.ToNullAsNaN()
            });

            collector.Read(entity, foreshoreProfile);

            return(foreshoreProfile);
        }
Exemple #2
0
        public void Read_WithCollector_NewPointAndEntityRegistered()
        {
            // Setup
            const string name   = "testName";
            var          points = new[]
            {
                new Point2D(0, 0)
            };
            string pointXml = new Point2DCollectionXmlSerializer().ToXml(points);
            var    entity   = new FailureMechanismSectionEntity
            {
                Name = name,
                FailureMechanismSectionPointXml = pointXml
            };

            var collector = new ReadConversionCollector();

            // Call
            FailureMechanismSection section = entity.Read(collector);

            // Assert
            Assert.IsNotNull(section);
            Assert.AreEqual(name, section.Name);
            Assert.AreEqual(section, collector.Get(entity));

            Assert.IsTrue(collector.Contains(entity));
        }
        public void ReadAsMacroStabilityInwardsStochasticSoilModel_SameStochasticSoilModelEntityMultipleTimes_ReturnSameStochasticSoilModel()
        {
            // Setup
            var    random           = new Random(21);
            string segmentPointsXml = new Point2DCollectionXmlSerializer().ToXml(new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble())
            });

            var entity = new StochasticSoilModelEntity
            {
                Name = "StochasticSoilModel",
                StochasticSoilModelSegmentPointXml = segmentPointsXml,
                MacroStabilityInwardsStochasticSoilProfileEntities =
                {
                    MacroStabilityInwardsStochasticSoilProfileEntityTestFactory.CreateStochasticSoilProfileEntity()
                }
            };

            var collector = new ReadConversionCollector();

            // Call
            MacroStabilityInwardsStochasticSoilModel soilModel1 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector);
            MacroStabilityInwardsStochasticSoilModel soilModel2 = entity.ReadAsMacroStabilityInwardsStochasticSoilModel(collector);

            // Assert
            Assert.AreSame(soilModel1, soilModel2);
        }
Exemple #4
0
        public void GivenArrayWithPoint2D_WhenConvertingRoundTrip_ThenEqualArrayOfPoints2D()
        {
            // Given
            var original = new[]
            {
                new Point2D(-7.7, -6.6),
                new Point2D(-5.5, -4.4),
                new Point2D(-3.3, -2.2),
                new Point2D(-1.1, 0.0),
                new Point2D(1.1, 2.2),
                new Point2D(3.3, 4.4),
                new Point2D(5.5, 6.6),
                new Point2D(7.7, 8.8),
                new Point2D(9.9, 10.10)
            };
            var serializer = new Point2DCollectionXmlSerializer();

            // When
            string xml = serializer.ToXml(original);

            Point2D[] roundtripResult = serializer.FromXml(xml);

            // Then
            CollectionAssert.AreEqual(original, roundtripResult);
        }
        public void Read_EmptyGeometryBreakWaterTypeAndNullableValuesAreNull_ForeshoreProfileWithoutBreakWaterNaNValues()
        {
            // Setup
            const string name     = "testName";
            const string id       = "testId";
            string       pointXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty <Point2D>());
            var          entity   = new ForeshoreProfileEntity
            {
                Id          = id,
                Name        = name,
                GeometryXml = pointXml
            };

            var readConversionCollector = new ReadConversionCollector();

            // Call
            ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector);

            // Assert
            Assert.IsNotNull(foreshoreProfile);
            Assert.AreEqual(id, foreshoreProfile.Id);
            Assert.AreEqual(name, foreshoreProfile.Name);
            Assert.IsNaN(foreshoreProfile.Orientation);
            Assert.IsNaN(foreshoreProfile.X0);
            Assert.IsNull(foreshoreProfile.BreakWater);
            Assert.IsFalse(foreshoreProfile.HasBreakWater);
            CollectionAssert.IsEmpty(foreshoreProfile.Geometry);
        }
Exemple #6
0
 private static void ReadReferenceLine(this AssessmentSectionEntity entity, IAssessmentSection assessmentSection)
 {
     if (entity.ReferenceLinePointXml != null)
     {
         Point2D[] points = new Point2DCollectionXmlSerializer().FromXml(entity.ReferenceLinePointXml);
         assessmentSection.ReferenceLine.SetGeometry(points);
     }
 }
Exemple #7
0
        public void Constructor_ExpectedValues()
        {
            // Call
            var serializer = new Point2DCollectionXmlSerializer();

            // Assert
            Assert.IsInstanceOf <DataCollectionSerializer <Point2D, Point2DCollectionXmlSerializer.SerializablePoint2D> >(serializer);
            SerializerTestHelper.AssertSerializedData(typeof(Point2DCollectionXmlSerializer.SerializablePoint2D));
        }
Exemple #8
0
        /// <summary>
        /// Read the <see cref="FailureMechanismSectionEntity"/> and use the information to construct a <see cref="FailureMechanismSection"/>.
        /// </summary>
        /// <param name="entity">The <see cref="FailureMechanismSectionEntity"/> to create <see cref="FailureMechanismSection"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="FailureMechanismSection"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="FailureMechanismSectionEntity.FailureMechanismSectionPointXml"/>
        /// of <paramref name="entity"/> is <c>null</c> or empty.</exception>
        internal static FailureMechanismSection Read(this FailureMechanismSectionEntity entity, ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

            Point2D[] points           = new Point2DCollectionXmlSerializer().FromXml(entity.FailureMechanismSectionPointXml);
            var       mechanismSection = new FailureMechanismSection(entity.Name, points);

            collector.Read(entity, mechanismSection);

            return(mechanismSection);
        }
Exemple #9
0
        private static FailureMechanismSectionEntity CreateSimpleFailureMechanismSectionEntity()
        {
            var dummyPoints = new[]
            {
                new Point2D(0, 0)
            };
            string dummyPointXml = new Point2DCollectionXmlSerializer().ToXml(dummyPoints);
            var    failureMechanismSectionEntity = new FailureMechanismSectionEntity
            {
                Name = "section",
                FailureMechanismSectionPointXml = dummyPointXml
            };

            return(failureMechanismSectionEntity);
        }
Exemple #10
0
        public void Create_WithoutBreakWater_ReturnEntityWithNullBreakWaterProperties()
        {
            // Setup
            int order       = new Random(22).Next();
            var dikeProfile = new DikeProfile(new Point2D(1.1, 2.2),
                                              new[]
            {
                new RoughnessPoint(new Point2D(3.3, 4.4), 0.75),
                new RoughnessPoint(new Point2D(5.5, 6.6), 0.75)
            },
                                              new[]
            {
                new Point2D(7.7, 8.8),
                new Point2D(9.9, 10.10)
            },
                                              null,
                                              new DikeProfile.ConstructionProperties
            {
                Id          = "no_breakwater",
                Name        = "Dike profile without break water.",
                DikeHeight  = 11.11,
                Orientation = 12.12,
                X0          = 13.13
            });
            var registry = new PersistenceRegistry();

            // Call
            DikeProfileEntity entity = dikeProfile.Create(registry, order);

            // Assert
            Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X);
            Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y);
            Assert.AreEqual(dikeProfile.X0, entity.X0);
            Assert.AreEqual(order, entity.Order);
            string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry);

            Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml);
            string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry);

            Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml);
            Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation);
            Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight);
            Assert.AreEqual(dikeProfile.Id, entity.Id);
            Assert.AreEqual(dikeProfile.Name, entity.Name);

            Assert.IsNull(entity.BreakWaterHeight);
            Assert.IsNull(entity.BreakWaterType);
        }
Exemple #11
0
        public void Create_WithBreakWater_ReturnEntity(BreakWaterType type, double height)
        {
            // Setup
            int order       = new Random(42).Next();
            var dikeProfile = new DikeProfile(new Point2D(1234.4567, 5678.432),
                                              new[]
            {
                new RoughnessPoint(new Point2D(-6.6, -3.3), 0.75),
                new RoughnessPoint(new Point2D(4.4, 5.5), 0.75)
            },
                                              new[]
            {
                new Point2D(-12.12, -13.13),
                new Point2D(-6.6, -3.3)
            },
                                              new BreakWater(type, height),
                                              new DikeProfile.ConstructionProperties
            {
                Id          = "no_breakwater",
                Name        = "Dike profile without break water.",
                DikeHeight  = 98.76,
                Orientation = 76.54,
                X0          = -12.34
            });
            var registry = new PersistenceRegistry();

            // Call
            DikeProfileEntity entity = dikeProfile.Create(registry, order);

            // Assert
            Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X);
            Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y);
            Assert.AreEqual(dikeProfile.X0, entity.X0);
            Assert.AreEqual(order, entity.Order);
            string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry);

            Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml);
            string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry);

            Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml);
            Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation);
            Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight);
            Assert.AreEqual(dikeProfile.Id, entity.Id);
            Assert.AreEqual(dikeProfile.Name, entity.Name);

            Assert.AreEqual((byte)type, entity.BreakWaterType);
            Assert.AreEqual(height, entity.BreakWaterHeight);
        }
        public void Read_WithGeometryAndBreakWaterTypeAndValues_CompleteForeshoreProfile()
        {
            // Setup
            const string         name           = "testName";
            const string         id             = "testId";
            var                  random         = new Random(21);
            int                  order          = random.Next();
            double               orientation    = random.NextDouble();
            double               x0             = random.NextDouble();
            double               height         = random.NextDouble();
            const BreakWaterType breakWaterType = BreakWaterType.Wall;

            var points = new[]
            {
                new Point2D(0, 0)
            };
            string pointXml = new Point2DCollectionXmlSerializer().ToXml(points);
            var    entity   = new ForeshoreProfileEntity
            {
                Order            = order,
                Id               = id,
                Name             = name,
                Orientation      = orientation,
                X0               = x0,
                BreakWaterType   = Convert.ToByte(breakWaterType),
                BreakWaterHeight = height,
                GeometryXml      = pointXml
            };

            var readConversionCollector = new ReadConversionCollector();

            // Call
            ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector);

            // Assert
            Assert.IsNotNull(foreshoreProfile);
            Assert.AreEqual(name, foreshoreProfile.Name);
            Assert.AreEqual(order, entity.Order);
            Assert.AreEqual(id, foreshoreProfile.Id);
            Assert.AreEqual(name, entity.Name);
            Assert.AreEqual(orientation, foreshoreProfile.Orientation, foreshoreProfile.Orientation.GetAccuracy());
            Assert.AreEqual(x0, entity.X0);
            Assert.AreEqual(breakWaterType, foreshoreProfile.BreakWater.Type);
            Assert.IsTrue(foreshoreProfile.HasBreakWater);
            CollectionAssert.AreEqual(points, foreshoreProfile.Geometry);
        }
        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 Create_WithGeometryPoints_ReturnsStochasticSoilModelEntityWithPropertiesAndStochasticSoilModelSegmentPointEntitiesSet()
        {
            // Setup
            var random = new Random(31);
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            });

            var registry = new PersistenceRegistry();

            // Call
            StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0);

            // Assert
            Assert.IsNotNull(entity);
            string expectedXml = new Point2DCollectionXmlSerializer().ToXml(stochasticSoilModel.Geometry);

            Assert.AreEqual(expectedXml, entity.StochasticSoilModelSegmentPointXml);
        }
        public void Create_WithGeometry_ReturnsForeshoreProfileWithGeometryStringSet()
        {
            // Setup
            int order          = new Random(21).Next();
            var geometryPoints = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 0)
            };
            var foreshoreProfile = new TestForeshoreProfile(geometryPoints);
            var registry         = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, order);

            // Assert
            Assert.IsNotNull(entity);
            string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints);

            Assert.AreEqual(expectedXml, entity.GeometryXml);
        }
        public void Create_WithCollectorAndGeometry_ReturnsFailureMechanismSectionWithGeometryStringSet()
        {
            // Setup
            const string testName       = "testName";
            var          geometryPoints = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 0)
            };
            var failureMechanismSection = new FailureMechanismSection(testName, geometryPoints);
            var registry = new PersistenceRegistry();

            // Call
            FailureMechanismSectionEntity entity = failureMechanismSection.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(testName, entity.Name);
            string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints);

            Assert.AreEqual(expectedXml, entity.FailureMechanismSectionPointXml);
        }
Exemple #17
0
        public void Create_WithReferenceLine_AddsReferenceLinePointEntities()
        {
            // Setup
            var points = new[]
            {
                new Point2D(1, 0),
                new Point2D(2, 3),
                new Point2D(5, 3)
            };

            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);

            assessmentSection.ReferenceLine.SetGeometry(points);

            var registry = new PersistenceRegistry();

            // Call
            AssessmentSectionEntity entity = assessmentSection.Create(registry);

            // Assert
            string expectedXml = new Point2DCollectionXmlSerializer().ToXml(points);

            Assert.AreEqual(expectedXml, entity.ReferenceLinePointXml);
        }
Exemple #18
0
        private static void AssertOuterRing(Ring outerRing, MacroStabilityInwardsSoilLayerTwoDEntity entity)
        {
            string expectedOuterRingXml = new Point2DCollectionXmlSerializer().ToXml(outerRing.Points);

            Assert.AreEqual(expectedOuterRingXml, entity.OuterRingXml);
        }
        public void Read_WithCollector_ReturnsSoilProfileWithPropertiesSet()
        {
            // Setup
            Ring outerRingA = RingTestFactory.CreateRandomRing(32);
            Ring outerRingB = RingTestFactory.CreateRandomRing(33);

            var random = new Random(31);
            var preconsolidationStressEntity = new MacroStabilityInwardsPreconsolidationStressEntity
            {
                CoordinateX = random.NextDouble(),
                CoordinateZ = random.NextDouble(),
                PreconsolidationStressMean = random.NextDouble(),
                PreconsolidationStressCoefficientOfVariation = random.NextDouble(),
                Order = 1
            };

            var point2DXmlSerializer = new Point2DCollectionXmlSerializer();
            var entity = new MacroStabilityInwardsSoilProfileTwoDEntity
            {
                Name = nameof(MacroStabilityInwardsSoilProfileTwoDEntity),
                MacroStabilityInwardsSoilLayerTwoDEntities =
                {
                    new MacroStabilityInwardsSoilLayerTwoDEntity
                    {
                        MaterialName = "A",
                        OuterRingXml = point2DXmlSerializer.ToXml(outerRingA.Points),
                        Order        = 1
                    },
                    new MacroStabilityInwardsSoilLayerTwoDEntity
                    {
                        MaterialName = "B",
                        OuterRingXml = point2DXmlSerializer.ToXml(outerRingB.Points),
                        Order        = 0
                    }
                },
                MacroStabilityInwardsPreconsolidationStressEntities =
                {
                    preconsolidationStressEntity,
                    new MacroStabilityInwardsPreconsolidationStressEntity
                    {
                        Order = 0
                    }
                }
            };
            var collector = new ReadConversionCollector();

            // Call
            MacroStabilityInwardsSoilProfile2D profile = entity.Read(collector);

            // Assert
            Assert.IsNotNull(profile);
            Assert.AreEqual(entity.Name, profile.Name);
            CollectionAssert.AreEqual(new[]
            {
                "B",
                "A"
            }, profile.Layers.Select(l => l.Data.MaterialName));

            CollectionAssert.AreEqual(new[]
            {
                outerRingB,
                outerRingA
            }, profile.Layers.Select(l => l.OuterRing));

            profile.Layers.Select(l => l.NestedLayers).ForEachElementDo(CollectionAssert.IsEmpty);

            CollectionAssert.AreEqual(new[]
            {
                new MacroStabilityInwardsPreconsolidationStress(new Point2D(0, 0),
                                                                new VariationCoefficientLogNormalDistribution
                {
                    Mean = RoundedDouble.NaN,
                    CoefficientOfVariation = RoundedDouble.NaN
                }),
                new MacroStabilityInwardsPreconsolidationStress(new Point2D(preconsolidationStressEntity.CoordinateX,
                                                                            preconsolidationStressEntity.CoordinateZ),
                                                                new VariationCoefficientLogNormalDistribution
                {
                    Mean = (RoundedDouble)preconsolidationStressEntity.PreconsolidationStressMean.ToNullAsNaN(),
                    CoefficientOfVariation = (RoundedDouble)preconsolidationStressEntity.PreconsolidationStressCoefficientOfVariation.ToNullAsNaN()
                })
            }, profile.PreconsolidationStresses);
        }