Index: Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs =================================================================== diff -u -raae2ecaacbb094fe66d6a54d6ac4b1e6780b0864 -r66239a42b315209acc4d124200c58d8be1a18195 --- Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs (.../ObservableUniqueItemCollectionWithSourcePath.cs) (revision aae2ecaacbb094fe66d6a54d6ac4b1e6780b0864) +++ Core/Common/src/Core.Common.Base/ObservableUniqueItemCollectionWithSourcePath.cs (.../ObservableUniqueItemCollectionWithSourcePath.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) @@ -31,12 +31,12 @@ /// A collection to store unique elements based on their feature and the source path /// they were imported from. /// - /// The type of elements in the collection. - public abstract class ObservableUniqueItemCollectionWithSourcePath : Observable, IEnumerable - where TObject : class + /// The type of elements in the collection. + public abstract class ObservableUniqueItemCollectionWithSourcePath : Observable, IEnumerable + where TElement : class { - private readonly List collection = new List(); - private readonly Func getUniqueFeature; + private readonly List collection = new List(); + private readonly Func getUniqueFeature; private readonly string typeDescriptor; private readonly string featureDescription; @@ -46,7 +46,7 @@ /// A function to retrieve the unique feature of the items it stores. /// The description of the item that is validated. /// The description of the feature of the item to be validated on. - public ObservableUniqueItemCollectionWithSourcePath(Func getUniqueFeature, + public ObservableUniqueItemCollectionWithSourcePath(Func getUniqueFeature, string typeDescriptor, string featureDescription) { @@ -75,7 +75,7 @@ /// The element at index in the collection. /// Thrown when is not /// between [0, ) - public TObject this[int i] + public TElement this[int i] { get { @@ -104,10 +104,10 @@ /// /// Removes the first occurrence of in the collection. /// - /// The item of type to be removed. + /// The item of type to be removed. /// True if the was successfully removed from the collection; /// False if otherwise or if the was not found in the collection. - public bool Remove(TObject item) + public bool Remove(TElement item) { bool remove = collection.Remove(item); if (remove && Count == 0) @@ -139,7 +139,7 @@ /// an element in is invalid. /// /// - public void AddRange(IEnumerable items, string filePath) + public void AddRange(IEnumerable items, string filePath) { if (items == null) { @@ -159,7 +159,7 @@ collection.AddRange(items); } - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { return collection.GetEnumerator(); } @@ -169,7 +169,7 @@ return GetEnumerator(); } - private void InternalValidateItems(IEnumerable items) + private void InternalValidateItems(IEnumerable items) { if (items.Contains(null)) { @@ -179,23 +179,13 @@ } /// - /// Perform additional validations over . - /// - /// The items to validate. - /// Throw an exception when validation fails. - private void ValidateItems(IEnumerable items) - { - ValidateListOnDuplicateFeature(items); - } - - /// /// Validates the items of an based on their feature. /// /// Thrown when any parameters are null. /// Thrown when a duplicate item was found. - private void ValidateListOnDuplicateFeature(IEnumerable items) + private void ValidateItems(IEnumerable items) { - IEnumerable> duplicateItems = + IEnumerable> duplicateItems = items.GroupBy(getUniqueFeature) .Where(group => group.Count() > 1); Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs =================================================================== diff -u -raae2ecaacbb094fe66d6a54d6ac4b1e6780b0864 -r66239a42b315209acc4d124200c58d8be1a18195 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision aae2ecaacbb094fe66d6a54d6ac4b1e6780b0864) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (.../ReplaceDataStrategyBaseTest.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) @@ -98,7 +98,7 @@ } [Test] - public void ReplaceData_CallsClearData_ReturnsTrue() + public void ReplaceData_Always_CallsClearData() { // Setup var strategy = new ConcreteStrategyClass(new TestFailureMechanism()); @@ -205,22 +205,26 @@ } [Test] - public void ReplaceData_ClearDataCalled_ReturnsExpectedItems() + public void ReplaceData_Always_CalledWithExpectedFailureMechanism() { // Setup var failureMechanism = new TestFailureMechanism(); + var collection = new TestUniqueItemCollection(); var strategy = new ConcreteStrategyClass(failureMechanism); + var expectedObservables = new[] + { + collection + }; + strategy.ClearDataReturnedList = expectedObservables; - var collection = new TestUniqueItemCollection(); - // Call IObservable[] affectedObjects = strategy.ConcreteReplaceData(collection, Enumerable.Empty(), "some/source").ToArray(); // Assert - Assert.AreEqual(1, affectedObjects.Length); - Assert.AreSame(failureMechanism, affectedObjects[0]); + Assert.AreSame(failureMechanism, strategy.ClearDataFailureMechanism); + CollectionAssert.AreEqual(expectedObservables, affectedObjects); } #region Helper classes @@ -229,6 +233,8 @@ { public ConcreteStrategyClass(TestFailureMechanism failureMechanism) : base(failureMechanism) {} public bool IsClearDataCalled { get; private set; } + public TestFailureMechanism ClearDataFailureMechanism { get; private set; } + public IEnumerable ClearDataReturnedList { private get; set; } = Enumerable.Empty(); public IEnumerable ConcreteReplaceData(ObservableUniqueItemCollectionWithSourcePath items, IEnumerable readItems, @@ -240,10 +246,9 @@ protected override IEnumerable ClearData(TestFailureMechanism failureMechanism) { IsClearDataCalled = true; - return new[] - { - failureMechanism - }; + ClearDataFailureMechanism = failureMechanism; + + return ClearDataReturnedList; } } @@ -252,7 +257,6 @@ public TestUniqueItemCollection() : base(item => item.Name, "TestItem", "naam") {} } - private class TestItem { public TestItem(string name) Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs =================================================================== diff -u -r85b53922d59e2d43ef299322b89e0de7ea085c63 -r66239a42b315209acc4d124200c58d8be1a18195 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 85b53922d59e2d43ef299322b89e0de7ea085c63) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/UpdateDataStrategyBaseTest.cs (.../UpdateDataStrategyBaseTest.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) @@ -129,7 +129,7 @@ } [Test] - public void UpdateTargetCollectionData_WithNonEmtpyCollectionAndImportedDataEmpty_ClearsTargetCollection() + public void UpdateTargetCollectionData_WithNonEmptyCollectionAndImportedDataEmpty_ClearsTargetCollection() { // Setup var collection = new TestUniqueItemCollection(); @@ -147,11 +147,10 @@ IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, Enumerable.Empty(), filePath); // Assert - IEnumerable expectedAffectedItems = itemsRemoved.Concat(new IObservable[] + CollectionAssert.AreEquivalent(new IObservable[] { collection - }); - CollectionAssert.AreEquivalent(expectedAffectedItems, affectedObjects); + }, affectedObjects); CollectionAssert.IsEmpty(collection); Assert.AreEqual(filePath, collection.SourcePath); } @@ -164,8 +163,7 @@ const string filePath = "path"; var currentCollection = new[] { - new TestItem("Name A"), - new TestItem("Name B") + new TestItem("Name A") }; collection.AddRange(currentCollection, filePath); @@ -176,12 +174,12 @@ // Assert Assert.IsTrue(strategy.IsRemoveObjectAndDependentDataCalled); + Assert.AreSame(currentCollection[0], strategy.ObjectRemoved); - IEnumerable expectedAffectedObjects = currentCollection.Concat(new IObservable[] + CollectionAssert.AreEquivalent(new IObservable[] { collection - }); - CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + }, affectedObjects); CollectionAssert.IsEmpty(collection); Assert.AreEqual(filePath, collection.SourcePath); } @@ -194,27 +192,25 @@ const string filePath = "path"; var updatedItems = new[] { - new TestItem("Name A"), - new TestItem("Name B") + new TestItem("Name A") }; collection.AddRange(updatedItems, filePath); var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); var importedItems = new[] { - DeepCloneTestItem(updatedItems[0]), - DeepCloneTestItem(updatedItems[1]) + updatedItems[0].DeepClone() }; // Call - IObservable[] affectedObjects = strategy.ConcreteUpdateData(collection, importedItems, filePath).ToArray(); + strategy.ConcreteUpdateData(collection, importedItems, filePath); // Assert Assert.IsTrue(strategy.IsUpdateDataCalled); + Assert.AreSame(updatedItems[0], strategy.ObjectToUpdate); + Assert.AreSame(importedItems[0], strategy.ObjectToUpdateFrom); - IEnumerable expectedAffectedObjects = updatedItems.Concat(importedItems); - CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); CollectionAssert.AreEqual(updatedItems, collection); Assert.AreEqual(filePath, collection.SourcePath); } @@ -290,8 +286,8 @@ var importedItems = new[] { - DeepCloneTestItem(currentCollection[0]), - DeepCloneTestItem(currentCollection[1]) + currentCollection[0].DeepClone(), + currentCollection[1].DeepClone() }; var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); @@ -303,9 +299,7 @@ // Assert CollectionAssert.AreEqual(currentCollection, collection); - - IEnumerable expectedAffectedObjects = currentCollection.Concat(importedItems); - CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + CollectionAssert.IsEmpty(affectedObjects); } [Test] @@ -324,7 +318,7 @@ var importedItems = new[] { - DeepCloneTestItem(currentCollection[0]), + currentCollection[0].DeepClone(), new TestItem("Item Four") }; @@ -342,15 +336,10 @@ importedItems[1] }; CollectionAssert.AreEqual(expectedCollection, collection); - - var expectedAffectedItems = new IObservable[] + CollectionAssert.AreEquivalent(new IObservable[] { - collection, - currentCollection[0], - currentCollection[1], - importedItems[0] - }; - CollectionAssert.AreEquivalent(expectedAffectedItems, affectedObjects); + collection + }, affectedObjects); } [Test] @@ -380,11 +369,10 @@ // Assert CollectionAssert.AreEqual(importedItems, collection); - IEnumerable expectedAffectedObjects = currentCollection .Concat(new IObservable[] - { - collection - }); - CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + CollectionAssert.AreEquivalent(new IObservable[] + { + collection + }, affectedObjects); } [Test] @@ -407,7 +395,11 @@ itemTwo }; - var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()); + var strategy = new ConcreteUpdateDataStrategy(new TestFailureMechanism()) + { + ItemsToUpdate = currentCollection, + ItemsToUpdateFrom = importedItems + }; // Call IEnumerable affectedObjects = strategy.ConcreteUpdateData(collection, @@ -434,6 +426,13 @@ public bool IsUpdateDataCalled { get; private set; } public bool IsRemoveObjectAndDependentDataCalled { get; private set; } + public TestItem ObjectToUpdate { get; private set; } + public TestItem ObjectToUpdateFrom { get; private set; } + public TestItem ObjectRemoved { get; private set; } + + public IEnumerable ItemsToUpdate { private get; set; } = Enumerable.Empty(); + public IEnumerable ItemsToUpdateFrom { private get; set; } = Enumerable.Empty(); + public IEnumerable ConcreteUpdateData(ObservableUniqueItemCollectionWithSourcePath targetCollection, IEnumerable importedDataCollection, string sourceFilePath) @@ -444,22 +443,18 @@ protected override IEnumerable UpdateObjectAndDependentData(TestItem objectToUpdate, TestItem objectToUpdateFrom) { IsUpdateDataCalled = true; + ObjectToUpdateFrom = objectToUpdateFrom; + ObjectToUpdate = objectToUpdate; - return new [] - { - objectToUpdate, - objectToUpdateFrom - }; + return ItemsToUpdate.Concat(ItemsToUpdateFrom); } protected override IEnumerable RemoveObjectAndDependentData(TestItem removedObject) { IsRemoveObjectAndDependentDataCalled = true; + ObjectRemoved = removedObject; - return new [] - { - removedObject - }; + return Enumerable.Empty(); } private class NameComparer : IEqualityComparer @@ -490,16 +485,15 @@ public string Name { get; } + public TestItem DeepClone() + { + return new TestItem(Name); + } + public override string ToString() { return Name; } } - - private static TestItem DeepCloneTestItem(TestItem item) - { - var newItem = new TestItem(item.Name); - return newItem; - } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs =================================================================== diff -u -r85b53922d59e2d43ef299322b89e0de7ea085c63 -r66239a42b315209acc4d124200c58d8be1a18195 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 85b53922d59e2d43ef299322b89e0de7ea085c63) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelUpdateDataStrategy.cs (.../StochasticSoilModelUpdateDataStrategy.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) @@ -106,8 +106,10 @@ StochasticSoilModelProfileDifference difference = modelToUpdate.Update(modelToUpdateFrom); - var affectedObjects = new List(); - affectedObjects.Add(modelToUpdate); + var affectedObjects = new List + { + modelToUpdate + }; foreach (StochasticSoilProfile removedProfile in difference.RemovedProfiles) { affectedObjects.AddRange(PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, removedProfile)); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs =================================================================== diff -u -r85b53922d59e2d43ef299322b89e0de7ea085c63 -r66239a42b315209acc4d124200c58d8be1a18195 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 85b53922d59e2d43ef299322b89e0de7ea085c63) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineUpdateDataStrategyTest.cs) (revision 66239a42b315209acc4d124200c58d8be1a18195) @@ -457,12 +457,12 @@ failureMechanism.CalculationsGroup.Children.Add(calculation); RingtoetsPipingSurfaceLineCollection surfaceLineCollection = failureMechanism.SurfaceLines; surfaceLineCollection.AddRange(new[] -{ + { surfaceLine }, sourceFilePath); var strategy = new RingtoetsPipingSurfaceLineUpdateDataStrategy(failureMechanism); - + // Call IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(surfaceLineCollection, Enumerable.Empty(), @@ -647,7 +647,6 @@ calculationInput }, affectedObjects); Assert.AreSame(surfaceLine, calculationInput.SurfaceLine); - Assert.AreSame(surfaceLine, calculationInput.SurfaceLine); CollectionAssert.AreEqual(importedSurfaceLine.Points, surfaceLine.Points); Assert.AreEqual(soilModels[0], calculationInput.StochasticSoilModel); }