Esempio n. 1
0
        /// <summary>
        /// Makes a deep clone of the foreshore profile and modifies all the properties,
        /// except the <see cref="ForeshoreProfile.Id"/>.
        /// </summary>
        /// <param name="foreshoreProfile">The foreshore profile to deep clone.</param>
        /// <returns>A deep clone of the <paramref name="foreshoreProfile"/>.</returns>
        private static ForeshoreProfile DeepCloneAndModify(ForeshoreProfile foreshoreProfile)
        {
            var random = new Random(21);

            Point2D originalWorldCoordinate = foreshoreProfile.WorldReferencePoint;
            var     modifiedWorldCoordinate = new Point2D(originalWorldCoordinate.X + random.NextDouble(),
                                                          originalWorldCoordinate.Y + random.NextDouble());

            List <Point2D> modifiedForeshoreGeometry = foreshoreProfile.Geometry.ToList();

            modifiedForeshoreGeometry.Add(new Point2D(1, 2));

            RoundedDouble originalBreakWaterHeight = foreshoreProfile.BreakWater?.Height ?? (RoundedDouble)0.0;
            var           modifiedBreakWater       = new BreakWater(random.NextEnumValue <BreakWaterType>(),
                                                                    originalBreakWaterHeight + random.NextDouble());

            string modifiedName        = $"new_name_{foreshoreProfile.Name}";
            double modifiedOrientation = foreshoreProfile.Orientation + random.NextDouble();
            double modifiedX0          = foreshoreProfile.X0 + random.NextDouble();

            return(new ForeshoreProfile(modifiedWorldCoordinate, modifiedForeshoreGeometry,
                                        modifiedBreakWater,
                                        new ForeshoreProfile.ConstructionProperties
            {
                Name = modifiedName,
                Id = foreshoreProfile.Id,
                Orientation = modifiedOrientation,
                X0 = modifiedX0
            }));
        }
Esempio n. 2
0
        public void CopyProperties_FromDikeProfileAllPropertiesChanged_PropertiesUpdated()
        {
            // Setup
            DikeProfile dikeProfileToUpdate = CreateFullyDefinedDikeProfile();

            const string expectedId   = "new_id";
            const string expectedName = "new_name";

            var    random              = new Random(21);
            double expectedX0          = dikeProfileToUpdate.X0 + random.NextDouble();
            var    expectedOrientation = new RoundedDouble(2, (dikeProfileToUpdate.Orientation + random.NextDouble()) % 360);
            var    expectedDikeHeight  = new RoundedDouble(2, dikeProfileToUpdate.DikeHeight + random.NextDouble());

            double expectedBreakWaterHeight = dikeProfileToUpdate.BreakWater.Height + random.NextDouble();
            var    expectedBreakWater       = new BreakWater(random.NextEnumValue <BreakWaterType>(), expectedBreakWaterHeight);

            var expectedForeshoreGeometry = new[]
            {
                new Point2D(10, 10),
                new Point2D(15, 10)
            };

            var expectedDikeGeometry = new[]
            {
                new RoughnessPoint(new Point2D(10, 10), 1),
                new RoughnessPoint(new Point2D(15, 10), 2)
            };

            var expectedWorldReferencePoint = new Point2D(13, 37);

            var dikeProfileToUpdateFrom = new DikeProfile(expectedWorldReferencePoint,
                                                          expectedDikeGeometry,
                                                          expectedForeshoreGeometry,
                                                          expectedBreakWater,
                                                          new DikeProfile.ConstructionProperties
            {
                Id          = expectedId,
                Name        = expectedName,
                X0          = expectedX0,
                Orientation = expectedOrientation,
                DikeHeight  = expectedDikeHeight
            });

            // Call
            dikeProfileToUpdate.CopyProperties(dikeProfileToUpdateFrom);

            // Assert
            TestHelper.AssertAreEqualButNotSame(expectedWorldReferencePoint, dikeProfileToUpdate.WorldReferencePoint);
            CollectionAssert.AreEqual(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry);
            TestHelper.AssertCollectionAreNotSame(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry);
            CollectionAssert.AreEqual(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry);
            TestHelper.AssertCollectionAreNotSame(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry);
            TestHelper.AssertAreEqualButNotSame(expectedBreakWater, dikeProfileToUpdate.BreakWater);
            Assert.AreEqual(expectedId, dikeProfileToUpdate.Id);
            Assert.AreEqual(expectedName, dikeProfileToUpdate.Name);
            Assert.AreEqual(expectedX0, dikeProfileToUpdate.X0);
            Assert.AreEqual(expectedOrientation, dikeProfileToUpdate.Orientation);
            Assert.AreEqual(expectedDikeHeight, dikeProfileToUpdate.DikeHeight);
        }
        public void ForeshoreProfile_SetNewValue_InputSyncedAccordingly(
            [Values(true, false)] bool withBreakWater,
            [Values(true, false)] bool withValidForeshore)
        {
            // Setup
            var                       input = new SimpleStructuresInput();
            BreakWaterType            originalBreakWaterType            = input.BreakWater.Type;
            RoundedDouble             originalBreakWaterHeight          = input.BreakWater.Height;
            HydraulicBoundaryLocation originalHydraulicBoundaryLocation = input.HydraulicBoundaryLocation;

            var foreshoreGeometry = new List <Point2D>
            {
                new Point2D(2.2, 3.3)
            };

            if (withValidForeshore)
            {
                foreshoreGeometry.Add(new Point2D(4.4, 5.5));
            }

            BreakWater breakWater = null;

            if (withBreakWater)
            {
                const BreakWaterType nonDefaultBreakWaterType   = BreakWaterType.Wall;
                const double         nonDefaultBreakWaterHeight = 5.5;

                // Precondition
                Assert.AreNotEqual(nonDefaultBreakWaterType, input.BreakWater.Type);
                Assert.AreNotEqual(nonDefaultBreakWaterHeight, input.BreakWater.Height);

                breakWater = new BreakWater(nonDefaultBreakWaterType, nonDefaultBreakWaterHeight);
            }

            const double orientation      = 96;
            var          foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0),
                                                                 foreshoreGeometry.ToArray(),
                                                                 breakWater,
                                                                 new ForeshoreProfile.ConstructionProperties
            {
                Id          = "id",
                Orientation = orientation
            });

            // Call
            input.ForeshoreProfile = foreshoreProfile;

            // Assert
            Assert.AreSame(foreshoreProfile, input.ForeshoreProfile);
            Assert.AreEqual(withBreakWater, input.UseBreakWater);
            Assert.AreEqual(withBreakWater ? foreshoreProfile.BreakWater.Type : originalBreakWaterType, input.BreakWater.Type);
            Assert.AreEqual(withBreakWater ? foreshoreProfile.BreakWater.Height : originalBreakWaterHeight, input.BreakWater.Height);
            Assert.AreEqual(withValidForeshore, input.UseForeshore);
            CollectionAssert.AreEqual(foreshoreProfile.Geometry, input.ForeshoreGeometry);
            Assert.AreSame(originalHydraulicBoundaryLocation, input.HydraulicBoundaryLocation);
        }
