Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs =================================================================== diff -u -ra7f920661887773056c051edc7872d27f724c840 -r92acb4483676af5adad598c2ea8ca46f9b8379c1 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs (.../ClosingStructuresPluginTest.cs) (revision a7f920661887773056c051edc7872d27f724c840) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/ClosingStructuresPluginTest.cs (.../ClosingStructuresPluginTest.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -153,6 +153,20 @@ } [Test] + public void GetUpdateInfos_ReturnSupportedUpdateInfos() + { + using (var plugin = new ClosingStructuresPlugin()) + { + // Call + UpdateInfo[] updateInfo = plugin.GetUpdateInfos().ToArray(); + + // Assert + Assert.AreEqual(1, updateInfo.Length); + Assert.IsTrue(updateInfo.Any(i => i.DataType == typeof(ClosingStructuresContext))); + } + } + + [Test] public void GetExportInfos_ReturnsSupportedExportInfos() { // Setup Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -ra7f920661887773056c051edc7872d27f724c840 -r92acb4483676af5adad598c2ea8ca46f9b8379c1 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision a7f920661887773056c051edc7872d27f724c840) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -153,6 +153,20 @@ } [Test] + public void GetUpdateInfos_ReturnSupportedUpdateInfos() + { + using (var plugin = new HeightStructuresPlugin()) + { + // Call + UpdateInfo[] updateInfo = plugin.GetUpdateInfos().ToArray(); + + // Assert + Assert.AreEqual(1, updateInfo.Length); + Assert.IsTrue(updateInfo.Any(i => i.DataType == typeof(HeightStructuresContext))); + } + } + + [Test] public void GetExportInfos_ReturnsSupportedExportInfos() { // Setup Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r92acb4483676af5adad598c2ea8ca46f9b8379c1 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -45,6 +45,7 @@ using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.Common.IO.FileImporters.MessageProviders; +using Ringtoets.Common.IO.Structures; using Ringtoets.Common.Service; using Ringtoets.Common.Utils; using Ringtoets.StabilityPointStructures.Data; @@ -192,16 +193,15 @@ { yield return new ImportInfo { - CreateFileImporter = (context, filePath) => new StabilityPointStructuresImporter(context.WrappedData, - context.AssessmentSection.ReferenceLine, - filePath, - new ImportMessageProvider(), - new StabilityPointStructureReplaceStrategy(context.FailureMechanism)), + CreateFileImporter = (context, filePath) => CreateStabilityPointStructuresImporter( + context, + filePath, + new ImportMessageProvider(), + new StabilityPointStructureReplaceStrategy(context.FailureMechanism)), Name = RingtoetsCommonFormsResources.StructuresImporter_DisplayName, Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsCommonFormsResources.StructuresIcon, - FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, - RingtoetsCommonIOResources.Shape_file_filter_Description), + FileFilterGenerator = CreateStabilityPointStructureFileFilter(), IsEnabled = context => context.AssessmentSection.ReferenceLine != null }; @@ -228,6 +228,24 @@ }, filePath)); } + public override IEnumerable GetUpdateInfos() + { + yield return new UpdateInfo + { + CreateFileImporter = (context, filePath) => CreateStabilityPointStructuresImporter( + context, + filePath, + new UpdateMessageProvider(), + new StabilityPointStructureUpdateDataStrategy(context.FailureMechanism)), + Name = RingtoetsCommonDataResources.StructureCollection_TypeDescriptor, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsCommonFormsResources.StructuresIcon, + FileFilterGenerator = CreateStabilityPointStructureFileFilter(), + IsEnabled = context => context.WrappedData.SourcePath != null, + CurrentPath = context => context.WrappedData.SourcePath + }; + } + #region ViewInfo #region StabilityPointStructuresFailureMechanismView ViewInfo @@ -838,5 +856,27 @@ #endregion #endregion + + #region Importers + + private static StabilityPointStructuresImporter CreateStabilityPointStructuresImporter(StabilityPointStructuresContext context, + string filePath, + IImporterMessageProvider messageProvider, + IStructureUpdateStrategy updateStrategy) + { + return new StabilityPointStructuresImporter(context.WrappedData, + context.AssessmentSection.ReferenceLine, + filePath, + messageProvider, + updateStrategy); + } + + private static FileFilterGenerator CreateStabilityPointStructureFileFilter() + { + return new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, + RingtoetsCommonIOResources.Shape_file_filter_Description); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj =================================================================== diff -u -r0e100db56270f5f51374771a049b20dec82df128 -r92acb4483676af5adad598c2ea8ca46f9b8379c1 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 0e100db56270f5f51374771a049b20dec82df128) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/Ringtoets.StabilityPointStructures.Plugin.Test.csproj (.../Ringtoets.StabilityPointStructures.Plugin.Test.csproj) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -78,6 +78,7 @@ + Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs =================================================================== diff -u -rb3cd93a57114ffa27d177cabb8e4635dfc71955c -r92acb4483676af5adad598c2ea8ca46f9b8379c1 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs (.../StabilityPointStructuresPluginTest.cs) (revision b3cd93a57114ffa27d177cabb8e4635dfc71955c) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/StabilityPointStructuresPluginTest.cs (.../StabilityPointStructuresPluginTest.cs) (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -153,6 +153,20 @@ } [Test] + public void GetUpdateInfos_ReturnSupportedUpdateInfos() + { + using (var plugin = new StabilityPointStructuresPlugin()) + { + // Call + UpdateInfo[] updateInfo = plugin.GetUpdateInfos().ToArray(); + + // Assert + Assert.AreEqual(1, updateInfo.Length); + Assert.IsTrue(updateInfo.Any(i => i.DataType == typeof(StabilityPointStructuresContext))); + } + } + + [Test] public void GetExportInfos_ReturnsSupportedExportInfos() { // Setup Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs (revision 0) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/UpdateInfos/StabilityPointStructuresContextUpdateInfoTest.cs (revision 92acb4483676af5adad598c2ea8ca46f9b8379c1) @@ -0,0 +1,194 @@ +// Copyright (C) Stichting Deltares 2017. 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.Drawing; +using System.Linq; +using Core.Common.Base.IO; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.StabilityPointStructures.Data; +using Ringtoets.StabilityPointStructures.Forms.PresentationObjects; +using Ringtoets.StabilityPointStructures.IO; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.StabilityPointStructures.Plugin.Test.UpdateInfos +{ + [TestFixture] + public class StabilityPointStructuresContextUpdateInfoTest + { + [TestFixture] + public class ClosingStructuresContextUpdateInfoTest : NUnitFormTest + { + private UpdateInfo updateInfo; + private StabilityPointStructuresPlugin plugin; + + [SetUp] + public void SetUp() + { + plugin = new StabilityPointStructuresPlugin(); + updateInfo = plugin.GetUpdateInfos().First(i => i.DataType == typeof(StabilityPointStructuresContext)); + } + + [TearDown] + public override void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Name_Always_ReturnExpectedName() + { + // Call + string name = updateInfo.Name; + + // Assert + Assert.AreEqual("Kunstwerken", name); + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Call + string category = updateInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Call + Image image = updateInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.StructuresIcon, image); + } + + [Test] + public void IsEnabled_SourcePathNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_SourcePathSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + failureMechanism.StabilityPointStructures.AddRange(Enumerable.Empty(), "some path"); + + var context = new StabilityPointStructuresContext(failureMechanism.StabilityPointStructures, + failureMechanism, + assessmentSection); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Call + string fileFilter = updateInfo.FileFilterGenerator.Filter; + + // Assert + Assert.AreEqual(@"Shapebestand (*.shp)|*.shp", fileFilter); + } + + [Test] + public void CurrentPath_StructureCollectionHasPathSet_ReturnsExpectedPath() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + const string expectedFilePath = "some/path"; + var structures = new StructureCollection(); + structures.AddRange(Enumerable.Empty(), expectedFilePath); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var context = new StabilityPointStructuresContext(structures, failureMechanism, assessmentSection); + + // Call + string currentPath = updateInfo.CurrentPath(context); + + // Assert + Assert.AreEqual(expectedFilePath, currentPath); + mocks.VerifyAll(); + } + + [Test] + public void CreateFileImporter_ValidInput_ReturnFileImporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var structures = new StructureCollection(); + + var importTarget = new StabilityPointStructuresContext(structures, + failureMechanism, + assessmentSection); + + // Call + IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "This is valid"); + + // Assert + Assert.IsInstanceOf(importer); + mocks.VerifyAll(); + } + } + } +} \ No newline at end of file