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);
        }
Ejemplo n.º 2
0
        public void UpdateForeshoreProfilesWithImportedData_ForeshoreProfilePropertiesChanged_UpdateRelevantProperties(
            ForeshoreProfile readForeshoreProfile)
        {
            // Setup
            var profileToBeUpdated = new TestForeshoreProfile();

            var targetCollection = new ForeshoreProfileCollection();

            targetCollection.AddRange(new[]
            {
                profileToBeUpdated
            }, sourceFilePath);

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), targetCollection);

            // Call
            strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                readForeshoreProfile
            }, sourceFilePath);

            // Assert
            Assert.AreEqual(1, targetCollection.Count);
            Assert.AreSame(profileToBeUpdated, targetCollection[0]);
            AssertForeshoreProfile(readForeshoreProfile, profileToBeUpdated);
        }
Ejemplo n.º 3
0
        private static WaveImpactAsphaltCoverFailureMechanism CreateWaveImpactAsphaltCoverFailureMechanismWithAllUpdateForeshoreProfileScenarios(
            ForeshoreProfile unaffectedForeshoreProfile)
        {
            WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism =
                TestDataGenerator.GetWaveImpactAsphaltCoverFailureMechanismWithAllCalculationConfigurations();

            waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles.AddRange(new[]
            {
                unaffectedForeshoreProfile
            }, sourceFilePath);
            var unaffectedCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation
            {
                InputParameters =
                {
                    ForeshoreProfile = unaffectedForeshoreProfile
                },
                Output = new WaveImpactAsphaltCoverWaveConditionsOutput(new[]
                {
                    new TestWaveConditionsOutput()
                })
            };

            waveImpactAsphaltCoverFailureMechanism.CalculationsGroup.Children.Add(unaffectedCalculation);
            return(waveImpactAsphaltCoverFailureMechanism);
        }
        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);
        }
Ejemplo n.º 5
0
        public void Constructor_ValidParameters_ExpectedValues()
        {
            // Setup
            const string validId         = "id";
            var          worldCoordinate = new Point2D(1.1, 2.2);

            var foreshoreGeometry = new[]
            {
                new Point2D(0.0, 1.1),
                new Point2D(8.0, 9.1)
            };

            // Call
            var foreshoreProfile = new ForeshoreProfile(worldCoordinate, foreshoreGeometry,
                                                        null, new ForeshoreProfile.ConstructionProperties
            {
                Id = validId
            });

            // Assert
            Assert.IsInstanceOf <Observable>(foreshoreProfile);

            Assert.IsInstanceOf <RoundedDouble>(foreshoreProfile.Orientation);
            Assert.IsInstanceOf <double>(foreshoreProfile.X0);

            Assert.AreEqual(validId, foreshoreProfile.Id);
            Assert.AreEqual(validId, foreshoreProfile.Name);
            Assert.AreSame(worldCoordinate, foreshoreProfile.WorldReferencePoint);
            Assert.AreEqual(0.0, foreshoreProfile.X0);
            Assert.AreEqual(0.0, foreshoreProfile.Orientation.Value);
            Assert.AreEqual(2, foreshoreProfile.Orientation.NumberOfDecimalPlaces);
            Assert.IsNull(foreshoreProfile.BreakWater);
            CollectionAssert.AreEqual(foreshoreGeometry, foreshoreProfile.Geometry);
            Assert.AreEqual(2, foreshoreProfile.Geometry.NumberOfDecimalPlaces);
        }
Ejemplo n.º 6
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
            }));
        }
        public void TryReadForeshoreProfile_WithForeshoreProfileToFindForeshoreProfilesEmpty_LogsErrorReturnsFalse()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            ForeshoreProfile profile = null;
            var valid = true;

            const string profileName = "someName";
            const string calculationName = "name";

            // Call
            void Validate() => valid = importer.PublicTryReadForeshoreProfile(
                                   profileName, calculationName, Enumerable.Empty<ForeshoreProfile>(), out profile);

            // Assert
            var expectedMessage = $"Het voorlandprofiel met ID '{profileName}' bestaat niet. Berekening '{calculationName}' is overgeslagen.";
            TestHelper.AssertLogMessageWithLevelIsGenerated(Validate, Tuple.Create(expectedMessage, LogLevelConstant.Error));
            Assert.IsFalse(valid);
            Assert.IsNull(profile);
        }
