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 IsEnabled_DikeProfileCollectionSourcePathSet_ReturnTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine());
            mocks.ReplayAll();

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

            dikeProfiles.AddRange(Enumerable.Empty <DikeProfile>(), "some/path");

            var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection);

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                UpdateInfo importInfo = GetUpdateInfo(plugin);

                // Call
                bool isEnabled = importInfo.IsEnabled(context);

                // Assert
                Assert.IsTrue(isEnabled);
            }

            mocks.VerifyAll();
        }
        /// <summary>
        /// Clears <paramref name="dikeProfiles"/> and clears all the data that depends on it, either directly or indirectly.
        /// </summary>
        /// <param name="calculations">The calculations that may have
        /// an assigned element of <see cref="dikeProfiles"/>.</param>
        /// <param name="dikeProfiles">The collection to be cleared.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of all affected objects by this operation.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static IEnumerable <IObservable> RemoveAllDikeProfiles(IEnumerable <GrassCoverErosionInwardsCalculation> calculations,
                                                                      DikeProfileCollection dikeProfiles)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

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

            IEnumerable <GrassCoverErosionInwardsCalculation> affectedCalculations =
                calculations.Where(calc => calc.InputParameters.DikeProfile != null)
                .ToArray();

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

            affectedObjects.AddRange(ClearDikeProfileDependentData(affectedCalculations));

            dikeProfiles.Clear();
            return(affectedObjects);
        }
        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 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 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]);
        }
        public void IsEnabled_DikeProfileCollectionSourcePathNull_ReturnFalse()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

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

            var context = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection);

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                UpdateInfo importInfo = GetUpdateInfo(plugin);

                // Call
                bool isEnabled = importInfo.IsEnabled(context);

                // Assert
                Assert.IsFalse(isEnabled);
            }

            mocks.VerifyAll();
        }
        public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation());

                var dikeProfiles = new DikeProfileCollection();
                var context      = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection);

                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                bool updatesVerified = updateInfo.VerifyUpdates(context);

                // Assert
                Assert.IsTrue(updatesVerified);
                mocks.VerifyAll();
            }
        }
        public void CurrentPath_DikeProfileCollectionHasPathSet_ReturnsExpectedPath()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            const string expectedFilePath = "some/path";
            var          surfaceLines     = new DikeProfileCollection();

            surfaceLines.AddRange(new[]
            {
                DikeProfileTestFactory.CreateDikeProfile()
            }, expectedFilePath);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            var context = new DikeProfilesContext(surfaceLines, failureMechanism, assessmentSection);

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                // Call
                string currentFilePath = updateInfo.CurrentPath(context);

                // Assert
                Assert.AreEqual(expectedFilePath, currentFilePath);
                mocks.VerifyAll();
            }
        }
        /// <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);
        }
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            using (var plugin = new GrassCoverErosionInwardsPlugin())
            {
                plugin.Gui = gui;

                var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation
                {
                    Output = new TestGrassCoverErosionInwardsOutput()
                });

                var dikeProfiles = new DikeProfileCollection();
                var context      = new DikeProfilesContext(dikeProfiles, failureMechanism, assessmentSection);

                UpdateInfo updateInfo = GetUpdateInfo(plugin);

                string textBoxMessage = null;
                DialogBoxHandler = (name, wnd) =>
                {
                    var helper = new MessageBoxTester(wnd);
                    textBoxMessage = helper.Text;

                    if (isActionConfirmed)
                    {
                        helper.ClickOk();
                    }
                    else
                    {
                        helper.ClickCancel();
                    }
                };

                // Call
                bool updatesVerified = updateInfo.VerifyUpdates(context);

                // Assert
                string expectedInquiryMessage = "Als dijkprofielen wijzigen door het bijwerken, " +
                                                "dan worden de resultaten van berekeningen die deze dijkprofielen gebruiken " +
                                                $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";
                Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
                Assert.AreEqual(isActionConfirmed, updatesVerified);
                mocks.VerifyAll();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GrassCoverErosionInwardsFailureMechanism"/> class.
 /// </summary>
 public GrassCoverErosionInwardsFailureMechanism()
     : base(Resources.GrassCoverErosionInwardsFailureMechanism_DisplayName, Resources.GrassCoverErosionInwardsFailureMechanism_DisplayCode)
 {
     CalculationsGroup = new CalculationGroup
     {
         Name = RiskeerCommonDataResources.FailureMechanism_Calculations_DisplayName
     };
     GeneralInput = new GeneralGrassCoverErosionInwardsInput();
     DikeProfiles = new DikeProfileCollection();
     CalculationsInputComments = new Comment();
 }
