Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj
===================================================================
diff -u -r31012b85637f7fcf6b28f498fc996edcda2eb505 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 31012b85637f7fcf6b28f498fc996edcda2eb505)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -99,6 +99,7 @@
+
Index: Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/UpdateDataStrategies/ReplaceDataStrategyBase.cs (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -0,0 +1,112 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using Core.Common.Base;
+using Ringtoets.Common.Data.FailureMechanism;
+
+namespace Ringtoets.Common.Data.UpdateDataStrategies
+{
+ ///
+ /// Base class of the replace strategy algorithm to replace data from a
+ /// target collection with the data that was imported.
+ ///
+ /// The target data type.
+ /// The feature of the target data that should be validated on for the uniqueness of elements.
+ /// The failure mechanism in which the target collection should be updated.
+ public abstract class ReplaceDataStrategyBase
+ where TTargetData : class
+ where TFeature : class
+ where TFailureMechanism : IFailureMechanism
+ {
+ private readonly TFailureMechanism failureMechanism;
+
+ ///
+ /// Initializes a
+ ///
+ /// The failure mechanism in which the target collection should be updated.
+ /// Thrown when is null
+ protected ReplaceDataStrategyBase(TFailureMechanism failureMechanism)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ this.failureMechanism = failureMechanism;
+ }
+
+ ///
+ /// Clears all the dependent data of the target items that are contained within
+ /// the .
+ ///
+ /// The failure mechanism in which the target collection resides.
+ /// A with all the items that are affected within the failure mechanism
+ /// after clearing all the within the target collection.
+ protected abstract IEnumerable ClearData(TFailureMechanism failureMechanism);
+
+ ///
+ /// Replaces the data of the with the imported data in .
+ ///
+ /// The collection that needs to be updated.
+ /// The data that was imported.
+ /// The source file path where the imported data comes from.
+ /// An with affected objects.
+ /// Thrown when any of the input parameters are null.
+ /// Thrown when:
+ ///
+ /// - contains null items.
+ /// - contains duplicate items.
+ /// - is not a valid file path
+ ///
+ protected IEnumerable ReplaceTargetCollectionWithImportedData(
+ ObservableUniqueItemCollectionWithSourcePath targetCollection,
+ IEnumerable importedDataCollection,
+ string sourceFilePath)
+ {
+ if (targetCollection == null)
+ {
+ throw new ArgumentNullException(nameof(targetCollection));
+ }
+ if (importedDataCollection == null)
+ {
+ throw new ArgumentNullException(nameof(importedDataCollection));
+ }
+ if (sourceFilePath == null)
+ {
+ throw new ArgumentNullException(nameof(sourceFilePath));
+ }
+
+ var affectedObjects = new List();
+ affectedObjects.AddRange(ClearData(failureMechanism));
+ AddData(targetCollection, importedDataCollection, sourceFilePath);
+
+ return affectedObjects;
+ }
+
+ private static void AddData(ObservableUniqueItemCollectionWithSourcePath targetCollection,
+ IEnumerable readData, string sourceFilePath)
+ {
+ targetCollection.AddRange(readData, sourceFilePath);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj
===================================================================
diff -u -r31012b85637f7fcf6b28f498fc996edcda2eb505 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 31012b85637f7fcf6b28f498fc996edcda2eb505)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -94,6 +94,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/UpdateDataStrategies/ReplaceDataStrategyBaseTest.cs (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -0,0 +1,256 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Core.Common.Base;
+using NUnit.Framework;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.Common.Data.UpdateDataStrategies;
+
+namespace Ringtoets.Common.Data.Test.UpdateDataStrategies
+{
+ [TestFixture]
+ public class ReplaceDataStrategyBaseTest
+ {
+ private const string typeDescriptor = "TestItem";
+ private const string featureDescription = "Name";
+ private readonly Func getUniqueFeature = item => item.Name;
+
+ [Test]
+ public void DefaultConstructor_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new ConcreteStrategyClass(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("failureMechanism", paramName);
+ }
+
+ [Test]
+ public void DefaultConstructor_FailureMechanisNotNull_DoesNotThrowException()
+ {
+ // Call
+ TestDelegate call = () => new ConcreteStrategyClass(new TestFailureMechanism());
+
+ // Assert
+ Assert.DoesNotThrow(call);
+ }
+
+ [Test]
+ public void ReplaceData_TargetCollectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(null, Enumerable.Empty(), string.Empty);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("targetCollection", paramName);
+ }
+
+ [Test]
+ public void ReplaceData_ImportedDataCollectionNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(collection, null, string.Empty);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("importedDataCollection", paramName);
+ }
+
+ [Test]
+ public void ReplaceData_SourceFilePathNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(collection, Enumerable.Empty(), null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sourceFilePath", paramName);
+ }
+
+ [Test]
+ public void ReplaceData_CallsClearData()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ // Call
+ strategy.ConcreteReplaceData(collection, Enumerable.Empty(), "some/source");
+
+ // Assert
+ Assert.IsTrue(strategy.IsClearDataCalled);
+ }
+
+ [Test]
+ public void ReplaceData_ImportedDataCollectionContainsDuplicateItems_ThrowsArgumentException()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ const string duplicateName = "Item A";
+ var itemsToAdd = new[]
+ {
+ new TestItem(duplicateName),
+ new TestItem(duplicateName)
+ };
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(collection, itemsToAdd, "some/source");
+
+ // Assert
+ CollectionAssert.IsEmpty(collection);
+ var exception = Assert.Throws(call);
+ string expectedMessage = $"{typeDescriptor} moeten een unieke {featureDescription} hebben. Gevonden dubbele elementen: {duplicateName}.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ [Test]
+ public void ReplaceData_ImportedDataCollectionContainsNull_ThrowsArgumentException()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ var itemsToAdd = new[]
+ {
+ new TestItem("Item A"),
+ new TestItem("Item B"),
+ null
+ };
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(collection, itemsToAdd, "some/source");
+
+ // Assert
+ CollectionAssert.IsEmpty(collection);
+ Assert.Throws(call);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ public void ReplaceData_InvalidSourceFilePath_ThrowsArgumentException(string invalidPath)
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ const string duplicateName = "Item A";
+ var itemsToAdd = new[]
+ {
+ new TestItem(duplicateName),
+ new TestItem(duplicateName)
+ };
+
+ // Call
+ TestDelegate call = () => strategy.ConcreteReplaceData(collection, itemsToAdd, invalidPath);
+
+ // Assert
+ CollectionAssert.IsEmpty(collection);
+ Assert.Throws(call);
+ }
+
+ [Test]
+ public void ReplaceData_ImportedDataCollectionAndValidSourcePath_UpdatesTargetCollectionAndSourcePath()
+ {
+ // Setup
+ var strategy = new ConcreteStrategyClass(new TestFailureMechanism());
+ var collection = new ObservableUniqueItemCollectionWithSourcePath(
+ getUniqueFeature, typeDescriptor, featureDescription);
+
+ var itemsToAdd = new[]
+ {
+ new TestItem("Item A"),
+ new TestItem("Item B")
+ };
+
+ const string expectedSourcePath = "some/source";
+
+ // Call
+ strategy.ConcreteReplaceData(collection, itemsToAdd, expectedSourcePath);
+
+ // Assert
+ CollectionAssert.AreEqual(itemsToAdd, collection);
+ Assert.AreEqual(expectedSourcePath, collection.SourcePath);
+ }
+
+ #region Helper classes
+
+ private class ConcreteStrategyClass : ReplaceDataStrategyBase
+ {
+ public ConcreteStrategyClass(TestFailureMechanism failureMechanism) : base(failureMechanism) {}
+ public bool IsClearDataCalled { get; private set; }
+
+ public IEnumerable ConcreteReplaceData(ObservableUniqueItemCollectionWithSourcePath items,
+ IEnumerable readItems,
+ string sourceFilePath)
+ {
+ return ReplaceTargetCollectionWithImportedData(items, readItems, sourceFilePath);
+ }
+
+ protected override IEnumerable ClearData(TestFailureMechanism failureMechanism)
+ {
+ IsClearDataCalled = true;
+ return Enumerable.Empty();
+ }
+ }
+
+ private class TestItem
+ {
+ public TestItem(string name)
+ {
+ Name = name;
+ }
+
+ public string Name { get; }
+
+ public override string ToString()
+ {
+ return Name;
+ }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs
===================================================================
diff -u -r036199c1cde97f98829dc4405169ec327d2a1b95 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategy.cs) (revision 036199c1cde97f98829dc4405169ec327d2a1b95)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategy.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -21,8 +21,8 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using Core.Common.Base;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Importers;
using Ringtoets.Piping.Primitives;
@@ -33,55 +33,37 @@
///
/// Strategy to replace the surface lines with the imported surface lines.
///
- public class RingtoetsPipingSurfaceLineReplaceDataStrategy : ISurfaceLineUpdateDataStrategy
+ public class RingtoetsPipingSurfaceLineReplaceDataStrategy : ReplaceDataStrategyBase,
+ ISurfaceLineUpdateDataStrategy
{
- private readonly PipingFailureMechanism failureMechanism;
-
///
/// Creates a new instance of .
///
/// The failure mechanism in which the surface lines are updated.
- /// Thrown when is null.
- public RingtoetsPipingSurfaceLineReplaceDataStrategy(PipingFailureMechanism failureMechanism)
- {
- if (failureMechanism == null)
- {
- throw new ArgumentNullException(nameof(this.failureMechanism));
- }
+ /// Thrown when is null.
+ public RingtoetsPipingSurfaceLineReplaceDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism) {}
- this.failureMechanism = failureMechanism;
- }
-
public IEnumerable UpdateSurfaceLinesWithImportedData(RingtoetsPipingSurfaceLineCollection targetCollection,
IEnumerable readRingtoetsPipingSurfaceLines,
string sourceFilePath)
{
- if (targetCollection == null)
+ try
{
- throw new ArgumentNullException(nameof(targetCollection));
+ return ReplaceTargetCollectionWithImportedData(targetCollection, readRingtoetsPipingSurfaceLines, sourceFilePath);
}
- if (readRingtoetsPipingSurfaceLines == null)
+ catch (ArgumentNullException)
{
- throw new ArgumentNullException(nameof(readRingtoetsPipingSurfaceLines));
+ throw;
}
- if (sourceFilePath == null)
- {
- throw new ArgumentNullException(nameof(sourceFilePath));
- }
-
- var affectedObjects = new List();
- affectedObjects.AddRange(PipingDataSynchronizationService.RemoveAllSurfaceLines(failureMechanism));
-
- try
- {
- targetCollection.AddRange(readRingtoetsPipingSurfaceLines, sourceFilePath);
- }
catch (ArgumentException e)
{
throw new RingtoetsPipingSurfaceLineUpdateException(e.Message, e);
}
+ }
- return affectedObjects;
+ protected override IEnumerable ClearData(PipingFailureMechanism failureMechanism)
+ {
+ return PipingDataSynchronizationService.RemoveAllSurfaceLines(failureMechanism);
}
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs
===================================================================
diff -u -r9393d671e0b4e1e8c76e5fcf32f61d5c3a5998b2 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision 9393d671e0b4e1e8c76e5fcf32f61d5c3a5998b2)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/StochasticSoilModelReplaceDataStrategy.cs (.../StochasticSoilModelReplaceDataStrategy.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -21,8 +21,8 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using Core.Common.Base;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Importers;
using Ringtoets.Piping.Service;
@@ -32,58 +32,37 @@
///
/// Strategy for replacing the stochastic soil models with the imported stochastic soil models.
///
- public class StochasticSoilModelReplaceDataStrategy : IStochasticSoilModelUpdateModelStrategy
+ public class StochasticSoilModelReplaceDataStrategy : ReplaceDataStrategyBase,
+ IStochasticSoilModelUpdateModelStrategy
{
- private readonly PipingFailureMechanism failureMechanism;
-
///
/// Creates a new instance of .
///
/// The failure mechanism in which the models are updated.
- public StochasticSoilModelReplaceDataStrategy(PipingFailureMechanism failureMechanism)
- {
- if (failureMechanism == null)
- {
- throw new ArgumentNullException(nameof(failureMechanism));
- }
- this.failureMechanism = failureMechanism;
- }
+ /// Thrown when is null.
+ public StochasticSoilModelReplaceDataStrategy(PipingFailureMechanism failureMechanism) : base(failureMechanism) {}
public IEnumerable UpdateModelWithImportedData(StochasticSoilModelCollection targetCollection,
IEnumerable readStochasticSoilModels,
string sourceFilePath)
{
- if (targetCollection == null)
+ try
{
- throw new ArgumentNullException(nameof(targetCollection));
+ return ReplaceTargetCollectionWithImportedData(targetCollection, readStochasticSoilModels, sourceFilePath);
}
- if (readStochasticSoilModels == null)
+ catch (ArgumentNullException)
{
- throw new ArgumentNullException(nameof(readStochasticSoilModels));
+ throw;
}
- if (sourceFilePath == null)
- {
- throw new ArgumentNullException(nameof(sourceFilePath));
- }
-
- var affectedObjects = new List
- {
- targetCollection
- };
-
- foreach (StochasticSoilModel model in targetCollection.ToArray())
- {
- affectedObjects.AddRange(PipingDataSynchronizationService.RemoveStochasticSoilModel(failureMechanism, model));
- }
- try
- {
- targetCollection.AddRange(readStochasticSoilModels.ToList(), sourceFilePath);
- }
catch (ArgumentException e)
{
throw new StochasticSoilModelUpdateException(e.Message, e);
}
- return affectedObjects.Distinct();
}
+
+ protected override IEnumerable ClearData(PipingFailureMechanism failureMechanism)
+ {
+ return PipingDataSynchronizationService.RemoveAllStochasticSoilModels(failureMechanism);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs
===================================================================
diff -u -r036199c1cde97f98829dc4405169ec327d2a1b95 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision 036199c1cde97f98829dc4405169ec327d2a1b95)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingDataSynchronizationService.cs (.../PipingDataSynchronizationService.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -253,6 +253,38 @@
}
///
+ /// Removes all from the
+ /// and clears all data that depends on it, either directly or indirectly.
+ ///
+ /// The failure mechanism.
+ /// All objects that are affected by this operation.
+ /// Thrown when
+ /// is null.
+ public static IEnumerable RemoveAllStochasticSoilModels(PipingFailureMechanism failureMechanism)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ IEnumerable affectedCalculationScenarios =
+ failureMechanism.Calculations
+ .Cast()
+ .Where(calc => calc.InputParameters.StochasticSoilModel != null).ToArray();
+
+ var affectedObjects = new List();
+ foreach (PipingCalculation calculation in affectedCalculationScenarios)
+ {
+ affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation));
+ affectedObjects.AddRange(ClearStochasticSoilModel(calculation.InputParameters));
+ }
+
+ failureMechanism.StochasticSoilModels.Clear();
+ affectedObjects.Add(failureMechanism.StochasticSoilModels);
+ return affectedObjects;
+ }
+
+ ///
/// Removes a given from calculations in the
/// and clears all data that depends on it, either directly or indirectly.
///
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs
===================================================================
diff -u -r66b07e7599319ea71ff109d8303f74a4a2e5f71c -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs) (revision 66b07e7599319ea71ff109d8303f74a4a2e5f71c)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (.../RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -25,6 +25,7 @@
using Core.Common.Base;
using Core.Common.Base.Geometry;
using NUnit.Framework;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.IO.Importers;
using Ringtoets.Piping.Plugin.FileImporter;
@@ -56,6 +57,7 @@
// Assert
Assert.IsInstanceOf(strategy);
+ Assert.IsInstanceOf>(strategy);
}
[Test]
@@ -85,7 +87,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("readRingtoetsPipingSurfaceLines", paramName);
+ Assert.AreEqual("importedDataCollection", paramName);
}
[Test]
Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs
===================================================================
diff -u -rc290911dd4647e3115e239c8baf814717c098a5a -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs (.../StochasticSoilModelReplaceDataStrategyTest.cs) (revision c290911dd4647e3115e239c8baf814717c098a5a)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/StochasticSoilModelReplaceDataStrategyTest.cs (.../StochasticSoilModelReplaceDataStrategyTest.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -24,6 +24,7 @@
using System.Linq;
using Core.Common.Base;
using NUnit.Framework;
+using Ringtoets.Common.Data.UpdateDataStrategies;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.TestUtil;
using Ringtoets.Piping.IO.Importers;
@@ -55,6 +56,7 @@
// Assert
Assert.IsInstanceOf(strategy);
+ Assert.IsInstanceOf>(strategy);
}
[Test]
@@ -68,7 +70,7 @@
// Assert
string paramName = Assert.Throws(test).ParamName;
- Assert.AreEqual("readStochasticSoilModels", paramName);
+ Assert.AreEqual("importedDataCollection", paramName);
}
[Test]
@@ -108,17 +110,20 @@
new TestStochasticSoilModel("A"),
new TestStochasticSoilModel("B")
};
- var strategy = new StochasticSoilModelReplaceDataStrategy(new PipingFailureMechanism());
- var targetCollection = new StochasticSoilModelCollection();
+ var pipingFailureMechanism = new PipingFailureMechanism();
+ pipingFailureMechanism.StochasticSoilModels.AddRange(importedStochasticSoilModels, sourceFilePath);
+ var strategy = new StochasticSoilModelReplaceDataStrategy(pipingFailureMechanism);
// Call
- IEnumerable affectedObjects = strategy.UpdateModelWithImportedData(targetCollection, importedStochasticSoilModels, "path");
+ IEnumerable affectedObjects = strategy.UpdateModelWithImportedData(pipingFailureMechanism.StochasticSoilModels,
+ importedStochasticSoilModels,
+ "path");
// Assert
- CollectionAssert.AreEqual(importedStochasticSoilModels, targetCollection);
+ CollectionAssert.AreEqual(importedStochasticSoilModels, pipingFailureMechanism.StochasticSoilModels);
CollectionAssert.AreEqual(new[]
{
- targetCollection
+ pipingFailureMechanism.StochasticSoilModels
}, affectedObjects);
}
Index: Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs
===================================================================
diff -u -r036199c1cde97f98829dc4405169ec327d2a1b95 -rb1537a16c5961d9f66d5564c215f4bee59294f82
--- Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision 036199c1cde97f98829dc4405169ec327d2a1b95)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Service.Test/PipingDataSynchronizationServiceTest.cs (.../PipingDataSynchronizationServiceTest.cs) (revision b1537a16c5961d9f66d5564c215f4bee59294f82)
@@ -68,9 +68,9 @@
Assert.IsNull(calculation.SemiProbabilisticOutput);
CollectionAssert.AreEqual(new[]
- {
- calculation
- }, changedObjects);
+ {
+ calculation
+ }, changedObjects);
}
[Test]
@@ -413,5 +413,62 @@
CollectionAssert.Contains(array, calculation);
}
}
+
+ [Test]
+ public void RemoveAllStochasticSoilModel_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ PipingFailureMechanism failureMechanism = null;
+
+ // Call
+ TestDelegate call = () => PipingDataSynchronizationService.RemoveAllStochasticSoilModels(failureMechanism);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("failureMechanism", paramName);
+ }
+
+ [Test]
+ public void RemoveAllStochastiSoilModel_FullyConfiguredPipingFailureMechanism_RemovesAllSoilModelAndClearDependendentData()
+ {
+ // Setup
+ PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations();
+ PipingCalculation[] calculationsWithStochasticSoilModel = failureMechanism.Calculations
+ .Cast()
+ .Where(calc => calc.InputParameters.StochasticSoilModel != null)
+ .ToArray();
+ PipingCalculation[] calculationsWithOutput = calculationsWithStochasticSoilModel.Where(c => c.HasOutput)
+ .ToArray();
+
+ // Precondition
+ CollectionAssert.IsNotEmpty(calculationsWithStochasticSoilModel);
+
+ // Call
+ IEnumerable observables = PipingDataSynchronizationService.RemoveAllStochasticSoilModels(failureMechanism);
+
+ // Assert
+ // Note: To make sure the clear is performed regardless of what is done with
+ // the return result, no ToArray() should be called before these assertions:
+ CollectionAssert.IsEmpty(failureMechanism.StochasticSoilModels);
+ foreach (PipingCalculation calculation in calculationsWithStochasticSoilModel)
+ {
+ Assert.IsNull(calculation.InputParameters.StochasticSoilModel);
+ }
+
+ IObservable[] array = observables.ToArray();
+ var expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithStochasticSoilModel.Length;
+ Assert.AreEqual(expectedAffectedObjectCount, array.Length);
+
+ CollectionAssert.Contains(array, failureMechanism.StochasticSoilModels);
+ foreach (PipingCalculation calculation in calculationsWithStochasticSoilModel)
+ {
+ CollectionAssert.Contains(array, calculation.InputParameters);
+ }
+ foreach (PipingCalculation calculation in calculationsWithOutput)
+ {
+ Assert.IsFalse(calculation.HasOutput);
+ CollectionAssert.Contains(array, calculation);
+ }
+ }
}
}
\ No newline at end of file