Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs =================================================================== diff -u -ra70cb733eb761229173777b9f6cd1b977830b24b -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs (.../DikeProfilesContextUpdateInfoTest.cs) (revision a70cb733eb761229173777b9f6cd1b977830b24b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/UpdateInfos/DikeProfilesContextUpdateInfoTest.cs (.../DikeProfilesContextUpdateInfoTest.cs) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -33,6 +33,7 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.IO.FileImporters; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; @@ -277,6 +278,38 @@ } } + [Test] + public void CurrentPath_DikeProfileCollectionHasPathSet_ReturnsExpectedPath() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + const string expectedFilePath = "some/path"; + var surfaceLines = new DikeProfileCollection(); + surfaceLines.AddRange(new[] + { + new TestDikeProfile() + }, expectedFilePath); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var context = new DikeProfilesContext(surfaceLines, failureMechanism, assessmentSection); + + using (var plugin = new GrassCoverErosionInwardsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + string currentFilePath = updateInfo.CurrentPath(context); + + // Assert + Assert.AreEqual(expectedFilePath, currentFilePath); + mocks.VerifyAll(); + } + } + private static UpdateInfo GetUpdateInfo(GrassCoverErosionInwardsPlugin plugin) { return plugin.GetUpdateInfos().First(ii => ii.DataType == typeof(DikeProfilesContext)); Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r4eaa942f6a986a04aacee22d1b8e142b0d07f389 -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 4eaa942f6a986a04aacee22d1b8e142b0d07f389) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -448,12 +448,13 @@ }; yield return new ImportInfo { - CreateFileImporter = (context, filePath) => new ForeshoreProfilesImporter(context.WrappedData, - context.ParentAssessmentSection.ReferenceLine, - filePath, - new ForeshoreProfileReplaceDataStrategy(context.ParentFailureMechanism, - context.WrappedData), - new ImportMessageProvider()), + CreateFileImporter = (context, filePath) => + new ForeshoreProfilesImporter(context.WrappedData, + context.ParentAssessmentSection.ReferenceLine, + filePath, + new ForeshoreProfileReplaceDataStrategy(context.ParentFailureMechanism, + context.WrappedData), + new ImportMessageProvider()), Name = RingtoetsIntegrationPluginResources.ForeshoreProfilesImporter_DisplayName, Category = RingtoetsCommonFormsResources.Ringtoets_Category, Image = RingtoetsIntegrationPluginResources.Foreshore, @@ -484,6 +485,26 @@ }; } + public override IEnumerable GetUpdateInfos() + { + yield return new UpdateInfo + { + CreateFileImporter = (context, filePath) => + new ForeshoreProfilesImporter(context.WrappedData, + context.ParentAssessmentSection.ReferenceLine, + filePath, + new ForeshoreProfileUpdateDataStrategy(context.ParentFailureMechanism), + new UpdateMessageProvider()), + Name = RingtoetsIntegrationPluginResources.ForeshoreProfilesImporter_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsIntegrationPluginResources.Foreshore, + FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension, + RingtoetsCommonIOResources.Shape_file_filter_Description), + CurrentPath = context => context.WrappedData.SourcePath, + IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null + }; + } + /// /// Gets the child data instances that have definitions of some parent data object. /// @@ -629,6 +650,7 @@ .ToArray(), ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl) .AddImportItem() + .AddUpdateItem() .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/ForeshoreProfilesContextImportInfoTest.cs =================================================================== diff -u -red4b032b9903f394deb9691c2c39a9f2122ab0f5 -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/ForeshoreProfilesContextImportInfoTest.cs (.../ForeshoreProfilesContextImportInfoTest.cs) (revision ed4b032b9903f394deb9691c2c39a9f2122ab0f5) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ImportInfos/ForeshoreProfilesContextImportInfoTest.cs (.../ForeshoreProfilesContextImportInfoTest.cs) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -21,7 +21,6 @@ using System.Drawing; using System.Linq; -using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.Gui.Plugin; using Core.Common.TestUtil; Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r4a9779426ab93aa90af783bf4d4f00aed2b32ce5 -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 4a9779426ab93aa90af783bf4d4f00aed2b32ce5) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -115,6 +115,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r43701b21ae485678c471bcf76ca9c374fd16b9f9 -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 43701b21ae485678c471bcf76ca9c374fd16b9f9) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -521,6 +521,21 @@ } [Test] + public void GetImportInfos_ReturnsSupportedUpdateInfos() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + // Call + UpdateInfo[] updateInfos = plugin.GetUpdateInfos().ToArray(); + + // Assert + Assert.AreEqual(1, updateInfos.Length); + Assert.IsTrue(updateInfos.Any(i => i.DataType == typeof(ForeshoreProfilesContext))); + } + } + + [Test] public void Activate_WithoutGui_ThrowsInvalidOperationException() { // Setup Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/ForeshoreProfilesContextTreeNodeInfoTest.cs =================================================================== diff -u -r91ff3f5d204bd88b21e62d553cfd867f1843859e -r6ea2281c03c04dfbfaa7742d533fc1f88b96f59c --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/ForeshoreProfilesContextTreeNodeInfoTest.cs (.../ForeshoreProfilesContextTreeNodeInfoTest.cs) (revision 91ff3f5d204bd88b21e62d553cfd867f1843859e) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/ForeshoreProfilesContextTreeNodeInfoTest.cs (.../ForeshoreProfilesContextTreeNodeInfoTest.cs) (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -198,6 +198,7 @@ using (mocks.Ordered()) { contextMenuBuilder.Expect(b => b.AddImportItem()).Return(contextMenuBuilder); + contextMenuBuilder.Expect(b => b.AddUpdateItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddSeparator()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddCollapseAllItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddExpandAllItem()).Return(contextMenuBuilder); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/UpdateInfos/ForeshoreProfileContextUpdateInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/UpdateInfos/ForeshoreProfileContextUpdateInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/UpdateInfos/ForeshoreProfileContextUpdateInfoTest.cs (revision 6ea2281c03c04dfbfaa7742d533fc1f88b96f59c) @@ -0,0 +1,225 @@ +// 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 Core.Common.Utils; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Integration.Plugin.Properties; + +namespace Ringtoets.Integration.Plugin.Test.UpdateInfos +{ + [TestFixture] + public class ForeshoreProfileContextUpdateInfoTest + { + [Test] + public void CreateFileImporter_Always_ReturnFileImporter() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.Stub(); + mocks.ReplayAll(); + + assessmentSection.ReferenceLine = new ReferenceLine(); + + var foreshoreProfiles = new ForeshoreProfileCollection(); + + var importTarget = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); + + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "test"); + + // Assert + Assert.IsInstanceOf>(importer); + } + mocks.VerifyAll(); + } + + [Test] + public void Name_Always_ReturnExpectedName() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + string name = updateInfo.Name; + + // Assert + Assert.AreEqual("Voorlandprofiellocaties", name); + } + } + + [Test] + public void Category_Always_ReturnExpectedCategory() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + string category = updateInfo.Category; + + // Assert + Assert.AreEqual("Algemeen", category); + } + } + + [Test] + public void Image_Always_ReturnExpectedIcon() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + Image image = updateInfo.Image; + + // Assert + TestHelper.AssertImagesAreEqual(Resources.Foreshore, image); + } + } + + [Test] + public void IsEnabled_ReferenceLineSet_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = new ReferenceLine(); + var failureMechanism = mocks.Stub(); + mocks.ReplayAll(); + + var foreshoreProfiles = new ForeshoreProfileCollection(); + + var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); + + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsTrue(isEnabled); + } + mocks.VerifyAll(); + } + + [Test] + public void IsEnabled_ReferenceLineNotSet_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.ReferenceLine = null; + var failureMechanism = mocks.Stub(); + mocks.ReplayAll(); + + var foreshoreProfiles = new ForeshoreProfileCollection(); + + var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); + + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + bool isEnabled = updateInfo.IsEnabled(context); + + // Assert + Assert.IsFalse(isEnabled); + } + mocks.VerifyAll(); + } + + [Test] + public void FileFilterGenerator_Always_ReturnExpectedFileFilter() + { + // Setup + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + FileFilterGenerator fileFilterGenerator = updateInfo.FileFilterGenerator; + + // Assert + Assert.AreEqual("Shapebestand (*.shp)|*.shp", fileFilterGenerator.Filter); + } + } + + [Test] + public void CurrentPath_DikeProfileCollectionHasPathSet_ReturnsExpectedPath() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + var failureMechanism = mocks.Stub(); + mocks.ReplayAll(); + + const string expectedFilePath = "some/path"; + var surfaceLines = new ForeshoreProfileCollection(); + surfaceLines.AddRange(new[] + { + new TestForeshoreProfile(), + }, expectedFilePath); + + var context = new ForeshoreProfilesContext(surfaceLines, failureMechanism, assessmentSection); + + using (var plugin = new RingtoetsPlugin()) + { + UpdateInfo updateInfo = GetUpdateInfo(plugin); + + // Call + string currentFilePath = updateInfo.CurrentPath(context); + + // Assert + Assert.AreEqual(expectedFilePath, currentFilePath); + mocks.VerifyAll(); + } + } + + private static UpdateInfo GetUpdateInfo(RingtoetsPlugin plugin) + { + return plugin.GetUpdateInfos().First(ii => ii.DataType == typeof(ForeshoreProfilesContext)); + } + } +}