Пример #13
0
        public void Constructor_WithValidParameters_ReturnsNewInstance()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            var importTarget  = new DikeProfileCollection();
            var referenceLine = new ReferenceLine();

            // Call
            var importer = new DikeProfilesImporter(importTarget, referenceLine, "", new TestDikeProfileUpdateStrategy(), messageProvider);

            // Assert
            Assert.IsInstanceOf <ProfilesImporter <DikeProfileCollection> >(importer);
        }
        public void Constructor_WithData_ReturnExpectedValues()
        {
            // Setup
            const string someFilePath = "location/to/a/file";
            var          collection   = new DikeProfileCollection();

            collection.AddRange(Enumerable.Empty <DikeProfile>(), someFilePath);

            // Call
            var properties = new DikeProfileCollectionProperties(collection);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <DikeProfileCollection> >(properties);
            Assert.AreSame(collection, properties.Data);
            Assert.AreEqual(someFilePath, properties.SourcePath);
        }
Пример #15
0
        public void Constructor_FailureMechanismNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var dikeProfiles = new DikeProfileCollection();

            // Call
            TestDelegate call = () => new DikeProfilesContext(dikeProfiles, null, assessmentSection);

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

            Assert.AreEqual("parentFailureMechanism", paramName);
            mocks.VerifyAll();
        }
        public void UpdateDikeProfilesWithImportedData_CalculationWithSameReference_OnlyReturnsDistinctCalculation()
        {
            // Setup
            DikeProfile affectedProfile     = DikeProfileTestFactory.CreateDikeProfile("Profile to be updated", "ID of updated profile");
            var         affectedCalculation = new GrassCoverErosionInwardsCalculation
            {
                InputParameters =
                {
                    DikeProfile = affectedProfile
                },
                Output = new TestGrassCoverErosionInwardsOutput()
            };

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(affectedCalculation);
            failureMechanism.CalculationsGroup.Children.Add(affectedCalculation);
            DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles;

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

            DikeProfile profileToUpdateFrom = DeepCloneAndModify(affectedProfile);

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                dikeProfiles,
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile
            }, affectedObjects);
        }
        public void UpdateDikeProfilesWithImportedData_DifferentSourcePath_UpdatesSourcePathOfDataCollection()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            DikeProfileCollection targetCollection = failureMechanism.DikeProfiles;

            var          strategy      = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism);
            const string newSourcePath = "some/other/path";

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateDikeProfilesWithImportedData(Enumerable.Empty <DikeProfile>(),
                                                                                                    newSourcePath);

            // Assert
            Assert.AreEqual(newSourcePath, targetCollection.SourcePath);
            CollectionAssert.AreEqual(new IObservable[]
            {
                targetCollection
            }, affectedObjects);
            CollectionAssert.IsEmpty(targetCollection);
        }
        public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAssignedToRemovedProfile_UpdatesCalculation()
        {
            // Setup
            DikeProfile profileToBeRemoved = DikeProfileTestFactory.CreateDikeProfile("Removed profile", "removed profile ID");
            var         calculation        = new GrassCoverErosionInwardsCalculation
            {
                InputParameters =
                {
                    DikeProfile = profileToBeRemoved
                },
                Output = new TestGrassCoverErosionInwardsOutput()
            };

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculation);
            DikeProfileCollection dikeProfileCollection = failureMechanism.DikeProfiles;

            dikeProfileCollection.AddRange(new[]
            {
                profileToBeRemoved
            }, sourceFilePath);

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.DikeProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                dikeProfileCollection,
                calculation,
                calculation.InputParameters
            }, affectedObjects);
        }
