Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Helpers/NamingHelper.cs
===================================================================
diff -u
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Helpers/NamingHelper.cs (revision 0)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Helpers/NamingHelper.cs (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Ringtoets.Piping.Forms.Helpers
+{
+ ///
+ /// Helper class for generating unique names.
+ ///
+ /// Has been created due to being obsolete.
+ 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: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs
===================================================================
diff -u -r464b6d664be0b6c7cef0b141f40f51bcef2217ac -r617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs (.../PipingFailureMechanismNodePresenter.cs) (revision 464b6d664be0b6c7cef0b141f40f51bcef2217ac)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/NodePresenters/PipingFailureMechanismNodePresenter.cs (.../PipingFailureMechanismNodePresenter.cs) (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -7,6 +7,7 @@
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms.Extensions;
+using Ringtoets.Piping.Forms.Helpers;
using Ringtoets.Piping.Forms.PresentationObjects;
using Ringtoets.Piping.Forms.Properties;
using Ringtoets.Piping.Service;
@@ -88,12 +89,16 @@
var rootMenu = new ContextMenuStrip();
rootMenu.AddMenuItem("Berekening toevoegen", "Voeg een nieuwe piping berekening toe aan het faalmechanisme.",
- Resources.PipingIcon, (o, args) =>
- {
- var failureMechanism = (PipingFailureMechanism)nodeData;
- failureMechanism.Calculations.Add(new PipingData());
- failureMechanism.NotifyObservers();
- });
+ Resources.PipingIcon, (o, args) =>
+ {
+ var failureMechanism = (PipingFailureMechanism)nodeData;
+ var pipingData = new PipingData
+ {
+ Name = NamingHelper.GetUniqueName(failureMechanism.Calculations, "Piping", pd => pd.Name)
+ };
+ failureMechanism.Calculations.Add(pipingData);
+ failureMechanism.NotifyObservers();
+ });
rootMenu.AddMenuItem("Berekenen", "Valideer en vervolgens reken all piping berekeningen door in het faalmechanisme.",
Resources.PlayAll, (o, args) =>
{
Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj
===================================================================
diff -u -rb02b755bf5d7a52b44deb11bdb9b1e70789306a0 -r617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4
--- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision b02b755bf5d7a52b44deb11bdb9b1e70789306a0)
+++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -52,6 +52,7 @@
Properties\GlobalAssembly.cs
+
Component
Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Helpers/NamingHelperTest.cs
===================================================================
diff -u
--- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Helpers/NamingHelperTest.cs (revision 0)
+++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Helpers/NamingHelperTest.cs (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -0,0 +1,88 @@
+using System.Linq;
+
+using NUnit.Framework;
+
+using Ringtoets.Piping.Forms.Helpers;
+
+namespace Ringtoets.Piping.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: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs
===================================================================
diff -u -r464b6d664be0b6c7cef0b141f40f51bcef2217ac -r617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4
--- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs (.../PipingFailureMechanismNodePresenterTest.cs) (revision 464b6d664be0b6c7cef0b141f40f51bcef2217ac)
+++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/NodePresenters/PipingFailureMechanismNodePresenterTest.cs (.../PipingFailureMechanismNodePresenterTest.cs) (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -307,6 +307,7 @@
// Assert
Assert.AreEqual(2, failureMechanism.Calculations.Count);
+ Assert.AreEqual("Piping (1)", failureMechanism.Calculations.ElementAt(1).Name);
mocks.VerifyAll();
}
Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj
===================================================================
diff -u -rb02b755bf5d7a52b44deb11bdb9b1e70789306a0 -r617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4
--- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision b02b755bf5d7a52b44deb11bdb9b1e70789306a0)
+++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision 617e40b29b2e1f5b5d2ad5abaeb4c6ad8ccffee4)
@@ -46,6 +46,7 @@
+