Пример #1
0
        public void Read_WithCollector_ReturnsNewStochasticSoilProfileWithPropertiesSet()
        {
            // Setup
            var random = new Random(21);
            var entity = new PipingStochasticSoilProfileEntity
            {
                Probability             = random.NextDouble(),
                PipingSoilProfileEntity = new PipingSoilProfileEntity
                {
                    Name       = "StochasticSoilProfile",
                    SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                    PipingSoilLayerEntities =
                    {
                        new PipingSoilLayerEntity()
                    }
                }
            };
            var collector = new ReadConversionCollector();

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

            // Assert
            Assert.IsNotNull(profile);
            Assert.AreEqual(entity.Probability, profile.Probability, 1e-6);
        }
Пример #2
0
        public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity()
        {
            // Setup
            PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(0.6, soilProfile);

            PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[]
            {
                stochasticSoilProfile
            });

            var registry = new PersistenceRegistry();
            StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0);

            var calculation = new ProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilModel   = soilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                }
            };

            // Call
            ProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First();

            Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity);
            Assert.IsTrue(registry.Contains(soilModel));
        }
        public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var stochasticSoilModelEntity = new StochasticSoilModelEntity();

            var stochasticSoilProfile       = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity
            {
                StochasticSoilModelEntity = stochasticSoilModelEntity
            };

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile);
            collector.Read(stochasticSoilModelEntity, stochasticSoilModel);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile);
            Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel);
        }
Пример #4
0
        public void Read_DifferentStochasticSoilProfileEntitiesWithSameSoilProfileEntity_ReturnsStochasticSoilProfilesWithSamePipingSoilProfile()
        {
            // Setup
            var    random            = new Random(21);
            double probability       = random.NextDouble();
            var    soilProfileEntity = new PipingSoilProfileEntity
            {
                Name       = "StochasticSoilProfile",
                SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                PipingSoilLayerEntities =
                {
                    new PipingSoilLayerEntity()
                }
            };
            var firstEntity = new PipingStochasticSoilProfileEntity
            {
                Probability             = probability,
                PipingSoilProfileEntity = soilProfileEntity
            };
            var secondEntity = new PipingStochasticSoilProfileEntity
            {
                Probability             = 1 - probability,
                PipingSoilProfileEntity = soilProfileEntity
            };
            var collector = new ReadConversionCollector();

            PipingStochasticSoilProfile firstProfile = firstEntity.Read(collector);

            // Call
            PipingStochasticSoilProfile secondProfile = secondEntity.Read(collector);

            // Assert
            Assert.AreNotSame(firstProfile, secondProfile);
            Assert.AreSame(firstProfile.SoilProfile, secondProfile.SoilProfile);
        }
Пример #5
0
        public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned()
        {
            // Given
            var random = new Random(9);
            var entity = new PipingStochasticSoilProfileEntity
            {
                PipingSoilProfileEntity = new PipingSoilProfileEntity
                {
                    Name       = "StochasticSoilProfile",
                    SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                    PipingSoilLayerEntities =
                    {
                        new PipingSoilLayerEntity()
                    }
                }
            };

            var collector = new ReadConversionCollector();

            PipingStochasticSoilProfile profile1 = entity.Read(collector);

            // When
            PipingStochasticSoilProfile profile2 = entity.Read(collector);

            // Then
            Assert.AreSame(profile1, profile2);
        }
        /// <summary>
        /// Reads the <see cref="PipingStochasticSoilProfileEntity"/> and use the information to
        /// construct a <see cref="PipingStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="entity">The <see cref="PipingStochasticSoilProfileEntity"/> to create
        /// <see cref="PipingStochasticSoilProfile"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="PipingStochasticSoilProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        internal static PipingStochasticSoilProfile Read(this PipingStochasticSoilProfileEntity 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));
            }

            PipingSoilProfile soilProfile = entity.ReadSoilProfile(collector);
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(entity.Probability, soilProfile);

            collector.Read(entity, stochasticSoilProfile);

            return(stochasticSoilProfile);
        }
