Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/ISurfaceLineUpdateStrategy.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/ISurfaceLineUpdateStrategy.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importer/ISurfaceLineUpdateStrategy.cs (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -0,0 +1,49 @@ +// 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.Piping.Primitives; + +namespace Ringtoets.Piping.IO.Importer +{ + /// + /// Interface describing the method of updating the data model after new surface lines + /// have been imported. + /// + public interface ISurfaceLineUpdateStrategy + { + /// + /// Adds the imported data to the . + /// + /// The + /// which needs to be updated. + /// The imported surface lines. + /// The source path from where the surface lines were imported from. + /// An of updated instances. + /// Thrown when any of the input parameters is null + IEnumerable UpdateSurfaceLinesWithImportedData( + ObservableCollectionWithSourcePath targetCollection, + IEnumerable readRingtoetsPipingSurfaceLines, + string sourceFilePath); + } +} Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -ree74bbc714b9c3d6b46e7c7734640366ef197ef6 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -54,6 +54,7 @@ + Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategy.cs (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -0,0 +1,61 @@ +// 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.Piping.IO.Importer; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Plugin.FileImporter +{ + /// + /// Strategy to replace the surface lines with the imported surface lines. + /// + public class RingtoetsPipingSurfaceLineReplaceDataStrategy : ISurfaceLineUpdateStrategy + { + public IEnumerable UpdateSurfaceLinesWithImportedData(ObservableCollectionWithSourcePath targetCollection, + IEnumerable readRingtoetsPipingSurfaceLines, + string sourceFilePath) + { + if (targetCollection == null) + { + throw new ArgumentNullException(nameof(targetCollection)); + } + if (readRingtoetsPipingSurfaceLines == null) + { + throw new ArgumentNullException(nameof(readRingtoetsPipingSurfaceLines)); + } + if (sourceFilePath == null) + { + throw new ArgumentNullException(nameof(sourceFilePath)); + } + + targetCollection.Clear(); + targetCollection.AddRange(readRingtoetsPipingSurfaceLines, sourceFilePath); + + return new [] + { + targetCollection + }; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj =================================================================== diff -u -ra59b471e3b6a02319f91b7317b3814a099ef0221 -ree74bbc714b9c3d6b46e7c7734640366ef197ef6 --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision a59b471e3b6a02319f91b7317b3814a099ef0221) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Ringtoets.Piping.Plugin.csproj (.../Ringtoets.Piping.Plugin.csproj) (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -59,6 +59,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/FileImporter/RingtoetsPipingSurfaceLineReplaceDataStrategyTest.cs (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -0,0 +1,158 @@ +// 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.Piping.IO.Importer; +using Ringtoets.Piping.Plugin.FileImporter; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Plugin.Test.FileImporter +{ + [TestFixture] + public class RingtoetsPipingSurfaceLineReplaceDataStrategyTest + { + [Test] + public void Constructor_CreatesNewInstance() + { + // Call + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + + // Assert + Assert.IsInstanceOf(strategy); + } + + [Test] + public void Constructor_TargetCollectionNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + + // Call + TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(null, Enumerable.Empty(), string.Empty); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("targetCollection", paramName); + } + + [Test] + public void UpdateModelWithImportedData_ReadSurfaceLinesNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + + // Call + TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new ObservableCollectionWithSourcePath(), + null, + string.Empty); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("readRingtoetsPipingSurfaceLines", paramName); + } + + [Test] + public void UpdateModelWithImportedData_SourceFilePathNull_ThrowsArgumentNullException() + { + // Setup + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + + // Call + TestDelegate test = () => strategy.UpdateSurfaceLinesWithImportedData(new ObservableCollectionWithSourcePath(), + Enumerable.Empty(), + null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("sourceFilePath", paramName); + } + + [Test] + public void UpdateModelWithImportedData_DifferentSourcePath_UpdatesSourcePathOfTargetCollection() + { + // Setup + var targetCollection = new ObservableCollectionWithSourcePath(); + + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + const string newSourcePath = "some/other/path"; + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(targetCollection, + Enumerable.Empty(), + newSourcePath); + + // Assert + CollectionAssert.AreEqual(new IObservable[] + { + targetCollection + }, affectedObjects); + CollectionAssert.IsEmpty(targetCollection); + Assert.AreEqual(newSourcePath, targetCollection.SourcePath); + } + + [Test] + public void UpdateModelWithImportedData_DifferentElements_UpdatesTargetCollection() + { + // Setup + var targetSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name A", + }; + var targetCollection = new ObservableCollectionWithSourcePath(); + targetCollection.AddRange(new[] + { + targetSurfaceLine + }, "some/path"); + + var readSurfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Name B" + }; + var readSurfacelines = new[] + { + readSurfaceLine + }; + + var strategy = new RingtoetsPipingSurfaceLineReplaceDataStrategy(); + + // Call + IEnumerable affectedObjects = strategy.UpdateSurfaceLinesWithImportedData(targetCollection, + readSurfacelines, + "some/path"); + + // Assert + CollectionAssert.AreEqual(new IObservable[] + { + targetCollection + }, affectedObjects); + + var expectedTargetCollection = new[] + { + readSurfaceLine + }; + CollectionAssert.AreEqual(expectedTargetCollection, targetCollection); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj =================================================================== diff -u -r0ab02f0514e081770486d6a9b1b4fbcd9c92d642 -ree74bbc714b9c3d6b46e7c7734640366ef197ef6 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision 0ab02f0514e081770486d6a9b1b4fbcd9c92d642) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/Ringtoets.Piping.Plugin.Test.csproj (.../Ringtoets.Piping.Plugin.Test.csproj) (revision ee74bbc714b9c3d6b46e7c7734640366ef197ef6) @@ -72,6 +72,7 @@ Properties\GlobalAssembly.cs +