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_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); }