Esempio n. 4
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var random   = new Random(21);
            var original = new BreakWater(random.NextEnumValue <BreakWaterType>(), random.NextDouble());

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a <see cref="ForeshoreProfile"/> with all properties set, except for the
        /// parameters related to <see cref="ForeshoreProfile.ConstructionProperties"/> which
        /// are user specified.
        /// </summary>
        /// <param name="properties">The construction properties.</param>
        /// <returns>A <see cref="ForeshoreProfile"/> with default parameters and
        /// specified values of the <see cref="ForeshoreProfile.ConstructionProperties"/>.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="properties.Id"/>
        /// is <c>null</c>, empty or a whitespace.</exception>
        private static ForeshoreProfile CreateForeshoreProfile(ForeshoreProfile.ConstructionProperties properties)
        {
            var worldReferencePoint = new Point2D(0, 0);
            var geometry            = new[]
            {
                new Point2D(0, 1),
                new Point2D(2, 1)
            };
            var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3);

            return(new ForeshoreProfile(worldReferencePoint, geometry, breakWater, properties));
        }
Esempio n. 6
0
        public void Properties_Height_ReturnsExpectedValue()
        {
            // Setup
            const BreakWaterType type   = BreakWaterType.Caisson;
            const double         height = 100.10;
            var breakWater = new BreakWater(type, height);

            // Call
            breakWater.Height = (RoundedDouble)10.00;

            // Assert
            Assert.AreEqual(10.0, breakWater.Height.Value);
        }
Esempio n. 7
0
        public void Properties_Type_ReturnsExpectedValue(BreakWaterType newType)
        {
            // Setup
            const BreakWaterType type   = BreakWaterType.Caisson;
            const double         height = 100.1;
            var breakWater = new BreakWater(type, height);

            // Call
            breakWater.Type = newType;

            // Assert
            Assert.AreEqual(newType, breakWater.Type);
        }