Пример #7
0
        public void Read_CollectorNull_ThrowsArgumentNullException()
        {
            // Setup
            var entity = new PipingStochasticSoilProfileEntity();

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

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

            Assert.AreEqual("collector", parameter);
        }
        public void Read_EntityWithStochasticSoilProfileEntityNotYetInCollector_CalculationWithCreatedStochasticSoilProfileAndRegisteredNewEntities()
        {
            // Setup
            var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity
            {
                PipingSoilProfileEntity = new PipingSoilProfileEntity
                {
                    Name = "SoilProfile",
                    PipingSoilLayerEntities =
                    {
                        new PipingSoilLayerEntity()
                    }
                }
            };

            var random   = new Random(21);
            var geometry = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble())
            };
            var stochasticSoilModelEntity = new StochasticSoilModelEntity
            {
                Name = "StochasticSoilModel",
                StochasticSoilModelSegmentPointXml  = new Point2DCollectionXmlSerializer().ToXml(geometry),
                PipingStochasticSoilProfileEntities =
                {
                    stochasticSoilProfileEntity
                }
            };

            stochasticSoilProfileEntity.StochasticSoilModelEntity = stochasticSoilModelEntity;

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.Contains(stochasticSoilProfileEntity));
            Assert.IsTrue(collector.ContainsPipingStochasticSoilModel(stochasticSoilModelEntity));
        }
        public void Create_SamePipingStochasticSoilProfileMultipleTimes_ReturnSameEntity()
        {
            // Setup
            PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(0.4, soilProfile);
            var registry = new PersistenceRegistry();

            // Call
            PipingStochasticSoilProfileEntity entity1 = stochasticSoilProfile.Create(registry, 0);
            PipingStochasticSoilProfileEntity entity2 = stochasticSoilProfile.Create(registry, 0);

            // Assert
            Assert.AreSame(entity1, entity2);
        }
        public void Create_DifferentStochasticSoilProfilesWithSamePipingSoilProfile_ReturnsPipingStochasticSoilProfileEntityWithSameSoilProfileEntitySet()
        {
            // Setup
            PipingSoilProfile testPipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var firstStochasticSoilProfile          = new PipingStochasticSoilProfile(new Random(21).NextDouble(), testPipingSoilProfile);
            var secondStochasticSoilProfile         = new PipingStochasticSoilProfile(new Random(21).NextDouble(), testPipingSoilProfile);
            var registry = new PersistenceRegistry();

            // Call
            PipingStochasticSoilProfileEntity firstEntity  = firstStochasticSoilProfile.Create(registry, 0);
            PipingStochasticSoilProfileEntity secondEntity = secondStochasticSoilProfile.Create(registry, 0);

            // Assert
            Assert.AreSame(firstEntity.PipingSoilProfileEntity, secondEntity.PipingSoilProfileEntity);
        }
        public void Create_WithCollector_ReturnsPipingStochasticSoilProfileEntityWithPropertiesSet()
        {
            // Setup
            var    random                = new Random(21);
            double probability           = random.NextDouble();
            int    order                 = random.Next();
            var    stochasticSoilProfile = new PipingStochasticSoilProfile(probability, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var    registry              = new PersistenceRegistry();

            // Call
            PipingStochasticSoilProfileEntity entity = stochasticSoilProfile.Create(registry, order);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(probability, entity.Probability);
            Assert.IsNotNull(entity.PipingSoilProfileEntity);
            Assert.AreEqual(order, entity.Order);
        }
Пример #12
0
        /// <summary>
        /// Creates a <see cref="PipingStochasticSoilProfileEntity"/> based on the information of the
        /// <see cref="PipingStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="profile">The profile to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <param name="order">Index at which this instance resides inside its parent container.</param>
        /// <returns>A new <see cref="PipingStochasticSoilProfileEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static PipingStochasticSoilProfileEntity Create(this PipingStochasticSoilProfile profile,
                                                                 PersistenceRegistry registry,
                                                                 int order)
        {
            var entity = new PipingStochasticSoilProfileEntity
            {
                Probability             = profile.Probability,
                PipingSoilProfileEntity = profile.SoilProfile.Create(registry),
                Order = order
            };

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

            registry.Register(entity, profile);
            return(entity);
        }
        public void Create_WithStochasticSoilProfiles_ReturnsStochasticSoilModelEntityWithPropertiesAndPipingStochasticSoilProfileEntitiesSet()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("testName", new[]
            {
                new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile())
            });
            var registry = new PersistenceRegistry();

            // Call
            StochasticSoilModelEntity entity = stochasticSoilModel.Create(registry, 0);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Count(), entity.PipingStochasticSoilProfileEntities.Count);

            PipingStochasticSoilProfileEntity stochastEntity = entity.PipingStochasticSoilProfileEntities.Single();

            Assert.AreEqual(stochasticSoilModel.StochasticSoilProfiles.Single().Probability, stochastEntity.Probability);
            Assert.IsNotNull(stochastEntity.PipingSoilProfileEntity);

            CollectionAssert.IsEmpty(entity.MacroStabilityInwardsStochasticSoilProfileEntities);
        }
Пример #14
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="PipingStochasticSoilProfileEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="PipingStochasticSoilProfile"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(PipingStochasticSoilProfileEntity entity, PipingStochasticSoilProfile model)
 {
     Register(pipingStochasticSoilProfiles, entity, model);
 }
 private static PipingSoilProfile ReadSoilProfile(this PipingStochasticSoilProfileEntity entity,
                                                  ReadConversionCollector collector)
 {
     return(entity.PipingSoilProfileEntity.Read(collector));
 }