Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/FileImporters/ClosingStructureUpdateDataStrategyTest.cs =================================================================== diff -u -r89541dc8ef2d8b38372169ddecc0b37e9b225f6d -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/FileImporters/ClosingStructureUpdateDataStrategyTest.cs (.../ClosingStructureUpdateDataStrategyTest.cs) (revision 89541dc8ef2d8b38372169ddecc0b37e9b225f6d) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/FileImporters/ClosingStructureUpdateDataStrategyTest.cs (.../ClosingStructureUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -117,23 +117,6 @@ } [Test] - public void UpdateStructuresWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var targetCollection = new StructureCollection(); - var strategy = new ClosingStructureUpdateDataStrategy(new ClosingStructuresFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(targetCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(targetCollection); - CollectionAssert.IsEmpty(affectedObjects); - } - - [Test] public void UpdateStructuresWithImportedData_WithoutCurrentStructuresAndReadStructuresHaveDuplicateNames_ThrowsUpdateDataException() { // Setup @@ -198,32 +181,124 @@ } [Test] - public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedDataEmpty_StructuresRemoved() + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup + var targetStructure = new TestClosingStructure("target id"); + var failureMechanism = new ClosingStructuresFailureMechanism(); StructureCollection structures = failureMechanism.ClosingStructures; structures.AddRange(new[] { - new TestClosingStructure("id", "name"), - new TestClosingStructure("other id", "other name") + targetStructure }, sourceFilePath); + var readStructure = new TestClosingStructure("read id"); + var importedStructures = new[] + { + readStructure + }; + var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData( - structures, Enumerable.Empty(), sourceFilePath); + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, + sourceFilePath); // Assert - CollectionAssert.IsEmpty(structures); - CollectionAssert.AreEqual(new[] + CollectionAssert.AreEqual(importedStructures, structures); + Assert.AreSame(readStructure, structures[0]); + + CollectionAssert.AreEquivalent(new IObservable[] { structures }, affectedObjects); } [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasFullOverlap_UpdatesTargetCollection() + { + // Setup + const string commonId = "common id"; + var targetStructure = new TestClosingStructure(commonId, "old name"); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.ClosingStructures; + structures.AddRange(new[] + { + targetStructure + }, sourceFilePath); + + var readStructure = new TestClosingStructure(commonId, "new name"); + var importedStructures = new[] + { + readStructure + }; + + var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); + + // Assert + Assert.AreEqual(1, structures.Count); + Assert.AreSame(targetStructure, structures[0]); + AssertClosingStructures(readStructure, targetStructure); + + CollectionAssert.AreEquivalent(new IObservable[] + { + targetStructure, + structures + }, affectedObjects); + } + + [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() + { + // Setup + const string commonId = "common id"; + var updatedStructure = new TestClosingStructure(commonId, "old name"); + var removedStructure = new TestClosingStructure("removed id"); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.ClosingStructures; + structures.AddRange(new[] + { + removedStructure, + updatedStructure + }, sourceFilePath); + + var structureToUpdateFrom = new TestClosingStructure(commonId, "new name"); + var addedStructure = new TestClosingStructure("added id"); + var importedStructures = new[] + { + structureToUpdateFrom, + addedStructure + }; + + var strategy = new ClosingStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); + + // Assert + Assert.AreEqual(2, structures.Count); + Assert.AreSame(updatedStructure, structures[0]); + AssertClosingStructures(structureToUpdateFrom, updatedStructure); + + Assert.AreSame(addedStructure, structures[1]); + + CollectionAssert.AreEquivalent(new IObservable[] + { + updatedStructure, + structures + }, affectedObjects); + } + + [Test] [TestCaseSource(typeof(ClosingStructurePermutationHelper), nameof(ClosingStructurePermutationHelper.DifferentClosingStructuresWithSameId), new object[] Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs =================================================================== diff -u -r89541dc8ef2d8b38372169ddecc0b37e9b225f6d -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs (.../GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs) (revision 89541dc8ef2d8b38372169ddecc0b37e9b225f6d) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/FileImporters/GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs (.../GrassCoverErosionInwardsDikeProfileUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -116,23 +116,6 @@ } [Test] - public void UpdateDikeProfilesWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var targetCollection = new DikeProfileCollection(); - var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(targetCollection); - CollectionAssert.IsEmpty(affectedObjects); - } - - [Test] public void UpdateDikeProfilesWithImportedData_DikeProfilePropertiesChanged_UpdateRelevantProperties() { // Setup @@ -188,34 +171,6 @@ } [Test] - public void UpdateDikeProfilesWithImportedData_CurrentCollectionEmptyAndImportedCollectionNotEmpty_NewProfilesAdded() - { - // Setup - var dikeProfileOne = new TestDikeProfile(string.Empty, "ID One"); - var dikeProfileTwo = new TestDikeProfile(string.Empty, "ID Two"); - var importedDataCollection = new[] - { - dikeProfileOne, - dikeProfileTwo - }; - - var targetCollection = new DikeProfileCollection(); - var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(new GrassCoverErosionInwardsFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(targetCollection, - importedDataCollection, - sourceFilePath); - - // Assert - CollectionAssert.AreEqual(importedDataCollection, targetCollection); - CollectionAssert.AreEqual(new IObservable[] - { - targetCollection - }, affectedObjects); - } - - [Test] public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfileAndImportedMultipleDikeProfilesWithSameId_ThrowsUpdateException() { // Setup @@ -252,34 +207,6 @@ } [Test] - public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataEmpty_RemovesDikeProfiles() - { - // Setup - var dikeProfile = new TestDikeProfile(); - - var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - DikeProfileCollection dikeProfileCollection = failureMechanism.DikeProfiles; - dikeProfileCollection.AddRange(new[] - { - dikeProfile - }, sourceFilePath); - - var strategy = new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(failureMechanism); - - // Call - IEnumerable affectedObjects = strategy.UpdateDikeProfilesWithImportedData(dikeProfileCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(dikeProfileCollection); - CollectionAssert.AreEqual(new[] - { - dikeProfileCollection - }, affectedObjects); - } - - [Test] public void UpdateDikeProfilesWithImportedData_WithCurrentDikeProfilesAndImportedDataFullyOverlaps_UpdatesTargetCollection() { // Setup Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs =================================================================== diff -u -r89541dc8ef2d8b38372169ddecc0b37e9b225f6d -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision 89541dc8ef2d8b38372169ddecc0b37e9b225f6d) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/FileImporters/HeightStructureUpdateDataStrategyTest.cs (.../HeightStructureUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -117,23 +117,6 @@ } [Test] - public void UpdateStructuresWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var targetCollection = new StructureCollection(); - var strategy = new HeightStructureUpdateDataStrategy(new HeightStructuresFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(targetCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(targetCollection); - CollectionAssert.IsEmpty(affectedObjects); - } - - [Test] public void UpdateStructuresWithImportedData_WithoutCurrentStructuresAndReadStructuresHaveDuplicateIds_ThrowsUpdateDataException() { // Setup @@ -198,32 +181,124 @@ } [Test] - public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedDataEmpty_StructuresRemoved() + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() { // Setup + var targetStructure = new TestHeightStructure("target id"); + var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection structures = failureMechanism.HeightStructures; structures.AddRange(new[] { - new TestHeightStructure("id", "name"), - new TestHeightStructure("other id", "other name") + targetStructure }, sourceFilePath); + var readStructure = new TestHeightStructure("read id"); + var importedStructures = new[] + { + readStructure + }; + var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData( - structures, Enumerable.Empty(), sourceFilePath); + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, + sourceFilePath); // Assert - CollectionAssert.IsEmpty(structures); - CollectionAssert.AreEqual(new[] + CollectionAssert.AreEqual(importedStructures, structures); + Assert.AreSame(readStructure, structures[0]); + + CollectionAssert.AreEquivalent(new IObservable[] { structures }, affectedObjects); } [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasFullOverlap_UpdatesTargetCollection() + { + // Setup + const string commonId = "common id"; + var targetStructure = new TestHeightStructure(commonId, "old name"); + + var failureMechanism = new HeightStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.HeightStructures; + structures.AddRange(new[] + { + targetStructure + }, sourceFilePath); + + var readStructure = new TestHeightStructure(commonId, "new name"); + var importedStructures = new[] + { + readStructure + }; + + var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); + + // Assert + Assert.AreEqual(1, structures.Count); + Assert.AreSame(targetStructure, structures[0]); + AssertHeightStructures(readStructure, targetStructure); + + CollectionAssert.AreEquivalent(new IObservable[] + { + targetStructure, + structures + }, affectedObjects); + } + + [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() + { + // Setup + const string commonId = "common id"; + var updatedStructure = new TestHeightStructure(commonId, "old name"); + var removedStructure = new TestHeightStructure("removed id"); + + var failureMechanism = new HeightStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.HeightStructures; + structures.AddRange(new[] + { + removedStructure, + updatedStructure + }, sourceFilePath); + + var structureToUpdateFrom = new TestHeightStructure(commonId, "new name"); + var addedStructure = new TestHeightStructure("added id"); + var importedStructures = new[] + { + structureToUpdateFrom, + addedStructure + }; + + var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); + + // Assert + Assert.AreEqual(2, structures.Count); + Assert.AreSame(updatedStructure, structures[0]); + AssertHeightStructures(structureToUpdateFrom, updatedStructure); + + Assert.AreSame(addedStructure, structures[1]); + + CollectionAssert.AreEquivalent(new IObservable[] + { + updatedStructure, + structures + }, affectedObjects); + } + + [Test] [TestCaseSource(typeof(HeightStructurePermutationHelper), nameof(HeightStructurePermutationHelper.DifferentHeightStructuresWithSameId), new object[] Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs =================================================================== diff -u -rd85d1dec2d45f1f6be910b1e78c5837a0c4de837 -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs (.../ForeshoreProfileUpdateDataStrategyTest.cs) (revision d85d1dec2d45f1f6be910b1e78c5837a0c4de837) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileUpdateDataStrategyTest.cs (.../ForeshoreProfileUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -191,26 +191,8 @@ Assert.AreSame(profileToBeUpdated, targetCollection[0]); AssertForeshoreProfile(readForeshoreProfile, profileToBeUpdated); } - + [Test] - public void UpdateForeshoreProfilesWithImportedData_CurrentAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var strategy = new ForeshoreProfileUpdateDataStrategy(new TestFailureMechanism()); - var foreshoreProfiles = new ForeshoreProfileCollection(); - - // Call - IEnumerable affectedObjects = - strategy.UpdateForeshoreProfilesWithImportedData(foreshoreProfiles, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(affectedObjects); - CollectionAssert.IsEmpty(foreshoreProfiles); - } - - [Test] public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionEmptyImportedCollectionContainDuplicateIDs_ThrowUpdateException() { // Setup @@ -236,61 +218,8 @@ CollectionAssert.IsEmpty(foreshoreProfiles); } - + [Test] - public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionEmptyAndImportedCollectionNotEmpty_NewProfilesAdded() - { - // Setup - var strategy = new ForeshoreProfileUpdateDataStrategy(new TestFailureMechanism()); - var foreshoreProfiles = new ForeshoreProfileCollection(); - - var importedForeshoreProfiles = new[] - { - new TestForeshoreProfile("Name A", "ID A"), - new TestForeshoreProfile("Name B", "ID B") - }; - - // Call - IEnumerable affectedObjects = - strategy.UpdateForeshoreProfilesWithImportedData(foreshoreProfiles, - importedForeshoreProfiles, - sourceFilePath); - - // Assert - CollectionAssert.AreEqual(new[] - { - foreshoreProfiles - }, affectedObjects); - CollectionAssert.AreEqual(importedForeshoreProfiles, foreshoreProfiles); - } - - [Test] - public void UpdateForeshoreProfilesWithImportedData_CurrentCollectionNotEmptyAndImportedCollectionEmpty_RemovesProfiles() - { - // Setup - var strategy = new ForeshoreProfileUpdateDataStrategy(new TestFailureMechanism()); - var foreshoreProfiles = new ForeshoreProfileCollection(); - foreshoreProfiles.AddRange(new[] - { - new TestForeshoreProfile("Name A", "ID A"), - new TestForeshoreProfile("Name B", "ID B") - }, sourceFilePath); - - // Call - IEnumerable affectedObjects = - strategy.UpdateForeshoreProfilesWithImportedData(foreshoreProfiles, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.AreEqual(new[] - { - foreshoreProfiles - }, affectedObjects); - CollectionAssert.IsEmpty(foreshoreProfiles); - } - - [Test] public void UpdateForeshoreProfilesWithImportedData_WithCurrentCollectionNotEmptyAndImportedCollectionHasProfilesWithSameId_ThrowsUpdateException() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs =================================================================== diff -u -r89541dc8ef2d8b38372169ddecc0b37e9b225f6d -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 89541dc8ef2d8b38372169ddecc0b37e9b225f6d) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -111,23 +111,6 @@ } [Test] - public void UpdateSurfaceLinesWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var targetCollection = new RingtoetsPipingSurfaceLineCollection(); - var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(new PipingFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(targetCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(targetCollection); - CollectionAssert.IsEmpty(affectedObjects); - } - - [Test] public void UpdateSurfaceLinesWithImportedData_OnlyGeometryChanged_UpdatesGeometryOnly() { // Setup @@ -307,41 +290,6 @@ } [Test] - public void UpdateSurfaceLinesWithImportedData_CurrentCollectionEmptyAndImportedDataNotEmpty_NewSurfaceLinesAdded() - { - // Setup - const string collectionSurfaceLineOneName = "Name A"; - const string collectionSurfaceLineTwoName = "Name B"; - - var importedSurfaceLines = new[] - { - new RingtoetsPipingSurfaceLine - { - Name = collectionSurfaceLineOneName - }, - new RingtoetsPipingSurfaceLine - { - Name = collectionSurfaceLineTwoName - } - }; - - var targetCollection = new RingtoetsPipingSurfaceLineCollection(); - var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(new PipingFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(targetCollection, - importedSurfaceLines, - sourceFilePath); - - // Assert - CollectionAssert.AreEqual(importedSurfaceLines, targetCollection); - CollectionAssert.AreEqual(new[] - { - targetCollection - }, affectedObjects); - } - - [Test] public void UpdateSurfaceLinesWithImportedData_WithCurrentLinesAndImportedMultipleLinesWithSameNames_ThrowsUpdateDataException() { // Setup @@ -395,39 +343,8 @@ Assert.AreEqual(expectedSurfaceLine.Name, actualSurfaceLine.Name); CollectionAssert.AreEqual(expectedGeometry, actualSurfaceLine.Points); } - + [Test] - public void UpdateSurfaceLinesWithImportedData_WithCurrentLinesAndImportedDataEmpty_SurfaceLinesRemoved() - { - // Setup - const string collectionSurfaceLineName = "Name A"; - - var failureMechanism = new PipingFailureMechanism(); - RingtoetsPipingSurfaceLineCollection surfaceLineCollection = failureMechanism.SurfaceLines; - surfaceLineCollection.AddRange(new[] - { - new RingtoetsPipingSurfaceLine - { - Name = collectionSurfaceLineName - } - }, sourceFilePath); - - var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); - - // Call - IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(surfaceLineCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(surfaceLineCollection); - CollectionAssert.AreEqual(new[] - { - surfaceLineCollection - }, affectedObjects); - } - - [Test] public void UpdateSurfaceLinesWithImportedData_WithCurrentCollectionNotEmptyAndImportedDataHasFullOverlap_UpdatesTargetCollection() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs =================================================================== diff -u -r89541dc8ef2d8b38372169ddecc0b37e9b225f6d -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision 89541dc8ef2d8b38372169ddecc0b37e9b225f6d) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelUpdateDataStrategyTest.cs (.../StochasticSoilModelUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -175,56 +175,6 @@ } [Test] - public void UpdateModelWithImportedData_WithoutCurrentModelAndModelsImported_NewModelsAdded() - { - // Setup - var importedStochasticSoilModels = new[] - { - new TestStochasticSoilModel("A"), - new TestStochasticSoilModel("B") - }; - var strategy = new StochasticSoilModelUpdateDataStrategy(new PipingFailureMechanism()); - var targetCollection = new StochasticSoilModelCollection(); - - // Call - IEnumerable affectedObjects = strategy.UpdateModelWithImportedData(targetCollection, importedStochasticSoilModels, "path"); - - // Assert - CollectionAssert.AreEqual(importedStochasticSoilModels, targetCollection); - CollectionAssert.AreEqual(new[] - { - targetCollection - }, affectedObjects); - } - - [Test] - public void UpdateModelWithImportedData_WithCurrentModelsAndImportedDataEmpty_ModelsRemoved() - { - // Setup - var failureMechanism = new PipingFailureMechanism(); - StochasticSoilModelCollection stochasticSoilModelCollection = failureMechanism.StochasticSoilModels; - stochasticSoilModelCollection.AddRange(new[] - { - new TestStochasticSoilModel("A"), - new TestStochasticSoilModel("B") - }, sourceFilePath); - - var strategy = new StochasticSoilModelUpdateDataStrategy(failureMechanism); - - // Call - IEnumerable affectedObjects = strategy.UpdateModelWithImportedData(stochasticSoilModelCollection, - new List(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(stochasticSoilModelCollection); - CollectionAssert.AreEquivalent(new[] - { - stochasticSoilModelCollection - }, affectedObjects); - } - - [Test] public void UpdateModelWithImportedData_WithCurrentModelAndImportedModelWithOtherName_ModelReplaced() { // Setup Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/FileImporters/StabilityPointStructuresUpdateDataStrategyTest.cs =================================================================== diff -u -r7326c5c94201fa88fcfa4c73215f79088fcfee42 -r32ef1a284c06beac64572d830b50f291e390a66d --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/FileImporters/StabilityPointStructuresUpdateDataStrategyTest.cs (.../StabilityPointStructuresUpdateDataStrategyTest.cs) (revision 7326c5c94201fa88fcfa4c73215f79088fcfee42) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/FileImporters/StabilityPointStructuresUpdateDataStrategyTest.cs (.../StabilityPointStructuresUpdateDataStrategyTest.cs) (revision 32ef1a284c06beac64572d830b50f291e390a66d) @@ -67,23 +67,6 @@ } [Test] - public void UpdateStructuresWithImportedData_CurrentCollectionAndImportedCollectionEmpty_DoesNothing() - { - // Setup - var targetCollection = new StructureCollection(); - var strategy = new StabilityPointStructureUpdateDataStrategy(new StabilityPointStructuresFailureMechanism()); - - // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(targetCollection, - Enumerable.Empty(), - sourceFilePath); - - // Assert - CollectionAssert.IsEmpty(targetCollection); - CollectionAssert.IsEmpty(affectedObjects); - } - - [Test] public void UpdateStructuresWithImportedData_WithoutCurrentStructuresAndReadStructuresHaveDuplicateNames_ThrowsUpdateDataException() { // Setup @@ -110,34 +93,126 @@ CollectionAssert.IsEmpty(targetCollection); } + + [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasNoOverlap_UpdatesTargetCollection() + { + // Setup + var targetStructure = new TestStabilityPointStructure("target id"); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.StabilityPointStructures; + structures.AddRange(new[] + { + targetStructure + }, sourceFilePath); + + var readStructure = new TestStabilityPointStructure("read id"); + var importedStructures = new[] + { + readStructure + }; + + var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, + sourceFilePath); + + // Assert + CollectionAssert.AreEqual(importedStructures, structures); + Assert.AreSame(readStructure, structures[0]); + + CollectionAssert.AreEquivalent(new IObservable[] + { + structures + }, affectedObjects); + } + [Test] - public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedDataEmpty_StructuresRemoved() + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasFullOverlap_UpdatesTargetCollection() { // Setup + const string commonId = "common id"; + var targetStructure = new TestStabilityPointStructure(commonId, "old name"); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); StructureCollection structures = failureMechanism.StabilityPointStructures; structures.AddRange(new[] { - new TestStabilityPointStructure("id", "name"), - new TestStabilityPointStructure("other id", "other name") + targetStructure }, sourceFilePath); + var readStructure = new TestStabilityPointStructure(commonId, "new name"); + var importedStructures = new[] + { + readStructure + }; + var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); // Call - IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData( - structures, Enumerable.Empty(), sourceFilePath); + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); // Assert - CollectionAssert.IsEmpty(structures); - CollectionAssert.AreEqual(new[] + Assert.AreEqual(1, structures.Count); + Assert.AreSame(targetStructure, structures[0]); + AssertStabilityPointStructure(readStructure, targetStructure); + + CollectionAssert.AreEquivalent(new IObservable[] { + targetStructure, structures }, affectedObjects); } [Test] + public void UpdateStructuresWithImportedData_WithCurrentStructuresAndImportedHasPartialOverlap_UpdatesTargetCollection() + { + // Setup + const string commonId = "common id"; + var updatedStructure = new TestStabilityPointStructure(commonId, "old name"); + var removedStructure = new TestStabilityPointStructure("removed id"); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + StructureCollection structures = failureMechanism.StabilityPointStructures; + structures.AddRange(new[] + { + removedStructure, + updatedStructure + }, sourceFilePath); + + var structureToUpdateFrom = new TestStabilityPointStructure(commonId, "new name"); + var addedStructure = new TestStabilityPointStructure("added id"); + var importedStructures = new[] + { + structureToUpdateFrom, + addedStructure + }; + + var strategy = new StabilityPointStructureUpdateDataStrategy(failureMechanism); + + // Call + IEnumerable affectedObjects = strategy.UpdateStructuresWithImportedData(structures, + importedStructures, sourceFilePath); + + // Assert + Assert.AreEqual(2, structures.Count); + Assert.AreSame(updatedStructure, structures[0]); + AssertStabilityPointStructure(structureToUpdateFrom, updatedStructure); + + Assert.AreSame(addedStructure, structures[1]); + + CollectionAssert.AreEquivalent(new IObservable[] + { + updatedStructure, + structures + }, affectedObjects); + } + + [Test] [TestCaseSource(typeof(StabilityPointStructurePermutationHelper), nameof(StabilityPointStructurePermutationHelper.DifferentStabilityPointStructuresWithSameId), new object[]