コード例 #1
0
        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();
        }
        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);
        }
コード例 #3
0
        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();
            }
        }
        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_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]);
        }
コード例 #6
0
        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);
        }
        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_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);
        }
        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 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_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);
        }