Beispiel #1
0
        public void GivenFailureMechanismWithDikeProfiles_WhenAddingAndRemovingElements_ThenCollectionIsUpdated()
        {
            // Scenario
            var          failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            const string filePath         = "path";

            DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0, 0), "id1");
            DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(1, 1), "id2");
            DikeProfile dikeProfile3 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(2, 2), "id3");

            failureMechanism.DikeProfiles.AddRange(new[]
            {
                dikeProfile1
            }, filePath);

            // Event
            failureMechanism.DikeProfiles.AddRange(new[]
            {
                dikeProfile3,
                dikeProfile2
            }, filePath);
            failureMechanism.DikeProfiles.Remove(dikeProfile1);

            // Result
            DikeProfile[] expectedDikeProfiles =
            {
                dikeProfile3,
                dikeProfile2
            };
            CollectionAssert.AreEqual(expectedDikeProfiles, failureMechanism.DikeProfiles);
        }
        public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataHasPartialOverlap_UpdatesTargetCollection()
        {
            // Setup
            const string addedDikeProfileId   = "ID A";
            const string removedDikeProfileId = "ID B";
            const string updatedDikeProfileId = "ID C";
            const string commonName           = "Just a name for dike profile";

            DikeProfile dikeProfileToBeRemoved = DikeProfileTestFactory.CreateDikeProfile(commonName, removedDikeProfileId);
            DikeProfile dikeProfileToBeUpdated = DikeProfileTestFactory.CreateDikeProfile(commonName, updatedDikeProfileId);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles;

            dikeProfiles.AddRange(new[]
            {
                dikeProfileToBeRemoved,
                dikeProfileToBeUpdated
            }, sourceFilePath);

            DikeProfile dikeProfileToUpdateFrom = DeepCloneAndModify(dikeProfileToBeUpdated);
            DikeProfile dikeProfileToBeAdded    = DikeProfileTestFactory.CreateDikeProfile(commonName, addedDikeProfileId);

            DikeProfile[] readDikeProfiles =
            {
                dikeProfileToBeAdded,
                dikeProfileToUpdateFrom
            };

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(readDikeProfiles,
                                                                                                    sourceFilePath);

            // Assert
            Assert.AreEqual(2, dikeProfiles.Count);
            DikeProfile[] expectedDikeProfiles =
            {
                dikeProfileToBeAdded,
                dikeProfileToBeUpdated
            };
            CollectionAssert.AreEqual(expectedDikeProfiles, dikeProfiles);

            DikeProfile addedDikeProfile = dikeProfiles[0];

            Assert.AreSame(dikeProfileToBeAdded, addedDikeProfile);
            AssertDikeProfile(dikeProfileToBeAdded, addedDikeProfile);

            DikeProfile updatedDikeProfile = dikeProfiles[1];

            Assert.AreSame(dikeProfileToBeUpdated, updatedDikeProfile);
            AssertDikeProfile(dikeProfileToUpdateFrom, updatedDikeProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                dikeProfileToBeUpdated,
                dikeProfiles
            }, affectedObjects);
        }
        public void UpdateDikeProfilesWithImportedData_CollectionAndImportedDataCollectionNotEmpty_ReplacesCurrentWithImportedData()
        {
            // Setup
            DikeProfile targetDikeProfile = DikeProfileTestFactory.CreateDikeProfile("Name A", "Name A ID");
            var         failureMechanism  = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.DikeProfiles.AddRange(new[]
            {
                targetDikeProfile
            }, sourceFilePath);

            DikeProfile readDikeProfile = DikeProfileTestFactory.CreateDikeProfile("Name B", "Name B ID");

            var strategy = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(new[]
            {
                readDikeProfile
            }, sourceFilePath);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                failureMechanism.DikeProfiles
            }, affectedObjects);

            DikeProfile[] expectedDikeProfiles =
            {
                readDikeProfile
            };
            CollectionAssert.AreEqual(expectedDikeProfiles, failureMechanism.DikeProfiles);
        }