Ejemplo n.º 8
0
        public void SynchronizeForeshoreProfileInput_ChangedForeshoreProfile_ExpectedValues()
        {
            // Setup
            var differentProfile = new ForeshoreProfile(new Point2D(9, 9), new[]
            {
                new Point2D(3.3, 4.4),
                new Point2D(5.5, 6.6)
            }, new BreakWater(BreakWaterType.Caisson, 2),
                                                        new ForeshoreProfile.ConstructionProperties
            {
                Id          = "id",
                Name        = "Some name",
                Orientation = 123.0
            });

            var input = new WaveConditionsInput
            {
                ForeshoreProfile = new TestForeshoreProfile()
            };

            input.ForeshoreProfile.CopyProperties(differentProfile);

            // Precondition
            AssertForeshoreProfileInputProperties(new TestForeshoreProfile(), input);

            // Call
            input.SynchronizeForeshoreProfileInput();

            // Assert
            AssertForeshoreProfileInputProperties(differentProfile, input);
        }
Ejemplo n.º 9
0
        private static void AssertForeshoreProfilePropertiesOfInput(ForeshoreProfile expectedForeshoreProfile, SimpleStructuresInput input)
        {
            var defaultInput = new SimpleStructuresInput();

            if (expectedForeshoreProfile == null)
            {
                Assert.AreEqual(defaultInput.UseBreakWater, input.UseBreakWater);
                Assert.AreEqual(defaultInput.UseForeshore, input.UseForeshore);
            }
            else
            {
                Assert.AreEqual(expectedForeshoreProfile.Geometry.Count() > 1, input.UseForeshore);
                Assert.AreEqual(expectedForeshoreProfile.HasBreakWater, input.UseBreakWater);
            }

            if (expectedForeshoreProfile?.BreakWater == null)
            {
                Assert.AreEqual(defaultInput.BreakWater.Type, input.BreakWater.Type);
                Assert.AreEqual(defaultInput.BreakWater.Height, input.BreakWater.Height);
            }
            else
            {
                Assert.AreEqual(expectedForeshoreProfile.BreakWater.Type, input.BreakWater.Type);
                Assert.AreEqual(expectedForeshoreProfile.BreakWater.Height, input.BreakWater.Height);
            }
        }
        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);
        }
Ejemplo n.º 11
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);
        }
        public void Data_SetNewForeshoreProfileInstance_ReturnCorrectPropertyValues()
        {
            // Setup
            const string id               = "VP";
            const string name             = "Voorlandprofiel";
            var          foreshoreProfile = new ForeshoreProfile(new Point2D(12.34, 56.78), new Point2D[0],
                                                                 null, new ForeshoreProfile.ConstructionProperties
            {
                Id   = id,
                Name = name
            });

            // Call
            var properties = new ForeshoreProfileProperties
            {
                Data = foreshoreProfile
            };

            // Assert
            Assert.AreEqual(new Point2D(12, 57), properties.WorldReferencePoint);
            Assert.AreEqual(id, properties.Id);
            Assert.AreEqual(name, properties.Name);
            Assert.AreEqual(2, properties.Orientation.NumberOfDecimalPlaces);
            Assert.AreEqual(0.0, properties.Orientation.Value);
            Assert.AreSame(foreshoreProfile, properties.BreakWater.Data);
            Assert.AreEqual(foreshoreProfile, properties.Foreshore.Data);
        }
        /// <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);
        }
Ejemplo n.º 14
0
        private static void AssertForeshoreProfileInputProperties(ForeshoreProfile expectedForeshoreProfile,
                                                                  WaveConditionsInput input)
        {
            var defaultInput = new WaveConditionsInput();

            if (expectedForeshoreProfile == null)
            {
                Assert.AreEqual(defaultInput.UseBreakWater, input.UseBreakWater);
                Assert.AreEqual(defaultInput.UseForeshore, input.UseForeshore);
            }
            else
            {
                Assert.AreEqual(expectedForeshoreProfile.Orientation, input.Orientation);
                Assert.AreEqual(expectedForeshoreProfile.Geometry.Count() > 1, input.UseForeshore);
                Assert.AreEqual(expectedForeshoreProfile.HasBreakWater, input.UseBreakWater);
            }

            if (expectedForeshoreProfile?.BreakWater == null)
            {
                Assert.AreEqual(defaultInput.BreakWater.Type, input.BreakWater.Type);
                Assert.AreEqual(defaultInput.BreakWater.Height, input.BreakWater.Height);
            }
            else
            {
                Assert.AreEqual(expectedForeshoreProfile.BreakWater.Type, input.BreakWater.Type);
                Assert.AreEqual(expectedForeshoreProfile.BreakWater.Height, input.BreakWater.Height);
            }
        }
