Index: Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs =================================================================== diff -u -r4b2daa16b6b210d5d5c9a5f8f2a10a610add4eb1 -rd507de965210c6af40d57936780fa55b05430e13 --- Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs (.../FailureMechanismSectionCollection.cs) (revision 4b2daa16b6b210d5d5c9a5f8f2a10a610add4eb1) +++ Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs (.../FailureMechanismSectionCollection.cs) (revision d507de965210c6af40d57936780fa55b05430e13) @@ -29,7 +29,7 @@ namespace Ringtoets.Common.Data.FailureMechanism { - public class FailureMechanismSectionCollection : Observable, IObservableEnumerable + public class FailureMechanismSectionCollection : Observable, IEnumerable { private readonly List sections = new List(); @@ -76,19 +76,23 @@ Clear(); - List sourceCollection = failureMechanismSections.ToList(); - if (!sourceCollection.Any()) + if (failureMechanismSections.Any()) { - return; - } + FailureMechanismSection firstSection = failureMechanismSections.First(); + var newSections = new List + { + firstSection + }; - FailureMechanismSection firstSection = sourceCollection.First(); - sections.Add(firstSection); - sourceCollection.Remove(firstSection); + FailureMechanismSection previousSection = firstSection; + foreach (FailureMechanismSection section in failureMechanismSections.Skip(1)) + { + ValidateSection(section, previousSection); + newSections.Add(section); + previousSection = section; + } - foreach (FailureMechanismSection section in sourceCollection) - { - InsertSectionWhileMaintainingConnectivityOrder(section); + sections.AddRange(newSections); } SourcePath = sourcePath; @@ -105,24 +109,21 @@ } /// - /// Inserts the section to the collection while maintaining connectivity - /// order (neighboring have same end points). + /// Validates the section on its connectivity order (neighboring + /// must have same end points). /// - /// The new section. - /// Thrown when cannot - /// be connected to elements already defined in this collection. - private void InsertSectionWhileMaintainingConnectivityOrder(FailureMechanismSection sectionToInsert) + /// The new section. + /// The previous section. + /// Thrown when cannot + /// be connected to the previous section. + private static void ValidateSection(FailureMechanismSection section, FailureMechanismSection previousSection) { - if (sections.Last().EndPoint.Equals(sectionToInsert.StartPoint)) + if (!previousSection.EndPoint.Equals(section.StartPoint)) { - sections.Add(sectionToInsert); + string message = string.Format(Resources.FailureMechanismSectionCollection_ValidateSection_Section_0_must_connect_to_existing_sections, + section.Name); + throw new ArgumentException(message, nameof(section)); } - else - { - string message = string.Format(Resources.BaseFailureMechanism_AddSection_Section_0_must_connect_to_existing_sections, - sectionToInsert.Name); - throw new ArgumentException(message, nameof(sectionToInsert)); - } } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r42750c3eeb3410d3cd559ac0cb1a899efbaa1659 -rd507de965210c6af40d57936780fa55b05430e13 --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 42750c3eeb3410d3cd559ac0cb1a899efbaa1659) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d507de965210c6af40d57936780fa55b05430e13) @@ -164,15 +164,6 @@ } /// - /// Looks up a localized string similar to Vak '{0}' sluit niet aan op de al gedefinieerde vakken van het toetsspoor.. - /// - public static string BaseFailureMechanism_AddSection_Section_0_must_connect_to_existing_sections { - get { - return ResourceManager.GetString("BaseFailureMechanism_AddSection_Section_0_must_connect_to_existing_sections", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Caisson. /// public static string BreakWaterType_Caisson_DisplayName { @@ -547,6 +538,16 @@ } /// + /// Looks up a localized string similar to Vak '{0}' sluit niet aan op de al gedefinieerde vakken van het toetsspoor.. + /// + public static string FailureMechanismSectionCollection_ValidateSection_Section_0_must_connect_to_existing_sections { + get { + return ResourceManager.GetString("FailureMechanismSectionCollection_ValidateSection_Section_0_must_connect_to_exist" + + "ing_sections", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De waarde voor de faalkans moet in het bereik {0} liggen.. /// public static string FailureProbability_Value_needs_to_be_in_Range_0_ { Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx =================================================================== diff -u -r42750c3eeb3410d3cd559ac0cb1a899efbaa1659 -rd507de965210c6af40d57936780fa55b05430e13 --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision 42750c3eeb3410d3cd559ac0cb1a899efbaa1659) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision d507de965210c6af40d57936780fa55b05430e13) @@ -126,7 +126,7 @@ Een punt in de geometrie voor de referentielijn heeft geen waarde. - + Vak '{0}' sluit niet aan op de al gedefinieerde vakken van het toetsspoor. Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs =================================================================== diff -u -r4b2daa16b6b210d5d5c9a5f8f2a10a610add4eb1 -rd507de965210c6af40d57936780fa55b05430e13 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs (.../FailureMechanismSectionCollectionTest.cs) (revision 4b2daa16b6b210d5d5c9a5f8f2a10a610add4eb1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs (.../FailureMechanismSectionCollectionTest.cs) (revision d507de965210c6af40d57936780fa55b05430e13) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Core.Common.Base; using Core.Common.Base.Geometry; @@ -40,7 +41,7 @@ var sectionCollection = new FailureMechanismSectionCollection(); // Assert - Assert.IsInstanceOf>(sectionCollection); + Assert.IsInstanceOf>(sectionCollection); Assert.IsInstanceOf(sectionCollection); Assert.IsNull(sectionCollection.SourcePath); CollectionAssert.IsEmpty(sectionCollection); @@ -108,7 +109,7 @@ } [Test] - public void SetSections_SecondSectionEndConnectingToStartOfFirst_ThrowArgumentException() + public void SetSections_SecondSectionEndConnectingToStartOfFirst_ThrowsArgumentExceptionAndDoesNotSetSections() { // Setup var sectionCollection = new FailureMechanismSectionCollection(); @@ -137,10 +138,12 @@ // Assert const string expectedMessage = "Vak 'B' sluit niet aan op de al gedefinieerde vakken van het toetsspoor."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + CollectionAssert.IsEmpty(sectionCollection); + Assert.IsNull(sectionCollection.SourcePath); } [Test] - public void SetSections_SecondSectionDoesNotConnectToFirst_ThrowArgumentException() + public void SetSections_SecondSectionDoesNotConnectToFirst_ThrowsArgumentExceptionAndDoesNotSetSections() { // Setup var sectionCollection = new FailureMechanismSectionCollection(); @@ -166,6 +169,8 @@ // Assert const string expectedMessage = "Vak 'B' sluit niet aan op de al gedefinieerde vakken van het toetsspoor."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + CollectionAssert.IsEmpty(sectionCollection); + Assert.IsNull(sectionCollection.SourcePath); } [Test] @@ -204,5 +209,20 @@ }, sectionCollection); Assert.AreEqual(sourcePath, sectionCollection.SourcePath); } + + [Test] + public void SetSections_WithEmptySectionCollection_SourcePathSet() + { + // Setup + string sourcePath = TestHelper.GetScratchPadPath(); + var sectionCollection = new FailureMechanismSectionCollection(); + + // Call + sectionCollection.SetSections(Enumerable.Empty(), sourcePath); + + // Assert + CollectionAssert.IsEmpty(sectionCollection); + Assert.AreEqual(sourcePath, sectionCollection.SourcePath); + } } } \ No newline at end of file