Beispiel #4
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);
        }
        public void ChildNodeObjects_Always_ReturnDikeProfiles()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            DikeProfile dikeProfile1     = DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id1");
            DikeProfile dikeProfile2     = DikeProfileTestFactory.CreateDikeProfile(string.Empty, "id2");
            var         failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.DikeProfiles.AddRange(new[]
            {
                dikeProfile1,
                dikeProfile2
            }, "path");

            var dikeProfilesContext = new DikeProfilesContext(failureMechanism.DikeProfiles, failureMechanism, assessmentSection);

            // Call
            object[] children = info.ChildNodeObjects(dikeProfilesContext);

            // Assert
            Assert.AreEqual(2, children.Length);
            Assert.AreSame(dikeProfile1, children.ElementAt(0));
            Assert.AreSame(dikeProfile2, children.ElementAt(1));
            mocks.VerifyAll();
        }
        public void Data_SetDikeProfileInstanceWithData_ReturnCorrectPropertyValues()
        {
            // Setup
            DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(new[]
            {
                new RoughnessPoint(new Point2D(0, 0), 0.6),
                new RoughnessPoint(new Point2D(1, 1), 0.7)
            });

            var properties = new DikeProfileDikeGeometryProperties();

            // Call
            properties.Data = dikeProfile;

            // Assert
            var expectedCoordinates = new[]
            {
                new Point2D(0, 0),
                new Point2D(1, 1)
            };

            CollectionAssert.AreEqual(expectedCoordinates, properties.Coordinates);

            var expectedRoughness = new[]
            {
                new RoundedDouble(2, 0.6)
            };

            CollectionAssert.AreEqual(expectedRoughness, properties.Roughnesses);
        }
        public void UpdateDikeProfilesWithImportedData_CurrentCollectionEmptyAndReadProfilesHaveDuplicateIds_ThrowsUpdateException()
        {
            // Setup
            const string duplicateId    = "A duplicated ID";
            DikeProfile  dikeProfileOne = DikeProfileTestFactory.CreateDikeProfile("name one", duplicateId);
            DikeProfile  dikeProfileTwo = DikeProfileTestFactory.CreateDikeProfile("Another dike profile", duplicateId);

            var targetCollection = new DikeProfileCollection();
            var strategy         = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism());

            // Call
            void Call() => strategy.UpdateDikeProfilesWithImportedData(new[]
            {
                dikeProfileOne,
                dikeProfileTwo
            }, sourceFilePath);

            // Assert
            var exception = Assert.Throws <UpdateDataException>(Call);

            const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten.";

            Assert.AreEqual(expectedMessage, exception.Message);

            CollectionAssert.IsEmpty(targetCollection);
        }
        public void NotifyObservers_DataUpdatedNotifyObserversOnOldData_NoUpdateInViewData()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile  = GetDikeProfileWithGeometry();
                var         calculation1 = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = dikeProfile
                    }
                };

                var calculation2 = new GrassCoverErosionInwardsCalculation();

                view.Data = calculation1;
                ChartData dataBeforeUpdate = view.Chart.Data;

                view.Data = calculation2;

                DikeProfile dikeProfile2 = GetSecondDikeProfileWithGeometry();

                calculation1.InputParameters.DikeProfile = dikeProfile2;

                // Call
                calculation1.InputParameters.NotifyObservers();

                // Assert
                Assert.AreEqual(dataBeforeUpdate, view.Chart.Data);
            }
        }
