public void Read_WithNullValues_ReturnsSoilProfileWithNaNValues()
        {
            // Setup
            var entity = new MacroStabilityInwardsSoilProfileOneDEntity
            {
                Name   = nameof(MacroStabilityInwardsSoilProfileOneDEntity),
                Bottom = null,
                MacroStabilityInwardsSoilLayerOneDEntities =
                {
                    new MacroStabilityInwardsSoilLayerOneDEntity
                    {
                        MaterialName = nameof(MacroStabilityInwardsSoilLayerOneDEntity)
                    }
                }
            };
            var collector = new ReadConversionCollector();

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

            // Assert
            Assert.IsNotNull(profile);
            Assert.AreEqual(entity.Name, profile.Name);
            Assert.IsNaN(profile.Bottom);
            Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerOneDEntities.Count, profile.Layers.Count());

            MacroStabilityInwardsSoilLayer1D layer = profile.Layers.ElementAt(0);

            Assert.AreEqual(entity.MacroStabilityInwardsSoilLayerOneDEntities.First().MaterialName, layer.Data.MaterialName);
        }
        public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned()
        {
            // Given
            const string testName = "testName";
            var          random   = new Random(31);
            double       bottom   = random.NextDouble();
            var          entity   = new MacroStabilityInwardsSoilProfileOneDEntity
            {
                Name   = testName,
                Bottom = bottom,
                MacroStabilityInwardsSoilLayerOneDEntities =
                {
                    new MacroStabilityInwardsSoilLayerOneDEntity
                    {
                        Top = bottom + 0.5
                    }
                }
            };
            var collector = new ReadConversionCollector();

            MacroStabilityInwardsSoilProfile1D profile = entity.Read(collector);

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

            // Then
            Assert.AreSame(profile, secondProfile);
        }
Пример #3
0
        public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
        {
            // Setup
            var          random      = new Random(31);
            const string name        = "some name";
            double       bottom      = -random.NextDouble();
            var          soilProfile = new MacroStabilityInwardsSoilProfile1D(name, bottom, new[]
            {
                new MacroStabilityInwardsSoilLayer1D(random.NextDouble()),
                new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
            });
            var registry = new PersistenceRegistry();

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(soilProfile.Bottom, entity.Bottom);
            Assert.AreEqual(soilProfile.Layers.Count(), entity.MacroStabilityInwardsSoilLayerOneDEntities.Count);

            MacroStabilityInwardsSoilLayerOneDEntity firstLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(0);

            Assert.AreEqual(soilProfile.Layers.ElementAt(0).Top, firstLayerEntity.Top);

            MacroStabilityInwardsSoilLayerOneDEntity secondLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(1);

            Assert.AreEqual(soilProfile.Layers.ElementAt(1).Top, secondLayerEntity.Top);
        }
        /// <summary>
        /// Creates a <see cref="MacroStabilityInwardsSoilProfileOneDEntity"/> based on the information
        /// of the <see cref="MacroStabilityInwardsSoilProfile1D"/>.
        /// </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="MacroStabilityInwardsSoilProfileOneDEntity"/> 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 MacroStabilityInwardsSoilProfileOneDEntity Create(this MacroStabilityInwardsSoilProfile1D 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 MacroStabilityInwardsSoilProfileOneDEntity
            {
                Name   = soilProfile.Name.DeepClone(),
                Bottom = soilProfile.Bottom.ToNaNAsNull()
            };

            AddEntitiesForSoilLayers(soilProfile.Layers, entity);

            registry.Register(entity, soilProfile);
            return(entity);
        }