Esempio n. 8
0
        public void CopyProperties_FromForeshoreProfileAllPropertiesChanged_PropertiesChanged()
        {
            // Setup
            ForeshoreProfile foreshoreProfileToUpdate = CreateFullyDefinedForeshoreProfile();

            const string expectedId   = "new_id";
            const string expectedName = "new_name";

            var    random              = new Random(21);
            double expectedX0          = foreshoreProfileToUpdate.X0 + random.NextDouble();
            var    expectedOrientation = new RoundedDouble(2, (foreshoreProfileToUpdate.Orientation + random.NextDouble()) % 360);

            double expectedBreakWaterHeight = foreshoreProfileToUpdate.BreakWater.Height + random.NextDouble();
            var    expectedBreakWater       = new BreakWater(random.NextEnumValue <BreakWaterType>(), expectedBreakWaterHeight);

            Point2D originalPoint = foreshoreProfileToUpdate.WorldReferencePoint;
            var     expectedWorldReferencePoint = new Point2D(originalPoint.X + random.NextDouble(),
                                                              originalPoint.Y + random.NextDouble());

            var expectedForeshoreGeometry = new[]
            {
                new Point2D(10, 10),
                new Point2D(15, 10)
            };

            var foreshoreProfileToUpdateFrom = new ForeshoreProfile(expectedWorldReferencePoint,
                                                                    expectedForeshoreGeometry,
                                                                    expectedBreakWater,
                                                                    new ForeshoreProfile.ConstructionProperties
            {
                Id          = expectedId,
                Name        = expectedName,
                Orientation = expectedOrientation,
                X0          = expectedX0
            });

            // Call
            foreshoreProfileToUpdate.CopyProperties(foreshoreProfileToUpdateFrom);

            // Assert
            Assert.AreEqual(expectedWorldReferencePoint, foreshoreProfileToUpdate.WorldReferencePoint);
            Assert.AreNotSame(expectedWorldReferencePoint, foreshoreProfileToUpdate.WorldReferencePoint);
            CollectionAssert.AreEqual(expectedForeshoreGeometry, foreshoreProfileToUpdate.Geometry);
            TestHelper.AssertCollectionAreNotSame(expectedForeshoreGeometry, foreshoreProfileToUpdate.Geometry);
            Assert.AreEqual(expectedBreakWater, foreshoreProfileToUpdate.BreakWater);
            Assert.AreNotSame(expectedBreakWater, foreshoreProfileToUpdate.BreakWater);
            Assert.AreEqual(expectedId, foreshoreProfileToUpdate.Id);
            Assert.AreEqual(expectedName, foreshoreProfileToUpdate.Name);
            Assert.AreEqual(expectedX0, foreshoreProfileToUpdate.X0);
            Assert.AreEqual(expectedOrientation, foreshoreProfileToUpdate.Orientation);
        }
Esempio n. 9
0
        public void Constructor_Always_ExpectedValues()
        {
            // Setup
            const BreakWaterType type   = BreakWaterType.Caisson;
            const double         height = 100.1;

            // Call
            var breakWater = new BreakWater(type, height);

            // Assert
            Assert.IsInstanceOf <ICloneable>(breakWater);
            Assert.AreEqual(type, breakWater.Type);
            Assert.AreEqual(height, breakWater.Height, 1e-6);
            Assert.AreEqual(2, breakWater.Height.NumberOfDecimalPlaces);
        }
Esempio n. 10
0
        public void BreakWater_SetToNewInstance_GetsNewlySetInstance()
        {
            // Setup
            var newBreakWater = new BreakWater(BreakWaterType.Caisson, 1.1);

            // Call
            var dikeProfile = new DikeProfile(new Point2D(0, 0), new RoughnessPoint[0], new Point2D[0],
                                              newBreakWater, new DikeProfile.ConstructionProperties
            {
                Id = "id"
            });

            // Assert
            Assert.AreSame(newBreakWater, dikeProfile.BreakWater);
        }
Esempio n. 11
0
        public override object Clone()
        {
            var clone = (StructuresInputBase <T>)base.Clone();

            clone.allowedLevelIncreaseStorage  = (LogNormalDistribution)AllowedLevelIncreaseStorage.Clone();
            clone.storageStructureArea         = (VariationCoefficientLogNormalDistribution)StorageStructureArea.Clone();
            clone.flowWidthAtBottomProtection  = (LogNormalDistribution)FlowWidthAtBottomProtection.Clone();
            clone.criticalOvertoppingDischarge = (VariationCoefficientLogNormalDistribution)CriticalOvertoppingDischarge.Clone();
            clone.widthFlowApertures           = (NormalDistribution)WidthFlowApertures.Clone();
            clone.stormDuration = (VariationCoefficientLogNormalDistribution)StormDuration.Clone();

            clone.BreakWater = (BreakWater)BreakWater.Clone();

            return(clone);
        }