Beispiel #9
0
        public void IsDikeProfileIntersectionWithReferenceLineInSection_DikeProfileDoesNotIntersectReferenceLine_ReturnsFalse()
        {
            // Setup
            DikeProfile dikeProfile   = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0));
            var         referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(10.0, 0.0),
                new Point2D(20.0, 0.0)
            });

            var calculation = new GrassCoverErosionInwardsCalculationScenario
            {
                InputParameters =
                {
                    DikeProfile = dikeProfile
                }
            };

            IEnumerable <Segment2D> lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points);

            // Call
            bool intersects = calculation.IsDikeProfileIntersectionWithReferenceLineInSection(lineSegments);

            // Assert
            Assert.IsFalse(intersects);
        }
        public void Data_SetChartData_ChartDataSet()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile = GetDikeProfileWithGeometry();
                var         calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile = dikeProfile
                    }
                };

                // Call
                view.Data = calculation;

                // Assert
                Assert.AreSame(calculation, view.Data);

                ChartDataCollection chartData = view.Chart.Data;
                Assert.IsInstanceOf <ChartDataCollection>(chartData);
                Assert.AreEqual(3, chartData.Collection.Count());
                AssertDikeProfileChartData(dikeProfile, chartData.Collection.ElementAt(dikeProfileIndex));
                AssertForeshoreChartData(dikeProfile, chartData.Collection.ElementAt(foreshoreIndex));
                AssertDikeHeightChartData(dikeProfile, chartData.Collection.ElementAt(dikeHeightIndex));
            }
        }
        public void Data_UseForeshoreFalse_SetEmptyForeshoreDataOnChart()
        {
            // Setup
            using (var view = new GrassCoverErosionInwardsInputView())
            {
                DikeProfile dikeProfile = GetDikeProfileWithGeometry();
                var         calculation = new GrassCoverErosionInwardsCalculation
                {
                    InputParameters =
                    {
                        DikeProfile  = dikeProfile,
                        UseForeshore = false
                    }
                };

                // Call
                view.Data = calculation;

                // Assert
                Assert.AreSame(calculation, view.Data);

                ChartDataCollection chartData = view.Chart.Data;
                Assert.IsInstanceOf <ChartDataCollection>(chartData);
                Assert.AreEqual(3, chartData.Collection.Count());

                var dikeGeometryData = (ChartLineData)chartData.Collection.ElementAt(dikeProfileIndex);
                var foreshoreData    = (ChartLineData)chartData.Collection.ElementAt(foreshoreIndex);
                var dikeHeightData   = (ChartLineData)chartData.Collection.ElementAt(dikeHeightIndex);

                CollectionAssert.IsEmpty(foreshoreData.Points);
                Assert.AreEqual("Voorlandprofiel", foreshoreData.Name);
                AssertDikeProfileChartData(dikeProfile, dikeGeometryData);
                AssertDikeHeightChartData(dikeProfile, dikeHeightData);
            }
        }
        /// <summary>
        /// Removes the <see cref="DikeProfile"/> and clears all the data that depends on it, either directly or indirectly.
        /// </summary>
        /// <param name="dikeProfileToRemove">The dike profile to remove.</param>
        /// <param name="calculations">The calculations that may have
        /// <paramref name="dikeProfileToRemove"/> assigned.</param>
        /// <param name="dikeProfiles">The collection of <see cref="DikeProfile"/> in
        /// which <paramref name="dikeProfileToRemove"/> is contained.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of all affected objects by this operation.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception>
        public static IEnumerable <IObservable> RemoveDikeProfile(DikeProfile dikeProfileToRemove,
                                                                  IEnumerable <GrassCoverErosionInwardsCalculation> calculations,
                                                                  DikeProfileCollection dikeProfiles)
        {
            if (dikeProfileToRemove == null)
            {
                throw new ArgumentNullException(nameof(dikeProfileToRemove));
            }

            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (dikeProfiles == null)
            {
                throw new ArgumentNullException(nameof(dikeProfiles));
            }

            IEnumerable <GrassCoverErosionInwardsCalculation> affectedCalculations =
                calculations.Where(calc => ReferenceEquals(dikeProfileToRemove, calc.InputParameters.DikeProfile));

            var affectedObjects = new List <IObservable>
            {
                dikeProfiles
            };

            affectedObjects.AddRange(ClearDikeProfileDependentData(affectedCalculations));

            dikeProfiles.Remove(dikeProfileToRemove);
            return(affectedObjects);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void GenerateCalculations_Always_SetsCorrectCalculations()
        {
            // Setup
            var calculationGroup = new CalculationGroup();

            DikeProfile dikeProfile1 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0), "profiel 1");
            DikeProfile dikeProfile2 = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0), "profiel 2");

            var failureMechanismContribution = new FailureMechanismContribution(0.01, 0.001);

            // Call
            GrassCoverErosionInwardsCalculationConfigurationHelper.GenerateCalculations(
                calculationGroup, new[]
            {
                dikeProfile1,
                dikeProfile2
            }, failureMechanismContribution);

            // Assert
            Assert.AreEqual(2, calculationGroup.Children.Count);

            var calculation1 = (GrassCoverErosionInwardsCalculationScenario)calculationGroup.Children.First();

            Assert.AreEqual("name", calculation1.Name);
            Assert.AreEqual(dikeProfile1, calculation1.InputParameters.DikeProfile);
            Assert.AreEqual(failureMechanismContribution.NormativeProbability, calculation1.InputParameters.DikeHeightTargetProbability);
            Assert.AreEqual(failureMechanismContribution.NormativeProbability, calculation1.InputParameters.OvertoppingRateTargetProbability);

            var calculation2 = (GrassCoverErosionInwardsCalculationScenario)calculationGroup.Children.Last();

            Assert.AreEqual("name (1)", calculation2.Name);
            Assert.AreEqual(dikeProfile2, calculation2.InputParameters.DikeProfile);
            Assert.AreEqual(failureMechanismContribution.NormativeProbability, calculation2.InputParameters.DikeHeightTargetProbability);
            Assert.AreEqual(failureMechanismContribution.NormativeProbability, calculation2.InputParameters.OvertoppingRateTargetProbability);
        }
        public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfileAndImportedMultipleDikeProfilesWithSameId_ThrowsUpdateException()
        {
            // Setup
            const string duplicateId         = "A duplicated ID";
            DikeProfile  expectedDikeProfile = DikeProfileTestFactory.CreateDikeProfile("expectedName", duplicateId);

            var targetCollection = new DikeProfileCollection();

            DikeProfile[] expectedTargetCollection =
            {
                expectedDikeProfile
            };
            targetCollection.AddRange(expectedTargetCollection, sourceFilePath);

            DikeProfile[] importedTargetCollection =
            {
                DeepCloneAndModify(expectedDikeProfile),
                DeepCloneAndModify(expectedDikeProfile)
            };

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism());

            // Call
            void Call() => strategy.UpdateDikeProfilesWithImportedData(importedTargetCollection, sourceFilePath);

            // Assert
            var          exception       = Assert.Throws <UpdateDataException>(Call);
            const string expectedMessage = "Geïmporteerde data moet unieke elementen bevatten.";

            Assert.AreEqual(expectedMessage, exception.Message);

            CollectionAssert.AreEqual(expectedTargetCollection, targetCollection);
            AssertDikeProfile(expectedDikeProfile, targetCollection[0]);
        }
