Exemple #1
0
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string originalId   = "no_breakwater";
            const string originalName = "Dike profile without break water.";
            var          dikeProfile  = new DikeProfile(new Point2D(1.1, 2.2),
                                                        new RoughnessPoint[0],
                                                        new Point2D[0],
                                                        null,
                                                        new DikeProfile.ConstructionProperties
            {
                Id   = originalId,
                Name = originalName
            });
            var registry = new PersistenceRegistry();

            // Call
            DikeProfileEntity entity = dikeProfile.Create(registry, 0);

            // Assert
            Assert.AreNotSame(originalName, entity.Name,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
            Assert.AreEqual(originalName, entity.Name);
            Assert.AreNotSame(originalId, entity.Id,
                              "To create stable binary representations/fingerprints, it's really important that strings are not shared.");
            Assert.AreEqual(originalId, entity.Id);
        }
Exemple #2
0
        /// <summary>
        /// Creates a <see cref="DikeProfileEntity"/> based on the information of the <see cref="DikeProfile"/>.
        /// </summary>
        /// <param name="dikeProfile">The dike 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="DikeProfileEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception>
        internal static DikeProfileEntity Create(this DikeProfile dikeProfile, PersistenceRegistry registry, int order)
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

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

            var sectionResultEntity = new DikeProfileEntity
            {
                X  = dikeProfile.WorldReferencePoint.X,
                Y  = dikeProfile.WorldReferencePoint.Y,
                X0 = dikeProfile.X0,
                DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry),
                ForeshoreXml    = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry),
                Orientation     = dikeProfile.Orientation,
                DikeHeight      = dikeProfile.DikeHeight,
                Id    = dikeProfile.Id.DeepClone(),
                Name  = dikeProfile.Name.DeepClone(),
                Order = order
            };

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

            registry.Register(sectionResultEntity, dikeProfile);
            return(sectionResultEntity);
        }
Exemple #3
0
        public void Read_ValidEntityWithUnreadDikeProfileEntity_ReturnCalculationWithNewDikeProfile()
        {
            // Setup
            var dikeProfileEntity = new DikeProfileEntity
            {
                Id = "a",
                DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(new RoughnessPoint[0]),
                ForeshoreXml    = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0])
            };
            var entity = new GrassCoverErosionInwardsCalculationEntity
            {
                DikeProfileEntity                = dikeProfileEntity,
                ScenarioContribution             = 0,
                DikeHeightTargetProbability      = 0.01,
                OvertoppingRateTargetProbability = 0.02
            };

            var collector = new ReadConversionCollector();

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

            // Assert
            Assert.IsNotNull(calculation.InputParameters.DikeProfile);
            Assert.IsTrue(collector.Contains(dikeProfileEntity));
        }
        private static BreakWater CreateBreakWater(DikeProfileEntity entity)
        {
            if (entity.BreakWaterType == null || entity.BreakWaterHeight == null)
            {
                return(null);
            }

            return(new BreakWater((BreakWaterType)entity.BreakWaterType, entity.BreakWaterHeight.Value));
        }
 private static DikeProfile.ConstructionProperties CreateProperties(DikeProfileEntity entity)
 {
     return(new DikeProfile.ConstructionProperties
     {
         Id = entity.Id,
         Name = entity.Name,
         Orientation = entity.Orientation.ToNullAsNaN(),
         DikeHeight = entity.DikeHeight.ToNullAsNaN(),
         X0 = entity.X0.ToNullAsNaN()
     });
 }
Exemple #6
0
        public void Read_ReadConversionCollectorNull_ThrowArgumentNullException()
        {
            // Setup
            var entity = new DikeProfileEntity();

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

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("collector", paramName);
        }
Exemple #7
0
        public void Read_AlreadyReadDikeProfileEntity_ReturnDikeProfile()
        {
            // Setup
            var         registeredEntity  = new DikeProfileEntity();
            DikeProfile registeredProfile = DikeProfileTestFactory.CreateDikeProfile();
            var         collector         = new ReadConversionCollector();

            collector.Read(registeredEntity, registeredProfile);

            // Call
            DikeProfile returnedProfile = registeredEntity.Read(collector);

            // Assert
            Assert.AreSame(registeredProfile, returnedProfile);
        }
Exemple #8
0
        public void Create_WithoutBreakWater_ReturnEntityWithNullBreakWaterProperties()
        {
            // Setup
            int order       = new Random(22).Next();
            var dikeProfile = new DikeProfile(new Point2D(1.1, 2.2),
                                              new[]
            {
                new RoughnessPoint(new Point2D(3.3, 4.4), 0.75),
                new RoughnessPoint(new Point2D(5.5, 6.6), 0.75)
            },
                                              new[]
            {
                new Point2D(7.7, 8.8),
                new Point2D(9.9, 10.10)
            },
                                              null,
                                              new DikeProfile.ConstructionProperties
            {
                Id          = "no_breakwater",
                Name        = "Dike profile without break water.",
                DikeHeight  = 11.11,
                Orientation = 12.12,
                X0          = 13.13
            });
            var registry = new PersistenceRegistry();

            // Call
            DikeProfileEntity entity = dikeProfile.Create(registry, order);

            // Assert
            Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X);
            Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y);
            Assert.AreEqual(dikeProfile.X0, entity.X0);
            Assert.AreEqual(order, entity.Order);
            string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry);

            Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml);
            string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry);

            Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml);
            Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation);
            Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight);
            Assert.AreEqual(dikeProfile.Id, entity.Id);
            Assert.AreEqual(dikeProfile.Name, entity.Name);

            Assert.IsNull(entity.BreakWaterHeight);
            Assert.IsNull(entity.BreakWaterType);
        }
Exemple #9
0
        public void Create_WithBreakWater_ReturnEntity(BreakWaterType type, double height)
        {
            // Setup
            int order       = new Random(42).Next();
            var dikeProfile = new DikeProfile(new Point2D(1234.4567, 5678.432),
                                              new[]
            {
                new RoughnessPoint(new Point2D(-6.6, -3.3), 0.75),
                new RoughnessPoint(new Point2D(4.4, 5.5), 0.75)
            },
                                              new[]
            {
                new Point2D(-12.12, -13.13),
                new Point2D(-6.6, -3.3)
            },
                                              new BreakWater(type, height),
                                              new DikeProfile.ConstructionProperties
            {
                Id          = "no_breakwater",
                Name        = "Dike profile without break water.",
                DikeHeight  = 98.76,
                Orientation = 76.54,
                X0          = -12.34
            });
            var registry = new PersistenceRegistry();

            // Call
            DikeProfileEntity entity = dikeProfile.Create(registry, order);

            // Assert
            Assert.AreEqual(dikeProfile.WorldReferencePoint.X, entity.X);
            Assert.AreEqual(dikeProfile.WorldReferencePoint.Y, entity.Y);
            Assert.AreEqual(dikeProfile.X0, entity.X0);
            Assert.AreEqual(order, entity.Order);
            string convertedDikeGeometry = new RoughnessPointCollectionXmlSerializer().ToXml(dikeProfile.DikeGeometry);

            Assert.AreEqual(convertedDikeGeometry, entity.DikeGeometryXml);
            string convertedForeshoreGeometry = new Point2DCollectionXmlSerializer().ToXml(dikeProfile.ForeshoreGeometry);

            Assert.AreEqual(convertedForeshoreGeometry, entity.ForeshoreXml);
            Assert.AreEqual(dikeProfile.Orientation.Value, entity.Orientation);
            Assert.AreEqual(dikeProfile.DikeHeight.Value, entity.DikeHeight);
            Assert.AreEqual(dikeProfile.Id, entity.Id);
            Assert.AreEqual(dikeProfile.Name, entity.Name);

            Assert.AreEqual((byte)type, entity.BreakWaterType);
            Assert.AreEqual(height, entity.BreakWaterHeight);
        }
Exemple #10
0
        public void Create_DikeProfileAlreadyRegistered_ReturnRegisteredEntity()
        {
            // Setup
            DikeProfile       dikeProfile = DikeProfileTestFactory.CreateDikeProfile();
            var               registry    = new PersistenceRegistry();
            DikeProfileEntity entity1     = dikeProfile.Create(registry, 0);

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

            // Call
            DikeProfileEntity entity2 = dikeProfile.Create(registry, 0);

            // Assert
            Assert.AreSame(entity1, entity2);
        }
Exemple #11
0
        public void Read_DikeProfileEntityWithBreakWater_ReturnDikeProfileWithBreakWater(BreakWaterType type, double height)
        {
            // Setup
            var foreshorePoints = new Point2D[0];
            var roughnessPoints = new[]
            {
                new RoughnessPoint(new Point2D(1.1, 2.2), 1.0),
                new RoughnessPoint(new Point2D(3.3, 4.4), 0.6),
                new RoughnessPoint(new Point2D(5.5, 6.6), 1.0),
                new RoughnessPoint(new Point2D(7.7, 8.8), 0.5)
            };
            var entity = new DikeProfileEntity
            {
                Id               = "with_breakwater",
                Name             = "I have a Breakwater!",
                Orientation      = 360.0,
                BreakWaterHeight = height,
                BreakWaterType   = Convert.ToByte(type),
                ForeshoreXml     = new Point2DCollectionXmlSerializer().ToXml(foreshorePoints),
                DikeGeometryXml  = new RoughnessPointCollectionXmlSerializer().ToXml(roughnessPoints),
                DikeHeight       = 4.5,
                X  = 93.0,
                Y  = 945.6,
                X0 = 9.34
            };

            var collector = new ReadConversionCollector();

            // Call
            DikeProfile dikeProfile = entity.Read(collector);

            // Assert
            Assert.AreEqual(entity.Id, dikeProfile.Id);
            Assert.AreEqual(entity.Name, dikeProfile.Name);
            Assert.AreEqual(entity.Orientation, dikeProfile.Orientation.Value);
            CollectionAssert.AreEqual(foreshorePoints, dikeProfile.ForeshoreGeometry);
            CollectionAssert.AreEqual(roughnessPoints, dikeProfile.DikeGeometry, new RoughnessPointComparer());
            Assert.AreEqual(entity.X, dikeProfile.WorldReferencePoint.X);
            Assert.AreEqual(entity.Y, dikeProfile.WorldReferencePoint.Y);
            Assert.AreEqual(entity.X0, dikeProfile.X0);

            Assert.AreEqual(height, dikeProfile.BreakWater.Height.Value);
            Assert.AreEqual(type, dikeProfile.BreakWater.Type);

            Assert.IsTrue(collector.Contains(entity));
        }
Exemple #12
0
        public void Read_DikeGeometryXmlNullOrEmpty_ThrowsArgumentException(string xml)
        {
            // Setup
            var profile = new DikeProfileEntity
            {
                DikeGeometryXml = xml,
                ForeshoreXml    = validRoughnessPointXml
            };

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

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

            Assert.AreEqual("xml", paramName);
        }
Exemple #13
0
        public void Read_DikeProfileEntityWithBreakWaterPropertiesNull_ReturnDikeProfileWithoutBreakWater()
        {
            // Setup
            var foreshorePoints = new[]
            {
                new Point2D(-9.9, 8.8),
                new Point2D(-7.7, 5.5)
            };
            var roughnessPoints = new[]
            {
                new RoughnessPoint(new Point2D(-7.7, 5.5), 1.0),
                new RoughnessPoint(new Point2D(5.5, 6.6), 0.5)
            };
            var entity = new DikeProfileEntity
            {
                Id               = "saved",
                Name             = "Just saved",
                Orientation      = 45.67,
                BreakWaterHeight = null,
                BreakWaterType   = null,
                ForeshoreXml     = new Point2DCollectionXmlSerializer().ToXml(foreshorePoints),
                DikeGeometryXml  = new RoughnessPointCollectionXmlSerializer().ToXml(roughnessPoints),
                DikeHeight       = 1.2,
                X  = 3.4,
                Y  = 5.6,
                X0 = -7.8
            };

            var collector = new ReadConversionCollector();

            // Call
            DikeProfile dikeProfile = entity.Read(collector);

            // Assert
            Assert.AreEqual(entity.Id, dikeProfile.Id);
            Assert.AreEqual(entity.Name, dikeProfile.Name);
            Assert.AreEqual(entity.Orientation, dikeProfile.Orientation.Value);
            CollectionAssert.AreEqual(foreshorePoints, dikeProfile.ForeshoreGeometry);
            CollectionAssert.AreEqual(roughnessPoints, dikeProfile.DikeGeometry, new RoughnessPointComparer());
            Assert.AreEqual(entity.X, dikeProfile.WorldReferencePoint.X);
            Assert.AreEqual(entity.Y, dikeProfile.WorldReferencePoint.Y);
            Assert.AreEqual(entity.X0, dikeProfile.X0);

            Assert.IsFalse(dikeProfile.HasBreakWater);
        }
Exemple #14
0
        public void Read_EntityNotReadBefore_EntityRegistered()
        {
            // Setup
            var collector = new ReadConversionCollector();

            var entity = new DikeProfileEntity
            {
                Id              = "id",
                ForeshoreXml    = new Point2DCollectionXmlSerializer().ToXml(new Point2D[0]),
                DikeGeometryXml = new RoughnessPointCollectionXmlSerializer().ToXml(new RoughnessPoint[0])
            };

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

            // Call
            entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.Contains(entity));
        }
        /// <summary>
        /// Reads the <see cref="DikeProfileEntity"/> and use the information to update a
        /// <see cref="DikeProfile"/>.
        /// </summary>
        /// <param name="entity">The <see cref="DikeProfileEntity"/> to create <see cref="DikeProfile"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="DikeProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <see cref="DikeProfileEntity.DikeGeometryXml"/>
        /// or <see cref="DikeProfileEntity.ForeshoreXml"/> of <paramref name="entity"/> is <c>null</c> or empty.</exception>
        internal static DikeProfile Read(this DikeProfileEntity entity, ReadConversionCollector collector)
        {
            if (collector == null)
            {
                throw new ArgumentNullException(nameof(collector));
            }

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

            var dikeProfile = new DikeProfile(new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()),
                                              new RoughnessPointCollectionXmlSerializer().FromXml(entity.DikeGeometryXml),
                                              new Point2DCollectionXmlSerializer().FromXml(entity.ForeshoreXml),
                                              CreateBreakWater(entity),
                                              CreateProperties(entity));

            collector.Read(entity, dikeProfile);

            return(dikeProfile);
        }
Exemple #16
0
        public void Create_CalculationWithAlreadySavedDikeProfile_ReturnEntityWithDikeProfileEntity()
        {
            // Setup
            DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile();
            var         calculation = new GrassCoverErosionInwardsCalculationScenario
            {
                InputParameters =
                {
                    DikeProfile = dikeProfile
                }
            };

            var dikeProfileEntity = new DikeProfileEntity();
            var registry          = new PersistenceRegistry();

            registry.Register(dikeProfileEntity, dikeProfile);

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

            // Assert
            Assert.AreSame(dikeProfileEntity, entity.DikeProfileEntity);
        }
Exemple #17
0
        public void Read_ValidEntityWithAlreadyReadDikeProfileEntity_ReturnCalculationWithReadDikeProfile()
        {
            // Setup
            DikeProfile dikeProfile       = DikeProfileTestFactory.CreateDikeProfile();
            var         dikeProfileEntity = new DikeProfileEntity();
            var         entity            = new GrassCoverErosionInwardsCalculationEntity
            {
                DikeProfileEntity                = dikeProfileEntity,
                ScenarioContribution             = 0,
                DikeHeightTargetProbability      = 0.01,
                OvertoppingRateTargetProbability = 0.02
            };

            var collector = new ReadConversionCollector();

            collector.Read(dikeProfileEntity, dikeProfile);

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

            // Assert
            Assert.AreSame(dikeProfile, calculation.InputParameters.DikeProfile);
        }
 /// <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="DikeProfileEntity"/> to be registered.</param>
 /// <param name="model">The <see cref="DikeProfile"/> to be registered.</param>
 /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
 internal void Register(DikeProfileEntity entity, DikeProfile model)
 {
     Register(dikeProfiles, entity, model);
 }
Exemple #19
0
 private static DikeProfile GetDikeProfileValue(DikeProfileEntity dikeProfileEntity, ReadConversionCollector collector)
 {
     return(dikeProfileEntity?.Read(collector));
 }