Пример #19
0
        public void Import_OneDikeProfileLocationNotCloseEnoughToReferenceLine_FalseAndLogError()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

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

            var referencePoints = new List <Point2D>
            {
                new Point2D(131223.2, 548393.4),
                new Point2D(133854.3, 545323.1),
                new Point2D(135561.0, 541920.3),
                new Point2D(136432.1, 538235.2),
                new Point2D(146039.4, 533920.2)
            };
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(referencePoints);

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

            var importResult = false;

            // Call
            Action call = () => importResult = dikeProfilesImporter.Import();

            // Assert
            const string expectedMessage = "Fout bij het lezen van profiellocatie 5. De profiellocatie met " +
                                           "ID 'profiel005' ligt niet op de referentielijn.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 1);
            Assert.IsFalse(importResult);
            CollectionAssert.IsEmpty(dikeProfiles);
        }
Пример #20
0
        public void CreateInstance_WithContext_NewPropertiesWithInputContextAsData()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            var collection = new DikeProfileCollection();
            var context    = new DikeProfilesContext(collection, failureMechanism, assessmentSection);

            // Call
            IObjectProperties objectProperties = info.CreateInstance(context);

            // Assert
            Assert.IsInstanceOf <DikeProfileCollectionProperties>(objectProperties);
            Assert.AreSame(collection, objectProperties.Data);

            mocks.VerifyAll();
        }
        public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataFullyOverlaps_UpdatesTargetCollection()
        {
            // Setup
            const string id = "Just an ID";
            DikeProfile  targetDikeProfile = DikeProfileTestFactory.CreateDikeProfile("name", id);

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

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

            DikeProfile readDikeProfile = DeepCloneAndModify(targetDikeProfile);

            DikeProfile[] readDikeProfiles =
            {
                readDikeProfile
            };

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            Assert.AreEqual(1, targetCollection.Count);
            Assert.AreSame(targetDikeProfile, targetCollection[0]);
            AssertDikeProfile(readDikeProfile, targetDikeProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                targetCollection,
                targetDikeProfile
            }, affectedObjects);
        }
        public void Constructor_WithData_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            var collection = new DikeProfileCollection();

            // Call
            var properties = new DikeProfileCollectionProperties(collection);

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

            Assert.AreEqual(1, dynamicProperties.Count);

            PropertyDescriptor dikeProfileCollectionSourcePathProperty = dynamicProperties[0];

            Assert.IsNotNull(dikeProfileCollectionSourcePathProperty);
            Assert.IsTrue(dikeProfileCollectionSourcePathProperty.IsReadOnly);
            Assert.AreEqual("Algemeen", dikeProfileCollectionSourcePathProperty.Category);
            Assert.AreEqual("Bronlocatie", dikeProfileCollectionSourcePathProperty.DisplayName);
            Assert.AreEqual(
                "De locatie van het bestand waaruit de dijkprofielen zijn geïmporteerd.",
                dikeProfileCollectionSourcePathProperty.Description);
        }
        public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataHasNoOverlap_UpdatesTargetCollection()
        {
            // Setup
            const string currentDikeProfileId = "Current ID";
            DikeProfile  targetDikeProfile    = DikeProfileTestFactory.CreateDikeProfile(string.Empty, currentDikeProfileId);

            const string readDikeProfileId = "Read ID";
            DikeProfile  readDikeProfile   = DikeProfileTestFactory.CreateDikeProfile(string.Empty, readDikeProfileId);

            DikeProfile[] readDikeProfiles =
            {
                readDikeProfile
            };

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

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

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            Assert.AreEqual(1, dikeProfiles.Count);
            Assert.AreSame(readDikeProfile, dikeProfiles[0]);

            CollectionAssert.AreEquivalent(new[]
            {
                dikeProfiles
            }, affectedObjects);
        }
        public void UpdateDikeProfilesWithImportedData_CollectionEmptyAndImportedCollectionNotEmpty_AddsNewDikeProfiles()
        {
            // Setup
            DikeProfile[] importedDikeProfiles =
            {
                DikeProfileTestFactory.CreateDikeProfile()
            };

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
            var strategy         = new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(failureMechanism);

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

            // Assert
            DikeProfileCollection actualCollection = failureMechanism.DikeProfiles;

            CollectionAssert.AreEqual(importedDikeProfiles, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
        }
        public void UpdateDikeProfilesWithImportedData_CalculationWithOutputAndForeshoreProfileUpdatedWithProfileWithoutGeometry_UpdatesCalculation()
        {
            // Setup
            const string          id       = "profile ID";
            IEnumerable <Point2D> geometry = new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4)
            };

            DikeProfile affectedProfile     = DikeProfileTestFactory.CreateDikeProfile(geometry, id);
            var         affectedCalculation = new GrassCoverErosionInwardsCalculation
            {
                InputParameters =
                {
                    DikeProfile = affectedProfile
                },
                Output = new TestGrassCoverErosionInwardsOutput()
            };

            affectedCalculation.InputParameters.UseForeshore = true;

            DikeProfile profileToUpdateFrom = DikeProfileTestFactory.CreateDikeProfile(Enumerable.Empty <Point2D>(), id);

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism
            {
                CalculationsGroup =
                {
                    Children =
                    {
                        affectedCalculation
                    }
                }
            };

            DikeProfileCollection dikeProfiles = failureMechanism.DikeProfiles;

            DikeProfile[] originalDikeProfiles =
            {
                affectedProfile
            };
            dikeProfiles.AddRange(originalDikeProfiles, sourceFilePath);

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.IsFalse(affectedCalculation.InputParameters.UseForeshore);
            AssertDikeProfile(affectedProfile, profileToUpdateFrom);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                affectedProfile,
                dikeProfiles
            }, affectedObjects);
        }
        public void UpdateDikeProfilesWithImportedData_MultipleCalculationWithAssignedProfileOneRemovedProfile_OnlyUpdatesCalculationWithRemovedProfile()
        {
            // Setup
            DikeProfile removedProfile      = DikeProfileTestFactory.CreateDikeProfile("Profile to be removed", "ID of removed profile");
            var         affectedCalculation = new GrassCoverErosionInwardsCalculation
            {
                InputParameters =
                {
                    DikeProfile = removedProfile
                },
                Output = new TestGrassCoverErosionInwardsOutput()
            };

            const string unaffectedProfileName = "Unaffected Profile";
            const string unaffectedProfileId   = "unaffected profile Id";
            DikeProfile  unaffectedProfile     = DikeProfileTestFactory.CreateDikeProfile(unaffectedProfileName, unaffectedProfileId);
            var          unaffectedCalculation = new GrassCoverErosionInwardsCalculation
            {
                InputParameters =
                {
                    DikeProfile = unaffectedProfile
                },
                Output = new TestGrassCoverErosionInwardsOutput()
            };

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

            dikeProfiles.AddRange(new[]
            {
                removedProfile,
                unaffectedProfile
            }, sourceFilePath);
            failureMechanism.CalculationsGroup.Children.Add(affectedCalculation);
            failureMechanism.CalculationsGroup.Children.Add(unaffectedCalculation);

            DikeProfile importedUnaffectedProfile = DikeProfileTestFactory.CreateDikeProfile(unaffectedProfileName, unaffectedProfileId);

            var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism);

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

            // Assert
            Assert.IsTrue(unaffectedCalculation.HasOutput);
            DikeProfile inputParametersUnaffectedDikeProfile = unaffectedCalculation.InputParameters.DikeProfile;

            Assert.AreSame(unaffectedProfile, inputParametersUnaffectedDikeProfile);
            AssertDikeProfile(unaffectedProfile, inputParametersUnaffectedDikeProfile);

            Assert.IsFalse(affectedCalculation.HasOutput);
            Assert.IsNull(affectedCalculation.InputParameters.DikeProfile);

            CollectionAssert.AreEquivalent(new IObservable[]
            {
                affectedCalculation,
                affectedCalculation.InputParameters,
                dikeProfiles
            }, affectedObjects);
        }