Index: Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs =================================================================== diff -u -rd507de965210c6af40d57936780fa55b05430e13 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs (.../FailureMechanismSectionCollection.cs) (revision d507de965210c6af40d57936780fa55b05430e13) +++ Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/FailureMechanismSectionCollection.cs (.../FailureMechanismSectionCollection.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -29,6 +29,9 @@ namespace Ringtoets.Common.Data.FailureMechanism { + /// + /// A collection of . + /// public class FailureMechanismSectionCollection : Observable, IEnumerable { private readonly List sections = new List(); @@ -50,12 +53,16 @@ } /// - /// Adds all originating from a source file. + /// Sets all originating from a source file to the collection. /// - /// The collection of to add + /// The collection of to set. /// The path to the source file. /// Thrown when any parameter is null. - /// Thrown when is not a valid file path. + /// Thrown when: + /// + /// is not a valid file path. + /// contains sections that are not properly chained. + /// public void SetSections(IEnumerable failureMechanismSections, string sourcePath) { @@ -74,27 +81,29 @@ throw new ArgumentException($@"'{sourcePath}' is not a valid file path.", nameof(sourcePath)); } - Clear(); + if (!failureMechanismSections.Any()) + { + Clear(); + SourcePath = sourcePath; + return; + } - if (failureMechanismSections.Any()) + FailureMechanismSection firstSection = failureMechanismSections.First(); + var newSections = new List { - FailureMechanismSection firstSection = failureMechanismSections.First(); - var newSections = new List - { - firstSection - }; + firstSection + }; - FailureMechanismSection previousSection = firstSection; - foreach (FailureMechanismSection section in failureMechanismSections.Skip(1)) - { - ValidateSection(section, previousSection); - newSections.Add(section); - previousSection = section; - } - - sections.AddRange(newSections); + FailureMechanismSection previousSection = firstSection; + foreach (FailureMechanismSection section in failureMechanismSections.Skip(1)) + { + ValidateSection(section, previousSection); + newSections.Add(section); + previousSection = section; } + Clear(); + sections.AddRange(newSections); SourcePath = sourcePath; } Index: Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs =================================================================== diff -u -r88ba44b92caad86cf1343d9c191bc22761463c8c -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs (.../IFailureMechanism.cs) (revision 88ba44b92caad86cf1343d9c191bc22761463c8c) +++ Ringtoets/Common/src/Ringtoets.Common.Data/FailureMechanism/IFailureMechanism.cs (.../IFailureMechanism.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -96,8 +96,11 @@ /// The sections to set. /// The path of the file the sections originate from. /// Thrown when any parameter is null. - /// Thrown when cannot - /// be connected to elements already defined in . + /// Thrown when: + /// + /// is not a valid file path. + /// contains sections that are not properly chained. + /// void SetSections(IEnumerable sections, string sourcePath); /// Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismBaseTest.cs =================================================================== diff -u -ra100a49622ba13deb720c2c881906e890cb8094e -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismBaseTest.cs (.../FailureMechanismBaseTest.cs) (revision a100a49622ba13deb720c2c881906e890cb8094e) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismBaseTest.cs (.../FailureMechanismBaseTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -274,11 +274,15 @@ }); var failureMechanism = new SimpleFailureMechanismBase(); + string sourcePath = TestHelper.GetScratchPadPath(); failureMechanism.SetSections(new[] { section - }, string.Empty); + }, sourcePath); + // Precondition + Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath); + // Call failureMechanism.ClearAllSections(); Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs =================================================================== diff -u -rd507de965210c6af40d57936780fa55b05430e13 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs (.../FailureMechanismSectionCollectionTest.cs) (revision d507de965210c6af40d57936780fa55b05430e13) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/FailureMechanism/FailureMechanismSectionCollectionTest.cs (.../FailureMechanismSectionCollectionTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -143,10 +143,15 @@ } [Test] - public void SetSections_SecondSectionDoesNotConnectToFirst_ThrowsArgumentExceptionAndDoesNotSetSections() + public void SetSections_SecondSectionDoesNotConnectToFirst_ThrowsArgumentExceptionAndOldDataRemains() { // Setup var sectionCollection = new FailureMechanismSectionCollection(); + string oldPath = TestHelper.GetScratchPadPath(); + sectionCollection.SetSections(new[] + { + FailureMechanismSectionTestFactory.CreateFailureMechanismSection() + }, oldPath); var section1 = new FailureMechanismSection("A", new[] { @@ -169,8 +174,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); + Assert.AreEqual(1, sectionCollection.Count()); + Assert.AreEqual(oldPath, sectionCollection.SourcePath); } [Test] Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/FailureMechanismTestHelperTest.cs =================================================================== diff -u -rd2efd1dfcfbd8f09a47533950d3e89474ae2e1af -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/FailureMechanismTestHelperTest.cs (.../FailureMechanismTestHelperTest.cs) (revision d2efd1dfcfbd8f09a47533950d3e89474ae2e1af) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/FailureMechanismTestHelperTest.cs (.../FailureMechanismTestHelperTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -44,7 +44,7 @@ // Assert Assert.IsEmpty(failureMechanism.FailureMechanismSectionSourcePath); - Assert.AreEqual(sections.Single(), failureMechanism.Sections.Single()); + Assert.AreSame(sections.Single(), failureMechanism.Sections.Single()); } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/FailureMechanismTestHelper.cs =================================================================== diff -u -r235521fa82576e7717d74048522447a0e893af9a -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/FailureMechanismTestHelper.cs (.../FailureMechanismTestHelper.cs) (revision 235521fa82576e7717d74048522447a0e893af9a) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/FailureMechanismTestHelper.cs (.../FailureMechanismTestHelper.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -37,8 +37,8 @@ /// The failure mechanism to set the sections to. /// The sections to set. /// Thrown when is null. - /// Thrown when cannot - /// be connected to elements already defined in . + /// Thrown when contains elements that + /// are not properly connected. public static void SetSections(IFailureMechanism failureMechanism, IEnumerable sections) { failureMechanism.SetSections(sections, string.Empty); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs =================================================================== diff -u -r603210e73c97c052ba7fc2447b45cf57750a6ae4 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 603210e73c97c052ba7fc2447b45cf57750a6ae4) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -169,9 +169,10 @@ ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath); var failureMechanism = new TestFailureMechanism(); + var oldSection = new FailureMechanismSection("A", importReferenceLine.Points); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { - new FailureMechanismSection("A", importReferenceLine.Points) + oldSection }); var updateStrategy = new TestFailureMechanismSectionUpdateStrategy(); @@ -184,6 +185,7 @@ Assert.IsTrue(importSuccessful); IEnumerable sections = updateStrategy.ImportedFailureMechanismSections; + CollectionAssert.DoesNotContain(sections, oldSection); Assert.AreEqual(62, sections.Count()); AssertSectionsAreValidForReferenceLine(sections, importReferenceLine); mocks.VerifyAll(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r9d464742b12df2c1a1779e74b8e289eed5045e91 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismContextTreeNodeInfoTest.cs (.../FailureMechanismContextTreeNodeInfoTest.cs) (revision 9d464742b12df2c1a1779e74b8e289eed5045e91) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/FailureMechanismContextTreeNodeInfoTest.cs (.../FailureMechanismContextTreeNodeInfoTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -238,11 +238,7 @@ { IsRelevant = false }; - FailureMechanismTestHelper.SetSections(failureMechanism, new [] {new FailureMechanismSection("A", new[] - { - new Point2D(1, 2), - new Point2D(5, 6) - })}); + var failureMechanismContext = new FailureMechanismContext(failureMechanism, assessmentSection); // Call @@ -498,10 +494,10 @@ TreeNodeInfo info = GetInfo(plugin); var failureMechanism = mocks.StrictMultiMock>(typeof(IFailureMechanism)); - failureMechanism.Expect(fm => ((IFailureMechanism) fm).IsRelevant).Return(true); + failureMechanism.Expect(fm => fm.IsRelevant).Return(true); failureMechanism.Expect(fm => fm.SectionResults).Return(new ObservableList()).Repeat.Any(); - failureMechanism.Expect(fm => ((IFailureMechanism) fm).InputComments).Return(new Comment()); - failureMechanism.Expect(fm => ((IFailureMechanism) fm).OutputComments).Return(new Comment()); + failureMechanism.Expect(fm => fm.InputComments).Return(new Comment()); + failureMechanism.Expect(fm => fm.OutputComments).Return(new Comment()); var failureMechanismContext = mocks.Stub>(failureMechanism, assessmentSection); mocks.ReplayAll(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r9d464742b12df2c1a1779e74b8e289eed5045e91 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs (.../MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 9d464742b12df2c1a1779e74b8e289eed5045e91) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs (.../MacroStabilityOutwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -214,14 +214,7 @@ { IsRelevant = false }; - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - new FailureMechanismSection("A", new[] - { - new Point2D(1, 2), - new Point2D(5, 6) - }) - }); + var failureMechanismContext = new MacroStabilityOutwardsFailureMechanismContext(failureMechanism, assessmentSection); // Call Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/PipingStructureFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r9d464742b12df2c1a1779e74b8e289eed5045e91 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/PipingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../PipingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision 9d464742b12df2c1a1779e74b8e289eed5045e91) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/TreeNodeInfos/PipingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../PipingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -210,14 +210,7 @@ { IsRelevant = false }; - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - new FailureMechanismSection("A", new[] - { - new Point2D(1, 2), - new Point2D(5, 6) - }) - }); + var failureMechanismContext = new PipingStructureFailureMechanismContext(failureMechanism, assessmentSection); // Call Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs =================================================================== diff -u -r0d301f769dc84d57979a55d902c498afe5d93e19 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (.../MacroStabilityInwardsCalculationsViewTest.cs) (revision 0d301f769dc84d57979a55d902c498afe5d93e19) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsCalculationsViewTest.cs (.../MacroStabilityInwardsCalculationsViewTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -1340,20 +1340,20 @@ }); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - const string arbitrary = "path"; + const string sourcePath = "path"; failureMechanism.SurfaceLines.AddRange(new[] { surfaceLine1, surfaceLine2 - }, arbitrary); + }, sourcePath); failureMechanism.StochasticSoilModels.AddRange(new[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name", new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 0.0) }) - }, arbitrary); + }, sourcePath); FailureMechanismTestHelper.SetSections(failureMechanism, new[] { Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r6bc9f77c55e1fba2e86203b22778f8a405aee2eb -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailureMechanismContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 6bc9f77c55e1fba2e86203b22778f8a405aee2eb) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsFailureMechanismContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -214,8 +214,6 @@ { IsRelevant = false }; - failureMechanism.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario()); - failureMechanism.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario()); var failureMechanismContext = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection); Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r9395ef9c44963521a3d8a81cda0a040e7d08c589 -r2c6d254976145b223c6055b0b8c0c8303f8038a1 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingFailureMechanismContextTreeNodeInfoTest.cs (.../PipingFailureMechanismContextTreeNodeInfoTest.cs) (revision 9395ef9c44963521a3d8a81cda0a040e7d08c589) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/TreeNodeInfos/PipingFailureMechanismContextTreeNodeInfoTest.cs (.../PipingFailureMechanismContextTreeNodeInfoTest.cs) (revision 2c6d254976145b223c6055b0b8c0c8303f8038a1) @@ -210,13 +210,10 @@ var assessmentSection = mocks.Stub(); mocks.ReplayAll(); - var generalInputParameters = new GeneralPipingInput(); var pipingFailureMechanism = new PipingFailureMechanism { IsRelevant = false }; - pipingFailureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(generalInputParameters)); - pipingFailureMechanism.CalculationsGroup.Children.Add(new PipingCalculationScenario(generalInputParameters)); var pipingFailureMechanismContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection);