コード例 #1
0
        /// <summary>
        /// Read the <see cref="ForeshoreProfileEntity"/> and use the information to construct a <see cref="ForeshoreProfile"/>.
        /// </summary>
        /// <param name="entity">The <see cref="ForeshoreProfileEntity"/> to create <see cref="ForeshoreProfile"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="ForeshoreProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="ForeshoreProfileEntity.GeometryXml"/>
        /// of <paramref name="entity"/> is <c>null</c> or empty.</exception>
        internal static ForeshoreProfile Read(this ForeshoreProfileEntity entity, ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

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

            Point2D[] points = new Point2DCollectionXmlSerializer().FromXml(entity.GeometryXml);

            var foreshoreProfile = new ForeshoreProfile(new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()),
                                                        points,
                                                        CreateBreakWater(entity.BreakWaterType, entity.BreakWaterHeight),
                                                        new ForeshoreProfile.ConstructionProperties
            {
                Id          = entity.Id.DeepClone(),
                Name        = entity.Name.DeepClone(),
                Orientation = entity.Orientation.ToNullAsNaN(),
                X0          = entity.X0.ToNullAsNaN()
            });

            collector.Read(entity, foreshoreProfile);

            return(foreshoreProfile);
        }
コード例 #2
0
        public void Create_WithSimpleProperties_ReturnsForeshoreProfileWithSimplePropertiesSet()
        {
            // Setup
            const string name        = "testName";
            const string id          = "fpid";
            var          random      = new Random(21);
            int          order       = random.Next();
            double       orientation = random.NextDouble();
            double       x0          = random.NextDouble();

            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), Enumerable.Empty <Point2D>(), null, new ForeshoreProfile.ConstructionProperties
            {
                Id          = id,
                Name        = name,
                Orientation = orientation,
                X0          = x0
            });
            var registry = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, order);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(order, entity.Order);
            Assert.AreEqual(id, entity.Id);
            Assert.AreEqual(name, entity.Name);
            Assert.AreEqual(orientation, entity.Orientation, foreshoreProfile.Orientation.GetAccuracy());
            Assert.AreEqual(x0, entity.X0);
            Assert.IsNull(entity.BreakWaterType);
            Assert.IsNull(entity.BreakWaterHeight);
        }
コード例 #3
0
        public void Read_EmptyGeometryBreakWaterTypeAndNullableValuesAreNull_ForeshoreProfileWithoutBreakWaterNaNValues()
        {
            // Setup
            const string name     = "testName";
            const string id       = "testId";
            string       pointXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty <Point2D>());
            var          entity   = new ForeshoreProfileEntity
            {
                Id          = id,
                Name        = name,
                GeometryXml = pointXml
            };

            var readConversionCollector = new ReadConversionCollector();

            // Call
            ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector);

            // Assert
            Assert.IsNotNull(foreshoreProfile);
            Assert.AreEqual(id, foreshoreProfile.Id);
            Assert.AreEqual(name, foreshoreProfile.Name);
            Assert.IsNaN(foreshoreProfile.Orientation);
            Assert.IsNaN(foreshoreProfile.X0);
            Assert.IsNull(foreshoreProfile.BreakWater);
            Assert.IsFalse(foreshoreProfile.HasBreakWater);
            CollectionAssert.IsEmpty(foreshoreProfile.Geometry);
        }
コード例 #4
0
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string testName         = "original name";
            const string testId           = "test id";
            var          foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0),
                                                                 Enumerable.Empty <Point2D>(),
                                                                 null,
                                                                 new ForeshoreProfile.ConstructionProperties
            {
                Id   = testId,
                Name = testName
            });
            var registry = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0);

            // Assert
            Assert.AreNotSame(testName, entity.Name,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
            Assert.AreEqual(testName, entity.Name);
            Assert.AreNotSame(testId, entity.Id,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
            Assert.AreEqual(testId, entity.Id);
        }
コード例 #5
0
        /// <summary>
        /// Creates a <see cref="ForeshoreProfileEntity"/> based on the information of the <see cref="ForeshoreProfile"/>.
        /// </summary>
        /// <param name="foreshoreProfile">The foreshore profile to create a database entity for.</param>
        /// <param name="registry">The object keeping track of create operations.</param>
        /// <param name="order">The index at which <paramref name="foreshoreProfile"/> resides within its parent.</param>
        /// <returns>A new <see cref="ForeshoreProfileEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static ForeshoreProfileEntity Create(this ForeshoreProfile foreshoreProfile, PersistenceRegistry registry, int order)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

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

            var foreshoreProfileEntity = new ForeshoreProfileEntity
            {
                Id          = foreshoreProfile.Id.DeepClone(),
                Name        = foreshoreProfile.Name.DeepClone(),
                GeometryXml = new Point2DCollectionXmlSerializer().ToXml(foreshoreProfile.Geometry),
                X           = foreshoreProfile.WorldReferencePoint.X,
                Y           = foreshoreProfile.WorldReferencePoint.Y,
                X0          = foreshoreProfile.X0,
                Orientation = foreshoreProfile.Orientation,
                Order       = order
            };

            if (foreshoreProfile.HasBreakWater)
            {
                foreshoreProfileEntity.BreakWaterHeight = foreshoreProfile.BreakWater.Height;
                foreshoreProfileEntity.BreakWaterType   = Convert.ToByte(foreshoreProfile.BreakWater.Type);
            }

            registry.Register(foreshoreProfileEntity, foreshoreProfile);

            return(foreshoreProfileEntity);
        }
 private static void AddEntitiesForForeshoreProfiles(
     ForeshoreProfileCollection foreshoreProfiles,
     FailureMechanismEntity entity,
     PersistenceRegistry registry)
 {
     for (var i = 0; i < foreshoreProfiles.Count; i++)
     {
         ForeshoreProfileEntity foreshoreProfileEntity = foreshoreProfiles[i].Create(registry, i);
         entity.ForeshoreProfileEntities.Add(foreshoreProfileEntity);
     }
 }
        private static void AddEntitiesForForeshoreProfiles(
            IEnumerable <ForeshoreProfile> foreshoreProfiles,
            FailureMechanismEntity entity,
            PersistenceRegistry registry)
        {
            var i = 0;

            foreach (ForeshoreProfile foreshoreProfile in foreshoreProfiles)
            {
                ForeshoreProfileEntity foreshoreProfileEntity = foreshoreProfile.Create(registry, i++);
                entity.ForeshoreProfileEntities.Add(foreshoreProfileEntity);
            }
        }
コード例 #8
0
        public void Read_GeometryXmlNullOrEmpty_ThrowsArgumentException(string xml)
        {
            // Setup
            var entity = new ForeshoreProfileEntity
            {
                GeometryXml = xml
            };

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

            // Assert
            string paramName = Assert.Throws <ArgumentException>(test).ParamName;

            Assert.AreEqual("xml", paramName);
        }
コード例 #9
0
        public void Create_WithBreakWater_ReturnsForeshoreProfileWithBreakWaterPropertiesSet()
        {
            // Setup
            double height = new Random(21).NextDouble();
            const BreakWaterType breakWaterType = BreakWaterType.Caisson;
            var foreshoreProfile = new TestForeshoreProfile(new BreakWater(breakWaterType, height));
            var registry         = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual((int)breakWaterType, entity.BreakWaterType);
            Assert.AreEqual(height, entity.BreakWaterHeight, foreshoreProfile.BreakWater.Height.GetAccuracy());
        }
コード例 #10
0
        public void Read_WithGeometryAndBreakWaterTypeAndValues_CompleteForeshoreProfile()
        {
            // Setup
            const string         name           = "testName";
            const string         id             = "testId";
            var                  random         = new Random(21);
            int                  order          = random.Next();
            double               orientation    = random.NextDouble();
            double               x0             = random.NextDouble();
            double               height         = random.NextDouble();
            const BreakWaterType breakWaterType = BreakWaterType.Wall;

            var points = new[]
            {
                new Point2D(0, 0)
            };
            string pointXml = new Point2DCollectionXmlSerializer().ToXml(points);
            var    entity   = new ForeshoreProfileEntity
            {
                Order            = order,
                Id               = id,
                Name             = name,
                Orientation      = orientation,
                X0               = x0,
                BreakWaterType   = Convert.ToByte(breakWaterType),
                BreakWaterHeight = height,
                GeometryXml      = pointXml
            };

            var readConversionCollector = new ReadConversionCollector();

            // Call
            ForeshoreProfile foreshoreProfile = entity.Read(readConversionCollector);

            // Assert
            Assert.IsNotNull(foreshoreProfile);
            Assert.AreEqual(name, foreshoreProfile.Name);
            Assert.AreEqual(order, entity.Order);
            Assert.AreEqual(id, foreshoreProfile.Id);
            Assert.AreEqual(name, entity.Name);
            Assert.AreEqual(orientation, foreshoreProfile.Orientation, foreshoreProfile.Orientation.GetAccuracy());
            Assert.AreEqual(x0, entity.X0);
            Assert.AreEqual(breakWaterType, foreshoreProfile.BreakWater.Type);
            Assert.IsTrue(foreshoreProfile.HasBreakWater);
            CollectionAssert.AreEqual(points, foreshoreProfile.Geometry);
        }
コード例 #11
0
        public void Create_ForeshoreProfileAlreadyRegistered_ReturnRegisteredEntity()
        {
            // Setup
            var foreshoreProfile = new TestForeshoreProfile();
            var registry         = new PersistenceRegistry();

            ForeshoreProfileEntity entity1 = foreshoreProfile.Create(registry, 0);

            // Precondition:
            Assert.IsTrue(registry.Contains(foreshoreProfile));

            // Call
            ForeshoreProfileEntity entity2 = foreshoreProfile.Create(registry, 0);

            // Assert
            Assert.AreSame(entity1, entity2);
        }
        public void Read_EntityWithForeshoreProfile_ReturnCalculation(bool flagUsage, BreakWaterType type, int randomSeed)
        {
            // Setup
            var random = new Random(randomSeed);

            double breakWaterHeight = random.NextDouble();
            var    points           = new[]
            {
                new Point2D(0, 0)
            };
            string pointXml        = new Point2DCollectionXmlSerializer().ToXml(points);
            var    foreshoreEntity = new ForeshoreProfileEntity
            {
                Id = "id",
                BreakWaterHeight = breakWaterHeight,
                BreakWaterType   = Convert.ToByte(type),
                GeometryXml      = pointXml
            };

            var entity = new HeightStructuresCalculationEntity
            {
                UseForeshore           = Convert.ToByte(flagUsage),
                UseBreakWater          = Convert.ToByte(!flagUsage),
                ForeshoreProfileEntity = foreshoreEntity,
                BreakWaterType         = Convert.ToByte(type),
                BreakWaterHeight       = breakWaterHeight,
                ScenarioContribution   = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            StructuresCalculationScenario <HeightStructuresInput> calculation = entity.Read(collector);

            // Assert
            HeightStructuresInput input = calculation.InputParameters;

            Assert.AreEqual(flagUsage, input.UseForeshore);
            Assert.AreEqual(!flagUsage, input.UseBreakWater);
            Assert.AreEqual(type, input.BreakWater.Type);
            Assert.AreEqual(breakWaterHeight, input.BreakWater.Height, input.BreakWater.Height.GetAccuracy());
            CollectionAssert.AreEqual(points, input.ForeshoreProfile.Geometry);
            Assert.IsNotNull(input.ForeshoreProfile);
        }
コード例 #13
0
        public void Read_EntityNotReadBefore_EntityRegistered()
        {
            // Setup
            var collector = new ReadConversionCollector();

            var entity = new ForeshoreProfileEntity
            {
                Id          = "id",
                GeometryXml = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0])
            };

            // Precondition
            Assert.IsFalse(collector.Contains(entity));

            // Call
            entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.Contains(entity));
        }
        public void Read_EntityWithForeshoreProfileEntity_ReturnCalculationWithForeshoreProfile()
        {
            // Setup
            var profile       = new TestForeshoreProfile();
            var profileEntity = new ForeshoreProfileEntity();
            var entity        = new StabilityPointStructuresCalculationEntity
            {
                ForeshoreProfileEntity = profileEntity,
                ScenarioContribution   = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(profileEntity, profile);

            // Call
            StructuresCalculationScenario <StabilityPointStructuresInput> calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(profile, calculation.InputParameters.ForeshoreProfile);
        }
コード例 #15
0
        public void Create_WithGeometry_ReturnsForeshoreProfileWithGeometryStringSet()
        {
            // Setup
            int order          = new Random(21).Next();
            var geometryPoints = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 0)
            };
            var foreshoreProfile = new TestForeshoreProfile(geometryPoints);
            var registry         = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, order);

            // Assert
            Assert.IsNotNull(entity);
            string expectedXml = new Point2DCollectionXmlSerializer().ToXml(geometryPoints);

            Assert.AreEqual(expectedXml, entity.GeometryXml);
        }
        public void Read_EntityWithForeshoreProfileInCollector_CalculationHasAlreadyReadForeshoreProfile()
        {
            // Setup
            var foreshoreProfile       = new TestForeshoreProfile();
            var foreshoreProfileEntity = new ForeshoreProfileEntity
            {
                GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty <Point2D>())
            };
            var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity
            {
                ForeshoreProfileEntity = foreshoreProfileEntity
            };

            var collector = new ReadConversionCollector();

            collector.Read(foreshoreProfileEntity, foreshoreProfile);

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

            // Assert
            Assert.AreSame(foreshoreProfile, calculation.InputParameters.ForeshoreProfile);
        }