Beispiel #16
0
        public void IsDikeProfileIntersectionWithReferenceLineInSection_EmptySegmentCollection_ThrowsInvalidOperationException()
        {
            // Setup
            DikeProfile dikeProfile   = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0));
            var         referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(10.0, 0.0)
            });

            var calculation = new GrassCoverErosionInwardsCalculationScenario
            {
                InputParameters =
                {
                    DikeProfile = dikeProfile
                }
            };

            // Call
            void Call() => calculation.IsDikeProfileIntersectionWithReferenceLineInSection(Enumerable.Empty <Segment2D>());

            // Assert
            Assert.Throws <InvalidOperationException>(Call);
        }
Beispiel #17
0
        public void Import_UseForeshoreButProfileWithoutGeometry_LogMessageAndContinueImport()
        {
            // Setup
            string filePath = Path.Combine(importerPath, "validConfigurationCalculationUseForeshoreWithoutGeometry.xml");

            var         calculationGroup = new CalculationGroup();
            DikeProfile dikeProfile      = DikeProfileTestFactory.CreateDikeProfile("Dijkprofiel", "Dijkprofiel ID");
            var         importer         = new GrassCoverErosionInwardsCalculationConfigurationImporter(
                filePath,
                calculationGroup,
                new FailureMechanismContribution(0.01, 0.001),
                Enumerable.Empty <HydraulicBoundaryLocation>(),
                new[]
            {
                dikeProfile
            });

            // Call
            var successful = false;

            void Call() => successful = importer.Import();

            // Assert
            const string expectedMessage = "Het opgegeven dijkprofiel 'Dijkprofiel ID' heeft geen voorlandgeometrie en kan daarom niet gebruikt worden. Berekening 'Berekening 1' is overgeslagen.";

            TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 2);
            Assert.IsTrue(successful);
            CollectionAssert.IsEmpty(calculationGroup.Children);
        }
        public void UpdateDikeProfilesWithImportedData_DikeProfilePropertiesChanged_UpdateRelevantProperties()
        {
            // Setup
            DikeProfile dikeProfileToUpdate     = DikeProfileTestFactory.CreateDikeProfile("name", "ID A");
            DikeProfile dikeProfileToUpdateFrom = DeepCloneAndModify(dikeProfileToUpdate);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            DikeProfileCollection targetCollection = failureMechanism.DikeProfiles;

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

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

            // Call
            strategy.UpdateDikeProfilesWithImportedData(new[]
            {
                dikeProfileToUpdateFrom
            }, sourceFilePath);

            // Assert
            Assert.AreSame(dikeProfileToUpdate, targetCollection[0]);
            AssertDikeProfile(dikeProfileToUpdateFrom, dikeProfileToUpdate);
        }
        public void Constructor_Always_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile();

            // Call
            var properties = new DikeProfileDikeGeometryProperties
            {
                Data = dikeProfile
            };

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(2, dynamicProperties.Count);

            PropertyDescriptor coordinatesProperty = dynamicProperties[coordinatesPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(coordinatesProperty,
                                                                            "Misc",
                                                                            "Coördinaten [m]",
                                                                            "Lijst met punten in lokale coördinaten.",
                                                                            true);

            PropertyDescriptor roughnessesProperty = dynamicProperties[roughnessesPropertyIndex];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(roughnessesProperty,
                                                                            "Misc",
                                                                            "Ruwheid invloedsfactoren [-]",
                                                                            "Lijst met invloedsfactoren voor ruwheid op het talud van elk onderdeel.",
                                                                            true);
        }
        public void Data_SetNewDikeProfileInstance_ReturnCorrectPropertyValues()
        {
            // Setup
            const string id          = "DP";
            const string name        = "Dijkprofiel";
            var          dikeProfile = new DikeProfile(
                new Point2D(12.34, 56.78),
                Enumerable.Empty <RoughnessPoint>(),
                Enumerable.Empty <Point2D>(),
                new BreakWater(BreakWaterType.Caisson, 2),
                new DikeProfile.ConstructionProperties
            {
                Id   = id,
                Name = name
            });

            // Call
            var properties = new DikeProfileProperties
            {
                Data = dikeProfile
            };

            // 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(dikeProfile.ForeshoreProfile, properties.BreakWater.Data);
            Assert.AreSame(dikeProfile.ForeshoreProfile, properties.Foreshore.Data);
            Assert.AreSame(dikeProfile, properties.DikeGeometry.Data);
            Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces);
            Assert.AreEqual(0.0, properties.DikeHeight.Value);
        }