Esempio n. 12
0
        public void HasBreakWater_BreakWaterSetToAnInstance_ReturnTrue()
        {
            // Setup
            var breakWater  = new BreakWater(BreakWaterType.Dam, 12.34);
            var dikeProfile = new DikeProfile(new Point2D(0, 0), new RoughnessPoint[0], new Point2D[0],
                                              breakWater, new DikeProfile.ConstructionProperties
            {
                Id = "id"
            });

            // Call
            bool hasBreakWater = dikeProfile.HasBreakWater;

            // Assert
            Assert.IsTrue(hasBreakWater);
        }
Esempio n. 13
0
        /// <summary>
        /// Creates a <see cref="DikeProfile"/> with all properties set, except for the
        /// parameters related to <see cref="DikeProfile.ConstructionProperties"/> which
        /// are user specified.
        /// </summary>
        /// <param name="properties">The construction properties.</param>
        /// <returns>A <see cref="DikeProfile"/> with default parameters and
        /// specified values of the <see cref="DikeProfile.ConstructionProperties"/>.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="properties.Id"/>
        /// is <c>null</c>, empty or a whitespace.</exception>
        private static DikeProfile CreateDikeProfile(DikeProfile.ConstructionProperties properties)
        {
            var worldCoordinate   = new Point2D(0, 0);
            var foreshoreGeometry = new[]
            {
                new Point2D(0, 1),
                new Point2D(2, 1)
            };
            var dikeGeometry = new[]
            {
                new RoughnessPoint(new Point2D(0, 1), 1),
                new RoughnessPoint(new Point2D(1, 2), 3)
            };
            var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3);

            return(new DikeProfile(worldCoordinate, dikeGeometry, foreshoreGeometry, breakWater, properties));
        }
Esempio n. 14
0
        /// <summary>
        /// Modifies <see cref="BreakWater"/> properties of the current instance
        /// of the foreshore profile to different values.
        /// </summary>
        /// <param name="foreshoreProfile">The current instance of which the properties
        /// need to be modified.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="foreshoreProfile"/>
        /// is <c>null</c>.</exception>
        public static void ChangeBreakWaterProperties(TestForeshoreProfile foreshoreProfile)
        {
            if (foreshoreProfile == null)
            {
                throw new ArgumentNullException(nameof(foreshoreProfile));
            }

            BreakWater differentBreakWater = null;

            if (!foreshoreProfile.HasBreakWater)
            {
                differentBreakWater = new BreakWater(BreakWaterType.Caisson, 12.34);
            }

            var foreshoreProfileToUpdateFrom = new TestForeshoreProfile(differentBreakWater);

            foreshoreProfile.CopyProperties(foreshoreProfileToUpdateFrom);
        }
Esempio n. 15
0
        public void ParseBreakWater_Use_ReturnHydraRingBreakWater(BreakWaterType breakWaterType)
        {
            // Setup
            var    random           = new Random(22);
            double breakWaterHeight = random.NextDouble();

            var mockRepository = new MockRepository();
            var breakWater     = mockRepository.Stub <IUseBreakWater>();

            breakWater.UseBreakWater = true;
            var expectedBreakWater = new BreakWater(breakWaterType, breakWaterHeight);

            breakWater.Stub(call => call.BreakWater).Return(expectedBreakWater);
            mockRepository.ReplayAll();

            // Call
            HydraRingBreakWater parsedBreakWater = HydraRingInputParser.ParseBreakWater(breakWater);

            // Assert
            Assert.AreEqual(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), parsedBreakWater.Type);
            Assert.AreEqual(expectedBreakWater.Height, parsedBreakWater.Height, expectedBreakWater.Height.GetAccuracy());
            mockRepository.VerifyAll();
        }
Esempio n. 16
0
        public void ParseBreakWater_InvalidBreakWaterType_ThrowInvalidEnumArgumentException()
        {
            // Setup
            var random         = new Random(22);
            var mockRepository = new MockRepository();
            var breakWater     = mockRepository.Stub <IUseBreakWater>();

            breakWater.UseBreakWater = true;
            var expectedBreakWater = new BreakWater((BreakWaterType)99, random.NextDouble());

            breakWater.Stub(call => call.BreakWater).Return(expectedBreakWater);
            mockRepository.ReplayAll();

            // Call
            TestDelegate test = () => HydraRingInputParser.ParseBreakWater(breakWater);

            // Assert
            string message = $"The value of argument 'type' ({99}) is invalid for Enum type '{typeof(BreakWaterType).Name}'.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(test, message);

            mockRepository.VerifyAll();
        }
