Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/NamingHelper.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/NamingHelper.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/NamingHelper.cs (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Ringtoets.Common.Forms.Helpers
+{
+ ///
+ /// Helper class for generating unique names.
+ ///
+ public static class NamingHelper
+ {
+ ///
+ /// Generate an unique name given a collection of existing named objects.
+ ///
+ /// Type of objects in the collection.
+ /// All existing named objects.
+ /// The base naming scheme to use.
+ /// Getter method to determine the name of each object in .
+ /// A unique name based on that is not used
+ /// in .
+ public static string GetUniqueName(IEnumerable existingObjects, string nameBase, Func nameGetter)
+ {
+ int i = 1;
+ string result = nameBase;
+ var existingNames = existingObjects.Select(nameGetter).ToArray();
+ while (existingNames.Any(name => name.Equals(result)))
+ {
+ result = string.Format("{0} ({1})", nameBase, i++);
+ }
+ return result;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -58,6 +58,7 @@
Properties\GlobalAssembly.cs
+
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/NamingHelperTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/NamingHelperTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Helpers/NamingHelperTest.cs (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -0,0 +1,88 @@
+using System.Linq;
+
+using NUnit.Framework;
+
+using Ringtoets.Common.Forms.Helpers;
+
+namespace Ringtoets.Common.Forms.Test.Helpers
+{
+ [TestFixture]
+ public class NamingHelperTest
+ {
+ [Test]
+ public void GetUniqueName_EmptyCollection_ReturnNameBase()
+ {
+ // Setup
+ const string nameBase = "The basic name";
+
+ var existingObjects = Enumerable.Empty();
+
+ // Call
+ var name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);
+
+ // Assert
+ Assert.AreEqual(nameBase, name);
+ }
+
+ [Test]
+ public void GetUniqueName_CollectionWithNamedObjectMatchingNameBase_ReturnNameBaseAppendedWithPostfixIncrement()
+ {
+ // Setup
+ const string nameBase = "The basic name";
+
+ var existingObjects = new[] { new ObjectWithName(nameBase) };
+
+ // Call
+ var name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);
+
+ // Assert
+ Assert.AreEqual(nameBase + " (1)", name);
+ }
+
+ [Test]
+ public void GetUniqueName_CollectionWithNamedObjectMatchingNameBaseAndPostFix_ReturnNameBaseAppendedWithNextPostfixIncrement()
+ {
+ // Setup
+ const string nameBase = "The basic name";
+
+ var existingObjects = new[]
+ {
+ new ObjectWithName(nameBase),
+ new ObjectWithName(nameBase + " (3)"),
+ new ObjectWithName(nameBase + " (1)"),
+ new ObjectWithName(nameBase + " (2)"),
+ };
+
+ // Call
+ var name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);
+
+ // Assert
+ Assert.AreEqual(nameBase + " (4)", name);
+ }
+
+ [Test]
+ public void GetUniqueName_CollectionWithNamedObjectNotMatchingNameBase_ReturnNameBase()
+ {
+ // Setup
+ const string nameBase = "The basic name";
+
+ var existingObjects = new[] { new ObjectWithName("Something original!") };
+
+ // Call
+ var name = NamingHelper.GetUniqueName(existingObjects, nameBase, namedObject => namedObject.Name);
+
+ // Assert
+ Assert.AreEqual(nameBase, name);
+ }
+
+ private class ObjectWithName
+ {
+ public ObjectWithName(string name)
+ {
+ Name = name;
+ }
+
+ public string Name { get; private set; }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -63,6 +63,7 @@
+
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/Ringtoets.Integration.Plugin.csproj (.../Ringtoets.Integration.Plugin.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -85,6 +85,10 @@
{30e4c2ae-719e-4d70-9fa9-668a9767fbfa}
Core.Common.Gui
+
+ {f49bd8b2-332a-4c91-a196-8cce0a2c7d98}
+ Core.Common.Utils
+
{c90b77da-e421-43cc-b82e-529651bc21ac}
Core.Common.Version
Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs
===================================================================
diff -u -r5c044a6799b45bec77af170dca0a84bc434c5f6f -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision 5c044a6799b45bec77af170dca0a84bc434c5f6f)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsApplicationPlugin.cs (.../RingtoetsApplicationPlugin.cs) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -1,7 +1,9 @@
using System.Collections.Generic;
+using System.Linq;
using Core.Common.Base;
+using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Integration.Data;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
@@ -21,15 +23,32 @@
Name = RingtoetsFormsResources.DikeAssessmentSection_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsFormsResources.AssessmentSectionFolderIcon,
- CreateData = owner => new DikeAssessmentSection()
+ CreateData = owner =>
+ {
+ var project = (Project)owner;
+ var dikeAssessmentSection = new DikeAssessmentSection();
+ dikeAssessmentSection.Name = GetUniqueForAssessmentSectionName(project, dikeAssessmentSection.Name);
+ return dikeAssessmentSection;
+ }
};
yield return new DataItemInfo
{
Name = RingtoetsFormsResources.DuneAssessmentSection_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsFormsResources.AssessmentSectionFolderIcon,
- CreateData = owner => new DuneAssessmentSection()
+ CreateData = owner =>
+ {
+ var project = (Project)owner;
+ var duneAssessmentSection = new DuneAssessmentSection();
+ duneAssessmentSection.Name = GetUniqueForAssessmentSectionName(project, duneAssessmentSection.Name);
+ return duneAssessmentSection;
+ }
};
}
+
+ private static string GetUniqueForAssessmentSectionName(Project project, string baseName)
+ {
+ return NamingHelper.GetUniqueName(project.Items.OfType(), baseName, a => a.Name);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -87,6 +87,10 @@
{30e4c2ae-719e-4d70-9fa9-668a9767fbfa}
Core.Common.Gui
+
+ {f49bd8b2-332a-4c91-a196-8cce0a2c7d98}
+ Core.Common.Utils
+
{d749ee4c-ce50-4c17-bf01-9a953028c126}
Core.Common.TestUtils
Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs
===================================================================
diff -u -re45c4de1ffabe66b3b49123abc2e4e6c951435f5 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision e45c4de1ffabe66b3b49123abc2e4e6c951435f5)
+++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsApplicationPluginTest.cs (.../RingtoetsApplicationPluginTest.cs) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -40,16 +40,62 @@
Assert.AreEqual("Algemeen", dikeAssessmentSectionDataItemDefinition.Category);
TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.AssessmentSectionFolderIcon, dikeAssessmentSectionDataItemDefinition.Image);
Assert.IsNull(dikeAssessmentSectionDataItemDefinition.AdditionalOwnerCheck);
- Assert.IsInstanceOf(dikeAssessmentSectionDataItemDefinition.CreateData(null));
+ Assert.IsInstanceOf(dikeAssessmentSectionDataItemDefinition.CreateData(new Project()));
Assert.IsNull(dikeAssessmentSectionDataItemDefinition.AddExampleData);
DataItemInfo duneAssessmentDataItemDefinition = dataItemDefinitions.Single(did => did.ValueType == typeof(DuneAssessmentSection));
Assert.AreEqual("Duintraject", duneAssessmentDataItemDefinition.Name);
Assert.AreEqual("Algemeen", duneAssessmentDataItemDefinition.Category);
TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.AssessmentSectionFolderIcon, duneAssessmentDataItemDefinition.Image);
Assert.IsNull(duneAssessmentDataItemDefinition.AdditionalOwnerCheck);
- Assert.IsInstanceOf(duneAssessmentDataItemDefinition.CreateData(null));
+ Assert.IsInstanceOf(duneAssessmentDataItemDefinition.CreateData(new Project()));
Assert.IsNull(duneAssessmentDataItemDefinition.AddExampleData);
}
+
+ [Test]
+ [TestCase(AssessmentSectionType.Dike)]
+ [TestCase(AssessmentSectionType.Dune)]
+ public void WhenAddingAssessmentSection_GivenProjectHasAssessmentSection_ThenAddedAssessmentSectionHasUniqueName(AssessmentSectionType type)
+ {
+ // Setup
+ var project = new Project();
+
+ var plugin = new RingtoetsApplicationPlugin();
+ AddAssessmentSectionToProject(project, plugin, type);
+
+ // Call
+ AddAssessmentSectionToProject(project, plugin, type);
+
+ // Assert
+ CollectionAssert.AllItemsAreUnique(project.Items.Cast().Select(section => section.Name));
+ }
+
+ private void AddAssessmentSectionToProject(Project project, RingtoetsApplicationPlugin plugin, AssessmentSectionType type)
+ {
+ object itemToAdd = null;
+ switch (type)
+ {
+ case AssessmentSectionType.Dike:
+ itemToAdd = plugin.GetDataItemInfos().First(di => di.ValueType == typeof(DikeAssessmentSection)).CreateData(project);
+ break;
+ case AssessmentSectionType.Dune:
+ itemToAdd = plugin.GetDataItemInfos().First(di => di.ValueType == typeof(DuneAssessmentSection)).CreateData(project);
+ break;
+ }
+
+ project.Items.Add(itemToAdd);
+ }
+
+ public enum AssessmentSectionType
+ {
+ ///
+ /// Type value representing instances.
+ ///
+ Dike,
+ ///
+ /// Type value representing instances.
+ ///
+ Dune
+ }
}
}
\ No newline at end of file
Fisheye: Tag 61f804a9e44dedf9c512646cf488e3761ddefac5 refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/Helpers/NamingHelper.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingCalculationGroupContextNodePresenter.cs
===================================================================
diff -u -r6917dbadda57c0b4b3e4f679e229585b584c8579 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingCalculationGroupContextNodePresenter.cs (.../PipingCalculationGroupContextNodePresenter.cs) (revision 6917dbadda57c0b4b3e4f679e229585b584c8579)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingCalculationGroupContextNodePresenter.cs (.../PipingCalculationGroupContextNodePresenter.cs) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -8,10 +8,10 @@
using Core.Common.Controls;
using Ringtoets.Common.Forms.Extensions;
+using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.NodePresenters;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.Properties;
-using Ringtoets.Piping.Forms.Helpers;
using Ringtoets.Piping.Forms.PresentationObjects;
using Ringtoets.Piping.Service;
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs
===================================================================
diff -u -r8a7fedc540b20939054fb148247f213a7b013916 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs (.../PipingFailureMechanismNodePresenter.cs) (revision 8a7fedc540b20939054fb148247f213a7b013916)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs (.../PipingFailureMechanismNodePresenter.cs) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -9,10 +9,11 @@
using Core.Common.Controls;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
+
+using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.NodePresenters;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Piping.Data;
-using Ringtoets.Piping.Forms.Helpers;
using Ringtoets.Piping.Forms.PresentationObjects;
using Ringtoets.Piping.Forms.Properties;
using Ringtoets.Piping.Service;
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -65,7 +65,6 @@
Properties\GlobalAssembly.cs
-
Fisheye: Tag 61f804a9e44dedf9c512646cf488e3761ddefac5 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Helpers/NamingHelperTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj
===================================================================
diff -u -r66c1d9f2620a134d459aca4d428b48b62ddbae23 -r61f804a9e44dedf9c512646cf488e3761ddefac5
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 66c1d9f2620a134d459aca4d428b48b62ddbae23)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 61f804a9e44dedf9c512646cf488e3761ddefac5)
@@ -64,7 +64,6 @@
-