Beispiel #21
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);
        }
 private static IEnumerable <Point2D> GetWorldPoints(DikeProfile dikeProfile)
 {
     return(AdvancedMath2D.FromXToXY(
                dikeProfile.DikeGeometry.Select(p => - p.Point.X),
                dikeProfile.WorldReferencePoint,
                -dikeProfile.X0,
                dikeProfile.Orientation));
 }
Beispiel #23
0
 /// <summary>
 /// Updates the name of <paramref name="chartData"/> based on <paramref name="dikeProfile"/>.
 /// </summary>
 /// <param name="chartData">The <see cref="ChartLineData"/> to update the name for.</param>
 /// <param name="dikeProfile">The <see cref="DikeProfile"/> used for obtaining the name.</param>
 /// <remarks>A default name is set (the same as in <see cref="CreateDikeGeometryChartData"/>) when <paramref name="dikeProfile"/> is <c>null</c>.</remarks>
 public static void UpdateDikeGeometryChartDataName(ChartLineData chartData, DikeProfile dikeProfile)
 {
     chartData.Name = dikeProfile != null
                          ? string.Format(RiskeerCommonFormsResources.ChartDataFactory_Create_DataIdentifier_0_DataTypeDisplayName_1_,
                                          dikeProfile.Name,
                                          Resources.DikeProfile_DisplayName)
                          : Resources.DikeProfile_DisplayName;
 }