Esempio n. 17
0
        /// <summary>
        /// Returns a collection of modified <see cref="ForeshoreProfile"/> entities, which all differ
        /// except for their id, name, orientation, and X0.
        /// </summary>
        /// <param name="targetName">The name of the target to test while using the test case source.</param>
        /// <param name="testResultDescription">A description of the result of the test while using the test case source.</param>
        /// <returns>The collection of test case data.</returns>
        /// <example>
        /// <code>
        /// [TestCaseSource(
        ///     typeof(ForeshoreProfilePermutationHelper),
        ///     nameof(ForeshoreProfilePermutationHelper.DifferentForeshoreProfilesWithSameIdNameOrientationAndX0),
        ///     new object[]
        ///     {
        ///         "TargetMethodName",
        ///         "TestResult"
        ///     })]
        /// </code>
        /// </example>
        public static IEnumerable <TestCaseData> DifferentForeshoreProfilesWithSameIdNameOrientationAndX0(string targetName, string testResultDescription)
        {
            var referenceProfile = new TestForeshoreProfile();

            var defaultBreakWater = new BreakWater(BreakWaterType.Dam, 0.0);

            var testCaseData = new List <TestCaseData>
            {
                new TestCaseData(new TestForeshoreProfile(referenceProfile.Id, new[]
                {
                    new Point2D(0, 0),
                    new Point2D(1, 1)
                }))
                .SetName($"{targetName}_DifferentGeometry_{testResultDescription}"),
                new TestCaseData(new TestForeshoreProfile(new BreakWater(defaultBreakWater.Type, 1 + defaultBreakWater.Height)))
                .SetName($"{targetName}_DifferentBreakWaterHeight_{testResultDescription}"),
                new TestCaseData(new TestForeshoreProfile(new BreakWater(BreakWaterType.Caisson, defaultBreakWater.Height)))
                .SetName($"{targetName}_DifferentBreakWaterTypeCaisson_{testResultDescription}"),
                new TestCaseData(new TestForeshoreProfile(new BreakWater(BreakWaterType.Wall, defaultBreakWater.Height)))
                .SetName($"{targetName}_DifferentBreakWaterTypeWall_{testResultDescription}")
            };

            return(testCaseData);
        }
Esempio n. 18
0
 public TestUseBreakWater()
 {
     BreakWater = new BreakWater(BreakWaterType.Caisson, 2);
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new instance of <see cref="TestForeshoreProfile"/> with a specified <see cref="BreakWater"/>.
 /// </summary>
 /// <param name="breakWater">The <see cref="BreakWater"/> which needs to be set on the <see cref="ForeshoreProfile"/>.</param>
 public TestForeshoreProfile(BreakWater breakWater)
     : this("id", "name", new Point2D(0, 0), breakWater, Enumerable.Empty <Point2D>())
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Creates a new instance of <see cref="TestForeshoreProfile"/> with given properties.
 /// </summary>
 /// <param name="profileId">The id of the foreshore profile.</param>
 /// <param name="profileName">The name of the foreshore profile.</param>
 /// <param name="worldCoordinate">The location of the foreshore profile.</param>
 /// <param name="breakWater">The breakwater of the foreshore profile.</param>
 /// <param name="geometry">The geometry of the foreshore profile.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="geometry"/>
 /// or <paramref name="worldCoordinate"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">Thrown when:
 /// <list type="bullet">
 /// <item>Any element of <paramref name="geometry"/> is <c>null</c>.</item>
 /// <item><paramref name="profileId"/> is null, empty or whitespaces.</item>
 /// </list></exception>
 private TestForeshoreProfile(string profileId, string profileName, Point2D worldCoordinate, BreakWater breakWater, IEnumerable <Point2D> geometry)
     : base(worldCoordinate,
            geometry,
            breakWater,
            new ConstructionProperties
 {
     Id   = profileId,
     Name = profileName
 })
 {
 }
 public TestInputWithForeshoreProfileAndBreakWater(BreakWater breakWater)
 {
     BreakWater = breakWater;
 }
Esempio n. 22
0
 /// <summary>
 /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/>
 /// are clones.
 /// </summary>
 /// <param name="original">The original object.</param>
 /// <param name="clone">The cloned object.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and
 /// <paramref name="clone"/> are not clones.</exception>
 public static void AreClones(BreakWater original, BreakWater clone)
 {
     Assert.AreEqual(original.Type, clone.Type);
     Assert.AreEqual(original.Height, clone.Height);
 }