/// <summary>
        /// Reads the <see cref="PipingSoilLayerEntity"/> and use the information to construct a <see cref="PipingSoilLayer"/>.
        /// </summary>
        /// <param name="entity">The <see cref="PipingSoilLayerEntity"/> to create <see cref="PipingSoilLayer"/> for.</param>
        /// <returns>A new <see cref="PipingSoilLayer"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/> is <c>null</c>.</exception>
        public static PipingSoilLayer Read(this PipingSoilLayerEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(new PipingSoilLayer(entity.Top.ToNullAsNaN())
            {
                IsAquifer = Convert.ToBoolean(entity.IsAquifer),
                Color = entity.Color.ToColor(),
                MaterialName = entity.MaterialName ?? string.Empty,
                BelowPhreaticLevel = new LogNormalDistribution
                {
                    Mean = (RoundedDouble)entity.BelowPhreaticLevelMean.ToNullAsNaN(),
                    StandardDeviation = (RoundedDouble)entity.BelowPhreaticLevelDeviation.ToNullAsNaN(),
                    Shift = (RoundedDouble)entity.BelowPhreaticLevelShift.ToNullAsNaN()
                },
                DiameterD70 = new VariationCoefficientLogNormalDistribution
                {
                    Mean = (RoundedDouble)entity.DiameterD70Mean.ToNullAsNaN(),
                    CoefficientOfVariation = (RoundedDouble)entity.DiameterD70CoefficientOfVariation.ToNullAsNaN()
                },
                Permeability = new VariationCoefficientLogNormalDistribution
                {
                    Mean = (RoundedDouble)entity.PermeabilityMean.ToNullAsNaN(),
                    CoefficientOfVariation = (RoundedDouble)entity.PermeabilityCoefficientOfVariation.ToNullAsNaN()
                }
            });
        }
