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_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 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 Constructor_CreatesNewInstance() { // Call var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Assert Assert.IsInstanceOf <UpdateDataStrategyBase <DikeProfile, GrassCoverErosionInwardsFailureMechanism> >(strategy); Assert.IsInstanceOf <IDikeProfileUpdateDataStrategy>(strategy); }
public void UpdateDikeProfilesWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() { // Setup var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Call void Call() => strategy.UpdateDikeProfilesWithImportedData(Enumerable.Empty <DikeProfile>(), null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("sourceFilePath", exception.ParamName); }
public void UpdateDikeProfilesWithImportedData_ImportedDataCollectionNull_ThrowsArgumentNullException() { // Setup var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); // Call void Call() => strategy.UpdateDikeProfilesWithImportedData(null, string.Empty); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("importedDataCollection", exception.ParamName); }
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); }