Beispiel #24
0
 private static void AddEntitiesForDikeProfiles(GrassCoverErosionInwardsFailureMechanism mechanism, PersistenceRegistry registry, FailureMechanismEntity entity)
 {
     for (var i = 0; i < mechanism.DikeProfiles.Count; i++)
     {
         DikeProfile dikeProfile = mechanism.DikeProfiles[i];
         entity.DikeProfileEntities.Add(dikeProfile.Create(registry, i));
     }
 }
        public void Import_AllOkTestData_CorrectDikeProfileProperties()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine = CreateMatchingReferenceLine();

            var updateDataStrategy   = new TestDikeProfileUpdateStrategy();
            var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider);

            // Call
            dikeProfilesImporter.Import();

            // Assert
            Assert.IsTrue(updateDataStrategy.Updated);

            DikeProfile[] dikeProfiles = updateDataStrategy.ReadDikeProfiles;
            DikeProfile   dikeProfile1 = dikeProfiles[0];

            Assert.AreEqual("profiel001", dikeProfile1.Id);
            Assert.AreEqual("profiel001", dikeProfile1.Name);

            DikeProfile dikeProfile2 = dikeProfiles[1];

            Assert.AreEqual("profiel002", dikeProfile2.Id);
            Assert.AreEqual("profiel002", dikeProfile2.Name);

            DikeProfile dikeProfile3 = dikeProfiles[2];

            Assert.AreEqual("profiel003", dikeProfile3.Id);
            Assert.AreEqual("profiel003", dikeProfile3.Name);

            DikeProfile dikeProfile4 = dikeProfiles[3];

            Assert.AreEqual(new Point2D(136432.12250000238, 538235.26300000318), dikeProfile4.WorldReferencePoint);
            Assert.AreEqual("profiel004", dikeProfile4.Id);
            Assert.AreEqual("Valide naam", dikeProfile4.Name);
            Assert.AreEqual(-17.93475471, dikeProfile4.X0);
            Assert.AreEqual(330.0, dikeProfile4.Orientation, dikeProfile4.Orientation.GetAccuracy());
            Assert.IsFalse(dikeProfile4.HasBreakWater);

            DikeProfile dikeProfile5 = dikeProfiles[4];

            Assert.AreEqual(new Point2D(136039.49100000039, 533920.28050000477), dikeProfile5.WorldReferencePoint);
            Assert.AreEqual("profiel005", dikeProfile5.Id);
            Assert.AreEqual("Heeeeeeeeeeeeeeeeeeeeeeeele laaaaaaaaaaaaaaaaaaaange naaaaaaaaaaam", dikeProfile5.Name);
            Assert.AreEqual(15.56165507, dikeProfile5.X0);
            Assert.AreEqual(330.0, dikeProfile5.Orientation, dikeProfile5.Orientation.GetAccuracy());
            Assert.IsTrue(dikeProfile5.HasBreakWater);
            Assert.AreEqual(6.0, dikeProfile5.DikeHeight, dikeProfile5.DikeHeight.GetAccuracy());
        }
Beispiel #26
0
        public void DikeProfile_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged()
        {
            // Setup
            DikeProfile newProfile = DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0));
            var         newValue   = new DataGridViewComboBoxItemWrapper <DikeProfile>(newProfile);

            var calculation = new GrassCoverErosionInwardsCalculationScenario();

            // Call & Assert
            SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.DikeProfile = newValue, calculation);
        }
Beispiel #27
0
        public void DikeProfile_SetNewValue_InputSyncedAccordingly(DikeProfile newDikeProfile)
        {
            // Setup
            var input = new GrassCoverErosionInwardsInput();

            // Call
            input.DikeProfile = newDikeProfile;

            // Assert
            AssertDikeProfileInput(newDikeProfile, input);
        }
Beispiel #28
0
        public void BreakWater_SetToNull_GetsNewlySetNull()
        {
            // Call
            var dikeProfile = new DikeProfile(new Point2D(0, 0), new RoughnessPoint[0], new Point2D[0],
                                              null, new DikeProfile.ConstructionProperties
            {
                Id = "id"
            });

            // Assert
            Assert.IsNull(dikeProfile.BreakWater);
        }
        private void SetChartData()
        {
            GrassCoverErosionInwardsInput input = data.InputParameters;
            DikeProfile dikeProfile             = input.DikeProfile;

            GrassCoverErosionInwardsChartDataFactory.UpdateForeshoreGeometryChartDataName(foreshoreChartData, input);
            GrassCoverErosionInwardsChartDataFactory.UpdateDikeGeometryChartDataName(dikeGeometryChartData, dikeProfile);

            foreshoreChartData.Points    = GrassCoverErosionInwardsChartDataPointsFactory.CreateForeshoreGeometryPoints(input);
            dikeGeometryChartData.Points = GrassCoverErosionInwardsChartDataPointsFactory.CreateDikeGeometryPoints(dikeProfile);
            dikeHeightChartData.Points   = GrassCoverErosionInwardsChartDataPointsFactory.CreateDikeHeightPoints(input);
        }
        public void Text_Always_ReturnDikeProfileName()
        {
            // Setup
            const string profileName = "Random profile name";
            DikeProfile  dikeProfile = DikeProfileTestFactory.CreateDikeProfile(profileName);

            // Call
            string text = info.Text(dikeProfile);

            // Assert
            Assert.AreEqual(profileName, text);
        }