Ejemplo n.º 15
0
        public void UpdateForeshoreProfilesWithImportedData_MultipleCalculationsWithOutputAndProfile_UpdatesCalculationWithUpdatedProfile()
        {
            // Setup
            var affectedProfile = new TestForeshoreProfile("Name", "Updated ID");
            TestCalculationWithForeshoreProfile affectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(affectedProfile);
            ForeshoreProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            const string unaffectedProfileId   = "Unaffected ID";
            const string unaffectedProfileName = "Name";
            var          unaffectedProfile     = new TestForeshoreProfile(unaffectedProfileName, unaffectedProfileId);
            TestCalculationWithForeshoreProfile unaffectedCalculation =
                TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(unaffectedProfile);

            var foreshoreProfiles = new ForeshoreProfileCollection();

            TestForeshoreProfile[] originalForeshoreProfiles =
            {
                affectedProfile,
                unaffectedProfile
            };
            foreshoreProfiles.AddRange(originalForeshoreProfiles, sourceFilePath);

            var failureMechanism = new TestCalculatableFailureMechanism(new[]
            {
                affectedCalculation,
                unaffectedCalculation
            });

            var strategy = new ForeshoreProfileUpdateDataStrategy(failureMechanism, foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects =
                strategy.UpdateForeshoreProfilesWithImportedData(new[]
            {
                new TestForeshoreProfile(unaffectedProfileName,
                                         unaffectedProfileId),
                profileToUpdateFrom
            },
                                                                 sourceFilePath);

            // Assert
            Assert.IsTrue(unaffectedCalculation.HasOutput);
            Assert.AreSame(unaffectedProfile,
                           unaffectedCalculation.InputParameters.ForeshoreProfile);

            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.AreSame(affectedProfile, affectedCalculation.InputParameters.ForeshoreProfile);

            CollectionAssert.AreEquivalent(originalForeshoreProfiles, foreshoreProfiles);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                foreshoreProfiles
            }, affectedObjects);
        }
Ejemplo n.º 16
0
 private static IEnumerable <Point2D> GetWorldPoints(ForeshoreProfile foreshoreProfile)
 {
     return(AdvancedMath2D.FromXToXY(
                foreshoreProfile.Geometry.Select(p => - p.X).ToArray(),
                foreshoreProfile.WorldReferencePoint,
                -foreshoreProfile.X0,
                foreshoreProfile.Orientation));
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 public DerivedForeshoreProfile(ForeshoreProfile profile)
     : base(profile.WorldReferencePoint, profile.Geometry, profile.BreakWater, new ConstructionProperties
 {
     Id          = profile.Id,
     Name        = profile.Name,
     X0          = profile.X0,
     Orientation = profile.X0
 })
 {
 }
Ejemplo n.º 19
0
        private static void AssertForeshoreChartData(ForeshoreProfile foreshoreProfile, ChartData chartData)
        {
            Assert.IsInstanceOf <ChartLineData>(chartData);
            var foreshoreChartData = (ChartLineData)chartData;

            RoundedPoint2DCollection foreshoreGeometry = foreshoreProfile.Geometry;
            string expectedName = $"{foreshoreProfile.Name} - Voorlandprofiel";

            Assert.AreEqual(expectedName, chartData.Name);
            CollectionAssert.AreEqual(foreshoreGeometry, foreshoreChartData.Points);
        }
Ejemplo n.º 20
0
        public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionAndImportedCollectionHasPartialOverlap_UpdatesTargetDataCollection()
        {
            // Setup
            var commonName = "Name";
            var foreshoreProfileToBeUpdated = new TestForeshoreProfile(commonName, "Updated ID");
            var foreshoreProfileToBeRemoved = new TestForeshoreProfile(commonName, "Removed ID");

            var foreshoreProfiles = new ForeshoreProfileCollection();

            foreshoreProfiles.AddRange(new[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfileToBeRemoved
            }, sourceFilePath);

            ForeshoreProfile foreshoreProfileToUpdateFrom = DeepCloneAndModify(foreshoreProfileToBeUpdated);
            var foreshoreProfileToBeAdded = new TestForeshoreProfile(commonName, "Added ID");

            ForeshoreProfile[] importedForeshoreProfiles =
            {
                foreshoreProfileToUpdateFrom,
                foreshoreProfileToBeAdded
            };

            var strategy = new ForeshoreProfileUpdateDataStrategy(new TestCalculatableFailureMechanism(), foreshoreProfiles);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(importedForeshoreProfiles,
                                                                                                         sourceFilePath);

            // Assert
            Assert.AreEqual(2, foreshoreProfiles.Count);
            CollectionAssert.AreEqual(new[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfileToBeAdded
            }, foreshoreProfiles);

            ForeshoreProfile updatedForeshoreProfile = foreshoreProfiles[0];

            Assert.AreSame(foreshoreProfileToBeUpdated, updatedForeshoreProfile);
            AssertForeshoreProfile(foreshoreProfileToUpdateFrom, updatedForeshoreProfile);

            ForeshoreProfile addedForeshoreProfile = foreshoreProfiles[1];

            Assert.AreSame(foreshoreProfileToBeAdded, addedForeshoreProfile);
            AssertForeshoreProfile(foreshoreProfileToBeAdded, addedForeshoreProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                foreshoreProfileToBeUpdated,
                foreshoreProfiles
            }, affectedObjects);
        }