Esempio n. 2
0
        public void Read_WithValues_ReturnsPipingSoilLayerWithDoubleParameterValues()
        {
            // Setup
            var          random       = new Random(21);
            double       top          = random.NextDouble();
            Color        color        = Color.FromKnownColor(random.NextEnumValue <KnownColor>());
            const string materialName = "sand";

            bool   isAquifer = random.NextBoolean();
            double belowPhreaticLevelMean             = random.NextDouble(1, double.MaxValue);
            double belowPhreaticLevelDeviation        = random.NextDouble();
            double belowPhreaticLevelShift            = random.NextDouble();
            double diameterD70Mean                    = random.NextDouble(1, double.MaxValue);
            double diameterD70CoefficientOfVariation  = random.NextDouble();
            double permeabilityMean                   = random.NextDouble(1, double.MaxValue);
            double permeabilityCoefficientOfVariation = random.NextDouble();

            var entity = new PipingSoilLayerEntity
            {
                Top                                = top,
                IsAquifer                          = Convert.ToByte(isAquifer),
                Color                              = color.ToInt64(),
                MaterialName                       = materialName,
                BelowPhreaticLevelMean             = belowPhreaticLevelMean,
                BelowPhreaticLevelDeviation        = belowPhreaticLevelDeviation,
                BelowPhreaticLevelShift            = belowPhreaticLevelShift,
                DiameterD70Mean                    = diameterD70Mean,
                DiameterD70CoefficientOfVariation  = diameterD70CoefficientOfVariation,
                PermeabilityMean                   = permeabilityMean,
                PermeabilityCoefficientOfVariation = permeabilityCoefficientOfVariation
            };

            // Call
            PipingSoilLayer layer = entity.Read();

            // Assert
            Assert.IsNotNull(layer);
            Assert.AreEqual(top, layer.Top, 1e-6);
            Assert.AreEqual(isAquifer, layer.IsAquifer);
            Assert.IsNotNull(color);
            Assert.AreEqual(color.ToArgb(), layer.Color.ToArgb());
            Assert.AreEqual(materialName, layer.MaterialName);

            Assert.AreEqual(belowPhreaticLevelMean, layer.BelowPhreaticLevel.Mean,
                            layer.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelDeviation, layer.BelowPhreaticLevel.StandardDeviation,
                            layer.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelShift, layer.BelowPhreaticLevel.Shift,
                            layer.BelowPhreaticLevel.GetAccuracy());

            Assert.AreEqual(diameterD70Mean, layer.DiameterD70.Mean,
                            layer.DiameterD70.GetAccuracy());
            Assert.AreEqual(diameterD70CoefficientOfVariation, layer.DiameterD70.CoefficientOfVariation,
                            layer.DiameterD70.GetAccuracy());

            Assert.AreEqual(permeabilityMean, layer.Permeability.Mean,
                            layer.Permeability.GetAccuracy());
            Assert.AreEqual(permeabilityCoefficientOfVariation, layer.Permeability.CoefficientOfVariation,
                            layer.Permeability.GetAccuracy());
        }
        public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
        {
            // Setup
            var random    = new Random(21);
            int order     = random.Next();
            var soilLayer = new PipingSoilLayer(random.NextDouble())
            {
                IsAquifer          = random.NextBoolean(),
                Color              = Color.FromKnownColor(random.NextEnumValue <KnownColor>()),
                MaterialName       = "MaterialName",
                BelowPhreaticLevel = new LogNormalDistribution
                {
                    Mean = random.NextRoundedDouble(1, double.MaxValue),
                    StandardDeviation = random.NextRoundedDouble(),
                    Shift             = random.NextRoundedDouble()
                },
                DiameterD70 = new VariationCoefficientLogNormalDistribution
                {
                    Mean = random.NextRoundedDouble(1, double.MaxValue),
                    CoefficientOfVariation = random.NextRoundedDouble()
                },
                Permeability = new VariationCoefficientLogNormalDistribution
                {
                    Mean = random.NextRoundedDouble(1, double.MaxValue),
                    CoefficientOfVariation = random.NextRoundedDouble()
                }
            };

            // Call
            PipingSoilLayerEntity entity = soilLayer.Create(order);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(soilLayer.Top, entity.Top);
            Assert.AreEqual(Convert.ToByte(soilLayer.IsAquifer), entity.IsAquifer);
            Assert.AreEqual(soilLayer.Color.ToInt64(), Convert.ToInt64(entity.Color));

            Assert.AreEqual(soilLayer.BelowPhreaticLevel.Mean, entity.BelowPhreaticLevelMean,
                            soilLayer.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(soilLayer.BelowPhreaticLevel.StandardDeviation, entity.BelowPhreaticLevelDeviation,
                            soilLayer.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(soilLayer.BelowPhreaticLevel.Shift, entity.BelowPhreaticLevelShift,
                            soilLayer.BelowPhreaticLevel.GetAccuracy());

            Assert.AreEqual(soilLayer.DiameterD70.Mean, entity.DiameterD70Mean,
                            soilLayer.DiameterD70.GetAccuracy());
            Assert.AreEqual(soilLayer.DiameterD70.CoefficientOfVariation, entity.DiameterD70CoefficientOfVariation,
                            soilLayer.DiameterD70.GetAccuracy());

            Assert.AreEqual(soilLayer.Permeability.Mean, entity.PermeabilityMean,
                            soilLayer.Permeability.GetAccuracy());
            Assert.AreEqual(soilLayer.Permeability.CoefficientOfVariation, entity.PermeabilityCoefficientOfVariation,
                            soilLayer.Permeability.GetAccuracy());
            Assert.AreEqual(order, entity.Order);
        }
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string materialName = "MaterialName";
            var          soilLayer    = new PipingSoilLayer(0)
            {
                MaterialName = materialName
            };

            // Call
            PipingSoilLayerEntity entity = soilLayer.Create(0);

            // Assert
            TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName);
        }
        public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull()
        {
            // Setup
            var soilLayer = new PipingSoilLayer(double.NaN)
            {
                BelowPhreaticLevel = new LogNormalDistribution
                {
                    Mean = RoundedDouble.NaN,
                    StandardDeviation = RoundedDouble.NaN,
                    Shift             = RoundedDouble.NaN
                },
                DiameterD70 = new VariationCoefficientLogNormalDistribution
                {
                    Mean = RoundedDouble.NaN,
                    CoefficientOfVariation = RoundedDouble.NaN
                },
                Permeability = new VariationCoefficientLogNormalDistribution
                {
                    Mean = RoundedDouble.NaN,
                    CoefficientOfVariation = RoundedDouble.NaN
                }
            };

            // Call
            PipingSoilLayerEntity entity = soilLayer.Create(0);

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNull(entity.Top);
            Assert.IsNull(entity.BelowPhreaticLevelMean);
            Assert.IsNull(entity.BelowPhreaticLevelDeviation);
            Assert.IsNull(entity.BelowPhreaticLevelShift);
            Assert.IsNull(entity.DiameterD70Mean);
            Assert.IsNull(entity.DiameterD70CoefficientOfVariation);
            Assert.IsNull(entity.PermeabilityMean);
            Assert.IsNull(entity.PermeabilityCoefficientOfVariation);
        }
Esempio n. 6
0
        public void Read_WithNullValues_ReturnsPipingSoilLayerWithNaNValues()
        {
            // Setup
            var entity = new PipingSoilLayerEntity
            {
                MaterialName = nameof(PipingSoilLayerEntity)
            };

            // Call
            PipingSoilLayer layer = entity.Read();

            // Assert
            Assert.IsNotNull(layer);
            Assert.AreEqual(entity.MaterialName, layer.MaterialName);

            Assert.IsNaN(layer.Top);
            Assert.IsNaN(layer.BelowPhreaticLevel.Mean);
            Assert.IsNaN(layer.BelowPhreaticLevel.StandardDeviation);
            Assert.IsNaN(layer.BelowPhreaticLevel.Shift);
            Assert.IsNaN(layer.DiameterD70.Mean);
            Assert.IsNaN(layer.DiameterD70.CoefficientOfVariation);
            Assert.IsNaN(layer.Permeability.Mean);
            Assert.IsNaN(layer.Permeability.CoefficientOfVariation);
        }