コード例 #17
0
        public void Create_WithNaNProperties_ReturnsForeshoreProfileWithPropertiesSetToNaN()
        {
            // Setup
            var foreshoreProfile = new ForeshoreProfile(
                new Point2D(0, 0),
                Enumerable.Empty <Point2D>(),
                new BreakWater(BreakWaterType.Caisson, double.NaN),
                new ForeshoreProfile.ConstructionProperties
            {
                Id          = "id",
                Orientation = double.NaN,
                X0          = double.NaN
            });
            var registry = new PersistenceRegistry();

            // Call
            ForeshoreProfileEntity entity = foreshoreProfile.Create(registry, 0);

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNaN(entity.Orientation);
            Assert.IsNaN(entity.X0);
            Assert.IsNaN(entity.BreakWaterHeight);
        }
コード例 #18
0
        public void Read_EntityWithForeshoreProfileEntity_InputObjectUpdatedWithForeshoreProfile()
        {
            // Setup
            var foreshoreProfile = new TestForeshoreProfile();
            var foreshoreEntity  = new ForeshoreProfileEntity();

            var mocks  = new MockRepository();
            var entity = mocks.Stub <IStructuresCalculationEntity>();

            entity.ForeshoreProfileEntity = foreshoreEntity;
            mocks.ReplayAll();

            var inputToUpdate = new SimpleStructuresInput();
            var collector     = new ReadConversionCollector();

            collector.Read(foreshoreEntity, foreshoreProfile);

            // Call
            entity.Read(inputToUpdate, collector);

            // Assert
            Assert.AreSame(foreshoreProfile, inputToUpdate.ForeshoreProfile);
            mocks.VerifyAll();
        }
        public void Read_EntityWithForeshoreProfileNotYetInCollector_CalculationWithCreatedForeshoreProfileAndRegisteredNewEntities()
        {
            // Setup
            const string id = "profile";
            var          foreshoreProfileEntity = new ForeshoreProfileEntity
            {
                Id          = id,
                GeometryXml = new Point2DCollectionXmlSerializer().ToXml(Enumerable.Empty <Point2D>())
            };

            var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity
            {
                ForeshoreProfileEntity = foreshoreProfileEntity
            };

            var collector = new ReadConversionCollector();

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

            // Assert
            Assert.IsTrue(collector.Contains(foreshoreProfileEntity));
            CollectionAssert.AreEqual(id, calculation.InputParameters.ForeshoreProfile.Id);
        }
コード例 #20
0
 private static ForeshoreProfile GetDikeProfileValue(ForeshoreProfileEntity foreshoreProfileEntity, ReadConversionCollector collector)
 {
     return(foreshoreProfileEntity?.Read(collector));
 }
コード例 #21
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="ForeshoreProfileEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="ForeshoreProfile"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(ForeshoreProfileEntity entity, ForeshoreProfile model)
 {
     Register(foreshoreProfiles, entity, model);
 }