/// <summary>
        /// Creates a <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> based on the information
        /// of the <see cref="MacroStabilityInwardsSoilProfile2D"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> or one from the
        /// <paramref name="registry"/> if it was created for the <see cref="soilProfile"/> earlier.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        public static MacroStabilityInwardsSoilProfileTwoDEntity Create(this MacroStabilityInwardsSoilProfile2D soilProfile,
                                                                        PersistenceRegistry registry)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            if (registry.Contains(soilProfile))
            {
                return(registry.Get(soilProfile));
            }

            var entity = new MacroStabilityInwardsSoilProfileTwoDEntity
            {
                Name = soilProfile.Name.DeepClone()
            };

            AddEntitiesForSoilLayers(soilProfile.Layers, entity);
            AddEntitiesForPreconsolidationStresses(soilProfile.PreconsolidationStresses, entity);

            registry.Register(entity, soilProfile);
            return(entity);
        }
        public void Read_DifferentStochasticSoilProfileEntitiesWithSame2dProfile_ReturnsStochasticSoilProfilesWithSameSoilProfile()
        {
            // Setup
            var    random                = new Random(21);
            double probability           = random.NextDouble();
            var    soilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity
            {
                Name = "SoilProfile",
                MacroStabilityInwardsSoilLayerTwoDEntities =
                {
                    MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity()
                }
            };

            var firstEntity = new MacroStabilityInwardsStochasticSoilProfileEntity
            {
                Probability = probability,
                MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity
            };
            var secondEntity = new MacroStabilityInwardsStochasticSoilProfileEntity
            {
                Probability = 1 - probability,
                MacroStabilityInwardsSoilProfileTwoDEntity = soilProfileTwoDEntity
            };
            var collector = new ReadConversionCollector();

            MacroStabilityInwardsStochasticSoilProfile firstStochasticSoilProfile = firstEntity.Read(collector);

            // Call
            MacroStabilityInwardsStochasticSoilProfile secondStochasticSoilProfile = secondEntity.Read(collector);

            // Assert
            Assert.AreNotSame(firstStochasticSoilProfile, secondStochasticSoilProfile);
            Assert.AreSame(firstStochasticSoilProfile.SoilProfile, secondStochasticSoilProfile.SoilProfile);
        }
Beispiel #3
0
        /// <summary>
        /// Reads the <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> and use the information
        /// to construct a <see cref="MacroStabilityInwardsSoilProfile2D"/>.
        /// </summary>
        /// <param name="entity">The <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> to
        /// create <see cref="MacroStabilityInwardsSoilProfile2D"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilProfile2D"/> or one from the <paramref name="collector"/>
        /// if the <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> has been read before.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        public static MacroStabilityInwardsSoilProfile2D Read(this MacroStabilityInwardsSoilProfileTwoDEntity entity,
                                                              ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

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

            IEnumerable <MacroStabilityInwardsSoilLayer2D> layers = entity.MacroStabilityInwardsSoilLayerTwoDEntities
                                                                    .OrderBy(sl => sl.Order)
                                                                    .Select(sl => sl.Read())
                                                                    .ToArray();
            IEnumerable <MacroStabilityInwardsPreconsolidationStress> preconsolidationStresses = entity.MacroStabilityInwardsPreconsolidationStressEntities
                                                                                                 .OrderBy(stressEntity => stressEntity.Order)
                                                                                                 .Select(stressEntity => stressEntity.Read())
                                                                                                 .ToArray();
            var soilProfile = new MacroStabilityInwardsSoilProfile2D(entity.Name,
                                                                     layers,
                                                                     preconsolidationStresses);

            collector.Read(entity, soilProfile);
            return(soilProfile);
        }
        private static void AddEntitiesForPreconsolidationStresses(IEnumerable <MacroStabilityInwardsPreconsolidationStress> preconsolidationStresses,
                                                                   MacroStabilityInwardsSoilProfileTwoDEntity entity)
        {
            var index = 0;

            foreach (MacroStabilityInwardsPreconsolidationStress preconsolidationStress in preconsolidationStresses)
            {
                entity.MacroStabilityInwardsPreconsolidationStressEntities.Add(preconsolidationStress.Create(index++));
            }
        }
        private static void AddEntitiesForSoilLayers(IEnumerable <MacroStabilityInwardsSoilLayer2D> layers,
                                                     MacroStabilityInwardsSoilProfileTwoDEntity entity)
        {
            var index = 0;

            foreach (MacroStabilityInwardsSoilLayer2D layer in layers)
            {
                entity.MacroStabilityInwardsSoilLayerTwoDEntities.Add(layer.Create(index++));
            }
        }
Beispiel #6
0
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            MacroStabilityInwardsSoilProfile2D soilProfile = CreateMacroStabilityInwardsSoilProfile2D("some name");
            var registry = new PersistenceRegistry();

            // Call
            MacroStabilityInwardsSoilProfileTwoDEntity entity = soilProfile.Create(registry);

            // Assert
            TestHelper.AssertAreEqualButNotSame(soilProfile.Name, entity.Name);
        }
        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);
        }
Beispiel #8
0
        public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned()
        {
            // Given
            MacroStabilityInwardsSoilProfile2D soilProfile = CreateMacroStabilityInwardsSoilProfile2D();
            var registry = new PersistenceRegistry();

            MacroStabilityInwardsSoilProfileTwoDEntity firstEntity = soilProfile.Create(registry);

            // When
            MacroStabilityInwardsSoilProfileTwoDEntity secondEntity = soilProfile.Create(registry);

            // Then
            Assert.AreSame(firstEntity, secondEntity);
        }
        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);
        }
Beispiel #10
0
        public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
        {
            // Setup
            var soilProfile = new MacroStabilityInwardsSoilProfile2D("some name", new[]
            {
                MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D(),
                MacroStabilityInwardsSoilLayer2DTestFactory.CreateMacroStabilityInwardsSoilLayer2D()
            }, new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress()
            });
            var registry = new PersistenceRegistry();

            // Call
            MacroStabilityInwardsSoilProfileTwoDEntity entity = soilProfile.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(soilProfile.Layers.Count(), entity.MacroStabilityInwardsSoilLayerTwoDEntities.Count);
            Assert.AreEqual(soilProfile.PreconsolidationStresses.Count(), entity.MacroStabilityInwardsPreconsolidationStressEntities.Count);

            AssertPreconsolidationStress(soilProfile.PreconsolidationStresses.First(),
                                         entity.MacroStabilityInwardsPreconsolidationStressEntities.First());
        }
Beispiel #11
0
 /// <summary>
 /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/>
 /// that was constructed with the information.
 /// </summary>
 /// <param name="entity">The <see cref="MacroStabilityInwardsSoilProfileTwoDEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="MacroStabilityInwardsSoilProfile2D"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(MacroStabilityInwardsSoilProfileTwoDEntity entity, MacroStabilityInwardsSoilProfile2D model)
 {
     Register(macroStabilityInwardsSoil2DProfiles, entity, model);
 }
        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);
        }