public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned()
        {
            // Given
            var entity = new MacroStabilityInwardsSoilProfileTwoDEntity
            {
                Name = "testName",
                MacroStabilityInwardsSoilLayerTwoDEntities =
                {
                    MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity()
                }
            };
            var collector = new ReadConversionCollector();

            MacroStabilityInwardsSoilProfile2D profile = entity.Read(collector);

            // When
            MacroStabilityInwardsSoilProfile2D secondProfile = entity.Read(collector);

            // Then
            Assert.AreSame(profile, secondProfile);
        }
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new MacroStabilityInwardsSoilProfileTwoDEntity();

            // Call
            TestDelegate test = () => entity.Read(null);

            // Assert
            string parameter = Assert.Throws <ArgumentNullException>(test).ParamName;

            Assert.AreEqual("collector", parameter);
        }
        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);
        }