Ejemplo n.º 21
0
        public void BreakWater_SetToNull_GetsNewlySetNull()
        {
            // Call
            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0],
                                                        null, new ForeshoreProfile.ConstructionProperties
            {
                Id = "id"
            });

            // Assert
            Assert.IsNull(foreshoreProfile.BreakWater);
        }
Ejemplo n.º 22
0
        private static void AssertForeshoreProfile(ForeshoreProfile expectedForeshoreProfile,
                                                   ForeshoreProfile actualForeshoreProfile)
        {
            Assert.AreEqual(expectedForeshoreProfile.WorldReferencePoint, actualForeshoreProfile.WorldReferencePoint);
            CollectionAssert.AreEqual(expectedForeshoreProfile.Geometry, actualForeshoreProfile.Geometry);
            Assert.AreEqual(expectedForeshoreProfile.BreakWater, actualForeshoreProfile.BreakWater);

            Assert.AreEqual(expectedForeshoreProfile.Id, actualForeshoreProfile.Id);
            Assert.AreEqual(expectedForeshoreProfile.Name, actualForeshoreProfile.Name);
            Assert.AreEqual(expectedForeshoreProfile.X0, actualForeshoreProfile.X0);
            Assert.AreEqual(expectedForeshoreProfile.Orientation, actualForeshoreProfile.Orientation);
        }
Ejemplo n.º 23
0
        public void Constructor_NonEmptyOrWhitespaceNameDifferentFromId_NameValueSet(string name)
        {
            // Call
            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0],
                                                        null, new ForeshoreProfile.ConstructionProperties
            {
                Id   = "id",
                Name = name
            });

            // Assert
            Assert.AreEqual(name, foreshoreProfile.Name);
        }
Ejemplo n.º 24
0
        public void CopyProperties_FromForeshoreProfileNull_ThrowsArgumentNullException()
        {
            // Setup
            ForeshoreProfile foreshoreProfile = CreateFullyDefinedForeshoreProfile();

            // Call
            TestDelegate call = () => foreshoreProfile.CopyProperties(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("fromForeshoreProfile", exception.ParamName);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        public void Orientation_SetToValueWithTooManyDecimalPlaces_ValueIsRounded()
        {
            // Call
            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0],
                                                        null, new ForeshoreProfile.ConstructionProperties
            {
                Id          = "id",
                Orientation = 1.23456
            });

            // Assert
            Assert.AreEqual(2, foreshoreProfile.Orientation.NumberOfDecimalPlaces);
            Assert.AreEqual(1.23, foreshoreProfile.Orientation.Value);
        }
Ejemplo n.º 27
0
        public void HasBreakWater_BreakWaterSetToNull_ReturnFalse()
        {
            // Setup
            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0],
                                                        null, new ForeshoreProfile.ConstructionProperties
            {
                Id = "id"
            });

            // Call
            bool hasBreakWater = foreshoreProfile.HasBreakWater;

            // Assert
            Assert.IsFalse(hasBreakWater);
        }
Ejemplo n.º 28
0
        private static ForeshoreProfile CreateForeshoreProfile(ProfileLocation dikeProfileLocation, DikeProfileData dikeProfileData)
        {
            var foreshoreProfile = new ForeshoreProfile(dikeProfileLocation.Point,
                                                        dikeProfileData.ForeshoreGeometry.Select(fg => fg.Point),
                                                        CreateBreakWater(dikeProfileData),
                                                        new ForeshoreProfile.ConstructionProperties
            {
                Id          = dikeProfileData.Id,
                Name        = dikeProfileLocation.Name,
                X0          = dikeProfileLocation.Offset,
                Orientation = dikeProfileData.Orientation
            });

            return(foreshoreProfile);
        }
Ejemplo n.º 29
0
        public void Constructor_NullOrWhitespaceName_NameSetToId(string name)
        {
            // Setup
            const string id = "id";

            // Call
            var foreshoreProfile = new ForeshoreProfile(new Point2D(0, 0), new Point2D[0], null, new ForeshoreProfile.ConstructionProperties
            {
                Id   = id,
                Name = name
            });

            // Assert
            Assert.AreEqual(id, foreshoreProfile.Name);
        }
Ejemplo n.º 30
0
        public void BreakWater_SetToNewInstance_GetsNewlySetInstance()
        {
            // Setup
            var newBreakWater = new BreakWater(BreakWaterType.Caisson, 1.1);

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

            // Assert
            Assert.AreSame(newBreakWater, foreshoreProfile.BreakWater);
        }