Пример #5
0
        /// <summary>
        /// Reads the <see cref="MacroStabilityInwardsSoilProfileOneDEntity"/> and use the information
        /// to construct a <see cref="MacroStabilityInwardsSoilProfile1D"/>.
        /// </summary>
        /// <param name="entity">The <see cref="MacroStabilityInwardsSoilProfileOneDEntity"/> to
        /// create <see cref="MacroStabilityInwardsSoilProfile1D"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilProfile1D"/> or one from the <paramref name="collector"/>
        /// if the <see cref="MacroStabilityInwardsSoilProfileOneDEntity"/> has been read before.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        public static MacroStabilityInwardsSoilProfile1D Read(this MacroStabilityInwardsSoilProfileOneDEntity 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 <MacroStabilityInwardsSoilLayer1D> layers = entity.MacroStabilityInwardsSoilLayerOneDEntities.OrderBy(sl => sl.Order)
                                                                    .Select(sl => sl.Read())
                                                                    .ToArray();
            var macroStabilityInwardsSoilProfile = new MacroStabilityInwardsSoilProfile1D(entity.Name,
                                                                                          entity.Bottom.ToNullAsNaN(),
                                                                                          layers);

            collector.Read(entity, macroStabilityInwardsSoilProfile);
            return(macroStabilityInwardsSoilProfile);
        }
        public void Read_DifferentStochasticSoilProfileEntitiesWithSame1dProfile_ReturnsStochasticSoilProfilesWithSameSoilProfile()
        {
            // Setup
            var    random                = new Random(21);
            double probability           = random.NextDouble();
            var    soilProfileOneDEntity = new MacroStabilityInwardsSoilProfileOneDEntity
            {
                Name = "SoilProfile",
                MacroStabilityInwardsSoilLayerOneDEntities =
                {
                    new MacroStabilityInwardsSoilLayerOneDEntity()
                }
            };

            var firstEntity = new MacroStabilityInwardsStochasticSoilProfileEntity
            {
                Probability = probability,
                MacroStabilityInwardsSoilProfileOneDEntity = soilProfileOneDEntity
            };
            var secondEntity = new MacroStabilityInwardsStochasticSoilProfileEntity
            {
                Probability = 1 - probability,
                MacroStabilityInwardsSoilProfileOneDEntity = soilProfileOneDEntity
            };
            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);
        }
        private static void AddEntitiesForSoilLayers(IEnumerable <MacroStabilityInwardsSoilLayer1D> layers,
                                                     MacroStabilityInwardsSoilProfileOneDEntity entity)
        {
            var index = 0;

            foreach (MacroStabilityInwardsSoilLayer1D layer in layers)
            {
                entity.MacroStabilityInwardsSoilLayerOneDEntities.Add(layer.Create(index++));
            }
        }
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new MacroStabilityInwardsSoilProfileOneDEntity();

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

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

            Assert.AreEqual("collector", parameter);
        }
Пример #9
0
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string name = "some name";
            MacroStabilityInwardsSoilProfile1D soilProfile =
                MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D(name);
            var registry = new PersistenceRegistry();

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

            // Assert
            TestHelper.AssertAreEqualButNotSame(name, entity.Name);
        }
Пример #10
0
        public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityReturned()
        {
            // Given
            MacroStabilityInwardsSoilProfile1D soilProfile =
                MacroStabilityInwardsSoilProfile1DTestFactory.CreateMacroStabilityInwardsSoilProfile1D();
            var registry = new PersistenceRegistry();

            MacroStabilityInwardsSoilProfileOneDEntity firstEntity = soilProfile.Create(registry);

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

            // Then
            Assert.AreSame(firstEntity, secondEntity);
        }
Пример #11
0
        public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull()
        {
            // Setup
            var random      = new Random(31);
            var soilProfile = new MacroStabilityInwardsSoilProfile1D("some name", double.NaN, new[]
            {
                new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
            });
            var registry = new PersistenceRegistry();

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNull(entity.Bottom);
        }
        public void Read_WithCollector_ReturnsNewSoilProfileWithPropertiesSet()
        {
            // Setup
            var    random = new Random(31);
            double bottom = random.NextDouble();
            var    entity = new MacroStabilityInwardsSoilProfileOneDEntity
            {
                Name   = nameof(MacroStabilityInwardsSoilProfileOneDEntity),
                Bottom = bottom,
                MacroStabilityInwardsSoilLayerOneDEntities =
                {
                    new MacroStabilityInwardsSoilLayerOneDEntity
                    {
                        Top          = bottom + 0.5,
                        MaterialName = "A",
                        Order        = 1
                    },
                    new MacroStabilityInwardsSoilLayerOneDEntity
                    {
                        Top          = bottom + 1.2,
                        MaterialName = "B",
                        Order        = 0
                    }
                }
            };
            var collector = new ReadConversionCollector();

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

            // Assert
            Assert.IsNotNull(profile);
            Assert.AreEqual(entity.Name, profile.Name);
            Assert.AreEqual(bottom, profile.Bottom);
            CollectionAssert.AreEqual(new[]
            {
                "B",
                "A"
            }, profile.Layers.Select(l => l.Data.MaterialName));
        }
Пример #13
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="MacroStabilityInwardsSoilProfileOneDEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="MacroStabilityInwardsSoilProfile1D"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(MacroStabilityInwardsSoilProfileOneDEntity entity, MacroStabilityInwardsSoilProfile1D model)
 {
     Register(macroStabilityInwardsSoil1DProfiles, entity, model);
 }