Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismView.cs =================================================================== diff -u -rc37eebd9171a53987f5929013edbe3d82e618ed0 -rfa2295dde23d04462bdf01b6bdf9a40af554b877 --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision c37eebd9171a53987f5929013edbe3d82e618ed0) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismView.cs (.../PipingFailureMechanismView.cs) (revision fa2295dde23d04462bdf01b6bdf9a40af554b877) @@ -47,7 +47,6 @@ /// public partial class PipingFailureMechanismView : UserControl, IMapView { - private MapDataCollection mapDataCollection; private MapLineData referenceLineMapData; private MapLineData stochasticSoilModelsMapData; private MapLineData surfaceLinesMapData; @@ -59,11 +58,6 @@ private MapPointData sectionsStartPointMapData; private MapPointData sectionsEndPointMapData; - private MapLineData simpleAssemblyMapData; - private MapLineData detailedAssemblyMapData; - private MapLineData tailorMadeAssemblyMapData; - private MapLineData combinedAssemblyMapData; - private Observer failureMechanismObserver; private Observer hydraulicBoundaryLocationsObserver; private Observer assessmentSectionObserver; @@ -85,7 +79,6 @@ private RecursiveObserver semiProbabilisticCalculationObserver; private RecursiveObserver probabilisticCalculationObserver; private RecursiveObserver surfaceLineObserver; - private RecursiveObserver, PipingFailureMechanismSectionResult> sectionResultObserver; /// /// Creates a new instance of . @@ -114,7 +107,6 @@ CreateMapData(); SetAllMapDataFeatures(); - riskeerMapControl.SetAllData(mapDataCollection, AssessmentSection.BackgroundData); } /// @@ -137,6 +129,15 @@ } } + protected MapDataCollection MapDataCollection { get; set; } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + riskeerMapControl.SetAllData(MapDataCollection, AssessmentSection.BackgroundData); + } + protected override void Dispose(bool disposing) { failureMechanismObserver.Dispose(); @@ -159,7 +160,6 @@ probabilisticCalculationObserver.Dispose(); surfaceLinesObserver.Dispose(); surfaceLineObserver.Dispose(); - sectionResultObserver.Dispose(); if (disposing) { @@ -171,7 +171,7 @@ private void CreateMapData() { - mapDataCollection = new MapDataCollection(PipingDataResources.PipingFailureMechanism_DisplayName); + MapDataCollection = new MapDataCollection(PipingDataResources.PipingFailureMechanism_DisplayName); referenceLineMapData = RiskeerMapDataFactory.CreateReferenceLineMapData(); hydraulicBoundaryLocationsMapData = RiskeerMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); stochasticSoilModelsMapData = RiskeerMapDataFactory.CreateStochasticSoilModelsMapData(); @@ -184,30 +184,18 @@ sectionsStartPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); sectionsEndPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); - MapDataCollection assemblyMapDataCollection = AssemblyMapDataFactory.CreateAssemblyMapDataCollection(); - tailorMadeAssemblyMapData = AssemblyMapDataFactory.CreateTailorMadeAssemblyMapData(); - detailedAssemblyMapData = AssemblyMapDataFactory.CreateDetailedAssemblyMapData(); - simpleAssemblyMapData = AssemblyMapDataFactory.CreateSimpleAssemblyMapData(); - combinedAssemblyMapData = AssemblyMapDataFactory.CreateCombinedAssemblyMapData(); + MapDataCollection.Add(referenceLineMapData); + MapDataCollection.Add(stochasticSoilModelsMapData); + MapDataCollection.Add(surfaceLinesMapData); - mapDataCollection.Add(referenceLineMapData); - mapDataCollection.Add(stochasticSoilModelsMapData); - mapDataCollection.Add(surfaceLinesMapData); - sectionsMapDataCollection.Add(sectionsMapData); sectionsMapDataCollection.Add(sectionsStartPointMapData); sectionsMapDataCollection.Add(sectionsEndPointMapData); - mapDataCollection.Add(sectionsMapDataCollection); + MapDataCollection.Add(sectionsMapDataCollection); - assemblyMapDataCollection.Add(tailorMadeAssemblyMapData); - assemblyMapDataCollection.Add(detailedAssemblyMapData); - assemblyMapDataCollection.Add(simpleAssemblyMapData); - assemblyMapDataCollection.Add(combinedAssemblyMapData); - mapDataCollection.Add(assemblyMapDataCollection); - - mapDataCollection.Add(hydraulicBoundaryLocationsMapData); - mapDataCollection.Add(probabilisticCalculationsMapData); - mapDataCollection.Add(semiProbabilisticCalculationsMapData); + MapDataCollection.Add(hydraulicBoundaryLocationsMapData); + MapDataCollection.Add(probabilisticCalculationsMapData); + MapDataCollection.Add(semiProbabilisticCalculationsMapData); } private void CreateObservers() @@ -284,11 +272,6 @@ { Observable = FailureMechanism.SurfaceLines }; - - sectionResultObserver = new RecursiveObserver, PipingFailureMechanismSectionResult>(UpdateAssemblyMapData, sr => sr) - { - Observable = FailureMechanism.SectionResults - }; } private void SetAllMapDataFeatures() @@ -301,39 +284,14 @@ SetSectionsMapData(); SetSurfaceLinesMapData(); SetStochasticSoilModelsMapData(); - - SetAssemblyMapData(); } - #region Assembly MapData - - private void UpdateAssemblyMapData() - { - SetAssemblyMapData(); - simpleAssemblyMapData.NotifyObservers(); - detailedAssemblyMapData.NotifyObservers(); - tailorMadeAssemblyMapData.NotifyObservers(); - combinedAssemblyMapData.NotifyObservers(); - } - - private void SetAssemblyMapData() - { - simpleAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(FailureMechanism); - detailedAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(FailureMechanism, AssessmentSection); - tailorMadeAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(FailureMechanism, AssessmentSection); - combinedAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(FailureMechanism, AssessmentSection); - } - - #endregion - #region Calculations MapData private void UpdateSemiProbabilisticCalculationsMapData() { SetCalculationsMapData(semiProbabilisticCalculationsMapData); semiProbabilisticCalculationsMapData.NotifyObservers(); - - UpdateAssemblyMapData(); } private void UpdateProbabilisticCalculationsMapData() @@ -391,8 +349,6 @@ sectionsMapData.NotifyObservers(); sectionsStartPointMapData.NotifyObservers(); sectionsEndPointMapData.NotifyObservers(); - - UpdateAssemblyMapData(); } private void SetSectionsMapData() Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailurePathView.cs =================================================================== diff -u --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailurePathView.cs (revision 0) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailurePathView.cs (revision fa2295dde23d04462bdf01b6bdf9a40af554b877) @@ -0,0 +1,115 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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; +using Core.Common.Base; +using Core.Components.Gis.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Forms.Factories; +using Riskeer.Piping.Data; +using Riskeer.Piping.Forms.Factories; +using PipingDataResources = Riskeer.Piping.Data.Properties.Resources; + +namespace Riskeer.Piping.Forms.Views +{ + /// + /// This class is a view showing map data for a piping failure path. + /// + public class PipingFailurePathView : PipingFailureMechanismView + { + private MapLineData simpleAssemblyMapData; + private MapLineData detailedAssemblyMapData; + private MapLineData tailorMadeAssemblyMapData; + private MapLineData combinedAssemblyMapData; + + private RecursiveObserver, PipingFailureMechanismSectionResult> sectionResultObserver; + + /// + /// Creates a new instance of . + /// + /// The failure mechanism to show the data for. + /// The assessment section to show the data for. + /// Thrown when any parameter is null. + public PipingFailurePathView(PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) : base(failureMechanism, assessmentSection) + { + CreateObservers(); + + CreateMapData(); + SetAllMapDataFeatures(); + } + + protected override void Dispose(bool disposing) + { + sectionResultObserver.Dispose(); + + base.Dispose(disposing); + } + + private void CreateMapData() + { + MapDataCollection assemblyMapDataCollection = AssemblyMapDataFactory.CreateAssemblyMapDataCollection(); + tailorMadeAssemblyMapData = AssemblyMapDataFactory.CreateTailorMadeAssemblyMapData(); + detailedAssemblyMapData = AssemblyMapDataFactory.CreateDetailedAssemblyMapData(); + simpleAssemblyMapData = AssemblyMapDataFactory.CreateSimpleAssemblyMapData(); + combinedAssemblyMapData = AssemblyMapDataFactory.CreateCombinedAssemblyMapData(); + + assemblyMapDataCollection.Add(tailorMadeAssemblyMapData); + assemblyMapDataCollection.Add(detailedAssemblyMapData); + assemblyMapDataCollection.Add(simpleAssemblyMapData); + assemblyMapDataCollection.Add(combinedAssemblyMapData); + MapDataCollection.Insert(4, assemblyMapDataCollection); + } + + private void CreateObservers() + { + sectionResultObserver = new RecursiveObserver, PipingFailureMechanismSectionResult>(UpdateAssemblyMapData, sr => sr) + { + Observable = FailureMechanism.SectionResults + }; + } + + private void SetAllMapDataFeatures() + { + SetAssemblyMapData(); + } + + #region Assembly MapData + + private void UpdateAssemblyMapData() + { + SetAssemblyMapData(); + simpleAssemblyMapData.NotifyObservers(); + detailedAssemblyMapData.NotifyObservers(); + tailorMadeAssemblyMapData.NotifyObservers(); + combinedAssemblyMapData.NotifyObservers(); + } + + private void SetAssemblyMapData() + { + simpleAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(FailureMechanism); + detailedAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(FailureMechanism, AssessmentSection); + tailorMadeAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(FailureMechanism, AssessmentSection); + combinedAssemblyMapData.Features = PipingAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(FailureMechanism, AssessmentSection); + } + + #endregion + } +} \ No newline at end of file Index: Riskeer/Piping/src/Riskeer.Piping.Plugin/PipingPlugin.cs =================================================================== diff -u -r946da8d4431742e51b1a30ea2fcfe0243c0d9848 -rfa2295dde23d04462bdf01b6bdf9a40af554b877 --- Riskeer/Piping/src/Riskeer.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision 946da8d4431742e51b1a30ea2fcfe0243c0d9848) +++ Riskeer/Piping/src/Riskeer.Piping.Plugin/PipingPlugin.cs (.../PipingPlugin.cs) (revision fa2295dde23d04462bdf01b6bdf9a40af554b877) @@ -253,6 +253,15 @@ CreateInstance = context => new PipingFailureMechanismView(context.WrappedData, context.Parent) }; + yield return new ViewInfo + { + GetViewName = (view, context) => context.WrappedData.Name, + Image = RiskeerCommonFormsResources.FailureMechanismIcon, + CloseForData = ClosePipingFailureMechanismViewForData, + AdditionalDataCheck = context => context.WrappedData.IsRelevant, + CreateInstance = context => new PipingFailurePathView(context.WrappedData, context.Parent) + }; + yield return new ViewInfo< ProbabilityFailureMechanismSectionResultContext, IObservableEnumerable, Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailurePathViewTest.cs =================================================================== diff -u --- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailurePathViewTest.cs (revision 0) +++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingFailurePathViewTest.cs (revision fa2295dde23d04462bdf01b6bdf9a40af554b877) @@ -0,0 +1,1407 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.Probabilistic; +using Riskeer.Piping.Data.SemiProbabilistic; +using Riskeer.Piping.Data.SoilProfile; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Data.TestUtil.Probabilistic; +using Riskeer.Piping.Data.TestUtil.SemiProbabilistic; +using Riskeer.Piping.Forms.Views; +using Riskeer.Piping.Primitives; + +namespace Riskeer.Piping.Forms.Test.Views +{ + [TestFixture] + public class PipingFailureMechanismViewTest + { + private const int referenceLineIndex = 0; + private const int stochasticSoilModelsIndex = 1; + private const int surfaceLinesIndex = 2; + private const int sectionsCollectionIndex = 3; + private const int assemblyResultsIndex = 4; + private const int hydraulicBoundaryLocationsIndex = 5; + private const int probabilisticCalculationsIndex = 6; + private const int semiProbabilisticCalculationsIndex = 7; + + private const int sectionsIndex = 0; + private const int sectionsStartPointIndex = 1; + private const int sectionsEndPointIndex = 2; + + private const int tailorMadeAssemblyIndex = 0; + private const int detailedAssemblyIndex = 1; + private const int simpleAssemblyIndex = 2; + private const int combinedAssemblyIndex = 3; + + private const int hydraulicBoundaryLocationsObserverIndex = 3; + private const int semiProbabilisticCalculationObserverIndex = 4; + private const int probabilisticCalculationObserverIndex = 5; + private const int sectionsObserverIndex = 6; + private const int sectionsStartPointObserverIndex = 7; + private const int sectionsEndPointObserverIndex = 8; + private const int simpleAssemblyObserverIndex = 9; + private const int detailedAssemblyObserverIndex = 10; + private const int tailorMadeAssemblyObserverIndex = 11; + private const int combinedAssemblyObserverIndex = 12; + + [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new PipingFailureMechanismView(null, assessmentSection); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new PipingFailureMechanismView(new PipingFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + using (var view = new PipingFailureMechanismView(failureMechanism, assessmentSection)) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + + Assert.AreEqual(1, view.Controls.Count); + Assert.IsInstanceOf(view.Controls[0]); + Assert.AreSame(view.Map, ((RiskeerMapControl) view.Controls[0]).MapControl); + Assert.AreEqual(DockStyle.Fill, ((Control) view.Map).Dock); + AssertEmptyMapData(view.Map.Data); + } + } + + [Test] + public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + + // Call + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); + } + } + + [Test] + public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var random = new Random(39); + + PipingStochasticSoilModel stochasticSoilModel1 = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name1", new[] + { + new Point2D(1.0, 2.0), + new Point2D(1.1, 2.2) + }); + + PipingStochasticSoilModel stochasticSoilModel2 = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("name2", new[] + { + new Point2D(3.0, 4.0), + new Point2D(3.3, 4.4) + }); + + var surfaceLineA = new PipingSurfaceLine("Line A"); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine("Name B"); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var failureMechanism = new PipingFailureMechanism(); + const string arbitraryFilePath = "path"; + var geometryPoints = new[] + { + new Point2D(0.0, 0.0), + new Point2D(2.0, 0.0), + new Point2D(4.0, 4.0), + new Point2D(6.0, 4.0) + }; + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLineA, + surfaceLineB + }, arbitraryFilePath); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + new FailureMechanismSection("A", geometryPoints.Take(2)), + new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), + new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) + }); + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel1, + stochasticSoilModel2 + }, arbitraryFilePath); + + var hydraulicBoundaryLocation1 = new HydraulicBoundaryLocation(1, "test", 1.0, 2.0); + var hydraulicBoundaryLocation2 = new HydraulicBoundaryLocation(2, "test", 3.0, 4.0); + + var calculationA = + SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + hydraulicBoundaryLocation1); + var calculationB = + ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + hydraulicBoundaryLocation2); + + calculationA.InputParameters.SurfaceLine = surfaceLineA; + calculationB.InputParameters.SurfaceLine = surfaceLineB; + + failureMechanism.CalculationsGroup.Children.Add(calculationA); + failureMechanism.CalculationsGroup.Children.Add(calculationB); + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(0.0, 3.0), + new Point2D(3.0, 0.0) + }); + + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + }); + + var expectedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = expectedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = expectedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = expectedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = expectedCombinedAssembly; + + // Call + using (var view = new PipingFailureMechanismView(failureMechanism, assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + // Assert + MapDataCollection mapData = map.Data; + Assert.IsInstanceOf(mapData); + + List mapDataList = mapData.Collection.ToList(); + Assert.AreEqual(8, mapDataList.Count); + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + AssertSurfaceLinesMapData(failureMechanism.SurfaceLines, mapDataList[surfaceLinesIndex]); + + IEnumerable sectionsCollection = ((MapDataCollection) mapDataList[sectionsCollectionIndex]).Collection; + MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsIndex)); + MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsStartPointIndex)); + MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsEndPointIndex)); + + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); + AssertStochasticSoilModelsMapData(failureMechanism.StochasticSoilModels, mapDataList[stochasticSoilModelsIndex]); + AssertProbabilisticCalculationsMapData(failureMechanism.Calculations.OfType(), mapDataList[probabilisticCalculationsIndex]); + AssertSemiProbabilisticCalculationsMapData(failureMechanism.Calculations.OfType(), mapDataList[semiProbabilisticCalculationsIndex]); + + MapDataTestHelper.AssertAssemblyMapDataCollection(expectedSimpleAssembly, + expectedDetailedAssembly, + expectedTailorMadeAssembly, + expectedCombinedAssembly, + (MapDataCollection) mapDataList[assemblyResultsIndex], + failureMechanism); + } + } + } + + [Test] + public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationsUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var assessmentSection = new AssessmentSectionStub(); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + }); + + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + + // When + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) + }); + assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.VerifyAll(); + } + } + + [Test] + [TestCaseSource(typeof(MapViewTestHelper), nameof(MapViewTestHelper.GetCalculationFuncs))] + public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationCalculationUpdatedAndNotified_ThenMapDataUpdated( + Func getCalculationFunc) + { + // Given + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); + var assessmentSection = new AssessmentSectionStub(); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation + }); + + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + + // When + HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection); + calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble()); + calculation.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithAssessmentSectionData_WhenAssessmentSectionUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + var referenceLineMapData = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + + // Precondition + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + + // When + assessmentSection.Name = "New name"; + assessmentSection.NotifyObservers(); + + // Then + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); + + // Precondition + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + + // When + referenceLine.SetGeometry(new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }); + referenceLine.NotifyObservers(); + + // Then + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithSurfaceLinesData_WhenSurfaceLinesUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + var surfaceLine = new PipingSurfaceLine(string.Empty); + + surfaceLine.SetGeometry(new Collection + { + new Point3D(1, 2, 3), + new Point3D(4, 5, 6) + }); + + var surfaceLineMapData = (MapLineData) map.Data.Collection.ElementAt(surfaceLinesIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[surfaceLinesIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "path"); + failureMechanism.SurfaceLines.NotifyObservers(); + + // Then + AssertSurfaceLinesMapData(failureMechanism.SurfaceLines, surfaceLineMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithSurfaceLineData_WhenSurfaceLineUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var surfaceLine = new PipingSurfaceLine(string.Empty); + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "path"); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[surfaceLinesIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + surfaceLine.SetGeometry(new[] + { + new Point3D(7, 8, 9), + new Point3D(10, 11, 12) + }); + surfaceLine.NotifyObservers(); + + // Then + var surfaceLineMapData = (MapLineData) map.Data.Collection.ElementAt(surfaceLinesIndex); + AssertSurfaceLinesMapData(failureMechanism.SurfaceLines, surfaceLineMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismSectionsUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + IEnumerable sectionsCollection = ((MapDataCollection) map.Data.Collection.ElementAt(sectionsCollectionIndex)).Collection; + var sectionMapData = (MapLineData) sectionsCollection.ElementAt(sectionsIndex); + var sectionStartsMapData = (MapPointData) sectionsCollection.ElementAt(sectionsStartPointIndex); + var sectionsEndsMapData = (MapPointData) sectionsCollection.ElementAt(sectionsEndPointIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + new FailureMechanismSection(string.Empty, new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + }) + }); + failureMechanism.NotifyObservers(); + + // Then + MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData); + MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData); + MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithStochasticSoilModels_WhenStochasticSoilModelsUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("", new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + }); + + var stochasticSoilModelMapData = (MapLineData) map.Data.Collection.ElementAt(stochasticSoilModelsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[stochasticSoilModelsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + failureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }, "path"); + failureMechanism.StochasticSoilModels.NotifyObservers(); + + // Then + AssertStochasticSoilModelsMapData(failureMechanism.StochasticSoilModels, stochasticSoilModelMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculationA = + SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + var calculationB = + ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculationA.InputParameters.SurfaceLine = surfaceLineA; + calculationB.InputParameters.SurfaceLine = surfaceLineB; + + failureMechanism.CalculationsGroup.Children.Add(calculationA); + failureMechanism.CalculationsGroup.Children.Add(calculationB); + + var probabilisticCalculationMapData = (MapLineData) map.Data.Collection.ElementAt(probabilisticCalculationsIndex); + var semiProbabilisticCalculationMapData = (MapLineData) map.Data.Collection.ElementAt(semiProbabilisticCalculationsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[semiProbabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[probabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + failureMechanism.CalculationsGroup.Children.Add(calculationB); + failureMechanism.CalculationsGroup.NotifyObservers(); + + // Then + AssertSemiProbabilisticCalculationsMapData(failureMechanism.Calculations.OfType(), semiProbabilisticCalculationMapData); + AssertProbabilisticCalculationsMapData(failureMechanism.Calculations.OfType(), probabilisticCalculationMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithSemiProbabilisticCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculationScenario = + SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculationScenario.InputParameters.SurfaceLine = surfaceLineA; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(semiProbabilisticCalculationsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[semiProbabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + calculationScenario.InputParameters.SurfaceLine = surfaceLineB; + calculationScenario.InputParameters.NotifyObservers(); + + // Then + AssertSemiProbabilisticCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithProbabilisticCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculationScenario = + ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculationScenario.InputParameters.SurfaceLine = surfaceLineA; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(probabilisticCalculationsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[probabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + calculationScenario.InputParameters.SurfaceLine = surfaceLineB; + calculationScenario.InputParameters.NotifyObservers(); + + // Then + AssertProbabilisticCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithSemiProbabilisticCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculationScenario = + SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculationScenario.InputParameters.SurfaceLine = surfaceLineA; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(semiProbabilisticCalculationsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[semiProbabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + calculationScenario.Name = "new name"; + calculationScenario.NotifyObservers(); + + // Then + AssertSemiProbabilisticCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithProbabilisticCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculationScenario = + ProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculationScenario.InputParameters.SurfaceLine = surfaceLineA; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationScenario); + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(probabilisticCalculationsIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[probabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + calculationScenario.Name = "new name"; + calculationScenario.NotifyObservers(); + + // Then + AssertProbabilisticCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + } + + [Test] + public void GivenViewWithAssemblyData_WhenFailureMechanismNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + failureMechanism.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + } + + [Test] + public void GivenViewWithAssemblyData_WhenSemiProbabilisticCalculationNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var surfaceLineA = new PipingSurfaceLine(string.Empty); + surfaceLineA.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.0), + new Point3D(3.0, 0.0, 1.7) + }); + + var surfaceLineB = new PipingSurfaceLine(string.Empty); + surfaceLineB.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 1.5), + new Point3D(3.0, 0.0, 1.8) + }); + surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); + surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); + + var calculation = + SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput( + new TestHydraulicBoundaryLocation()); + + calculation.InputParameters.SurfaceLine = surfaceLineA; + + var failureMechanism = new PipingFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculation); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[semiProbabilisticCalculationObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + calculation.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + } + + [Test] + public void GivenViewWithAssemblyData_WhenFailureMechanismSectionResultNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; + + using (var view = new PipingFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + failureMechanism.SectionResults.First().NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + } + + [Test] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 7; + const int updatedSurfaceLineLayerIndex = surfaceLinesIndex - 1; + const int updatedSectionCollectionIndex = sectionsCollectionIndex - 1; + const int updatedAssemblyResultsCollectionIndex = assemblyResultsIndex - 1; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedStochasticSoilModelsLayerIndex = stochasticSoilModelsIndex - 1; + const int updatedProbabilisticCalculationsIndex = probabilisticCalculationsIndex - 1; + const int updatedSemiProbabilisticCalculationsIndex = semiProbabilisticCalculationsIndex - 1; + + var assessmentSection = new AssessmentSectionStub(); + + using (var view = new PipingFailureMechanismView(new PipingFailureMechanism(), assessmentSection)) + { + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + MapDataCollection mapData = map.Data; + + var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); + + List mapDataList = mapData.Collection.ToList(); + + // Precondition + var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var surfaceLineData = (MapLineData) mapDataList[updatedSurfaceLineLayerIndex]; + Assert.AreEqual("Profielschematisaties", surfaceLineData.Name); + + var sectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; + Assert.AreEqual("Vakindeling", sectionsData.Name); + + var assemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; + Assert.AreEqual("Toetsoordeel", assemblyResultsData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var stochasticSoilModelsData = (MapLineData) mapDataList[updatedStochasticSoilModelsLayerIndex]; + Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsData.Name); + + var probabilisticCalculationsData = (MapLineData) mapDataList[updatedProbabilisticCalculationsIndex]; + Assert.AreEqual("Probabilistische berekeningen", probabilisticCalculationsData.Name); + + var semiProbabilisticCalculationsData = (MapLineData) mapDataList[updatedSemiProbabilisticCalculationsIndex]; + Assert.AreEqual("Semi-probabilistische berekeningen", semiProbabilisticCalculationsData.Name); + + var points = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(points); + assessmentSection.ReferenceLine = referenceLine; + + // Call + assessmentSection.NotifyObservers(); + + // Assert + var actualReferenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + + var actualSurfaceLineData = (MapLineData) mapDataList[updatedSurfaceLineLayerIndex]; + Assert.AreEqual("Profielschematisaties", actualSurfaceLineData.Name); + + var actualSectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; + Assert.AreEqual("Vakindeling", actualSectionsData.Name); + + var actualAssemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; + Assert.AreEqual("Toetsoordeel", actualAssemblyResultsData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualStochasticSoilModelsData = (MapLineData) mapDataList[updatedStochasticSoilModelsLayerIndex]; + Assert.AreEqual("Stochastische ondergrondmodellen", actualStochasticSoilModelsData.Name); + + var actualSemiProbabilisticCalculationsData = (MapLineData) mapDataList[updatedSemiProbabilisticCalculationsIndex]; + Assert.AreEqual("Semi-probabilistische berekeningen", actualSemiProbabilisticCalculationsData.Name); + + var actualProbabilisticCalculationsData = (MapLineData) mapDataList[updatedProbabilisticCalculationsIndex]; + Assert.AreEqual("Probabilistische berekeningen", actualProbabilisticCalculationsData.Name); + } + } + + private static void AssertSurfaceLinesMapData(IEnumerable surfaceLines, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var surfaceLinesMapData = (MapLineData) mapData; + MapFeature[] surfaceLineFeatures = surfaceLinesMapData.Features.ToArray(); + PipingSurfaceLine[] surfaceLinesArray = surfaceLines.ToArray(); + Assert.AreEqual(surfaceLinesArray.Length, surfaceLineFeatures.Length); + + for (var index = 0; index < surfaceLinesArray.Length; index++) + { + Assert.AreEqual(1, surfaceLineFeatures[index].MapGeometries.Count()); + PipingSurfaceLine surfaceLine = surfaceLinesArray[index]; + CollectionAssert.AreEquivalent(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y)), surfaceLineFeatures[index].MapGeometries.First().PointCollections.First()); + } + + Assert.AreEqual("Profielschematisaties", mapData.Name); + } + + private static void AssertStochasticSoilModelsMapData(IEnumerable soilModels, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var soilModelsMapData = (MapLineData) mapData; + MapFeature[] soilModelsFeatures = soilModelsMapData.Features.ToArray(); + PipingStochasticSoilModel[] stochasticSoilModelsArray = soilModels.ToArray(); + Assert.AreEqual(stochasticSoilModelsArray.Length, soilModelsFeatures.Length); + + for (var index = 0; index < stochasticSoilModelsArray.Length; index++) + { + Assert.AreEqual(1, soilModelsFeatures[index].MapGeometries.Count()); + PipingStochasticSoilModel stochasticSoilModel = stochasticSoilModelsArray[index]; + CollectionAssert.AreEquivalent(stochasticSoilModel.Geometry.Select(p => new Point2D(p)), soilModelsFeatures[index].MapGeometries.First().PointCollections.First()); + } + + Assert.AreEqual("Stochastische ondergrondmodellen", mapData.Name); + } + + private static void AssertSemiProbabilisticCalculationsMapData(IEnumerable calculations, MapData mapData) + { + Assert.AreEqual("Semi-probabilistische berekeningen", mapData.Name); + AssertCalculationsMapData(calculations, mapData); + } + + private static void AssertProbabilisticCalculationsMapData(IEnumerable calculations, MapData mapData) + { + Assert.AreEqual("Probabilistische berekeningen", mapData.Name); + AssertCalculationsMapData(calculations, mapData); + } + + private static void AssertCalculationsMapData(IEnumerable calculations, MapData mapData) + where TCalculationScenario : IPipingCalculationScenario + { + Assert.IsInstanceOf(mapData); + var calculationsMapData = (MapLineData) mapData; + TCalculationScenario[] calculationsArray = calculations.ToArray(); + MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray(); + Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length); + + for (var index = 0; index < calculationsArray.Length; index++) + { + MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray(); + Assert.AreEqual(1, geometries.Length); + + TCalculationScenario calculation = calculationsArray[index]; + CollectionAssert.AreEquivalent(new[] + { + calculation.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint, + calculation.InputParameters.HydraulicBoundaryLocation.Location + }, + geometries[0].PointCollections.First()); + } + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Dijken en dammen - Piping", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(8, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var stochasticSoilModelsMapData = (MapLineData) mapDataList[stochasticSoilModelsIndex]; + var surfaceLinesMapData = (MapLineData) mapDataList[surfaceLinesIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var probabilisticCalculationsMapData = (MapLineData) mapDataList[probabilisticCalculationsIndex]; + var semiProbabilisticCalculationsMapData = (MapLineData) mapDataList[semiProbabilisticCalculationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(stochasticSoilModelsMapData.Features); + CollectionAssert.IsEmpty(surfaceLinesMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + CollectionAssert.IsEmpty(probabilisticCalculationsMapData.Features); + CollectionAssert.IsEmpty(semiProbabilisticCalculationsMapData.Features); + + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsMapData.Name); + Assert.AreEqual("Profielschematisaties", surfaceLinesMapData.Name); + Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name); + Assert.AreEqual("Probabilistische berekeningen", probabilisticCalculationsMapData.Name); + Assert.AreEqual("Semi-probabilistische berekeningen", semiProbabilisticCalculationsMapData.Name); + + var sectionsMapDataCollection = (MapDataCollection) mapDataList[sectionsCollectionIndex]; + Assert.AreEqual("Vakindeling", sectionsMapDataCollection.Name); + List sectionsDataList = sectionsMapDataCollection.Collection.ToList(); + Assert.AreEqual(3, sectionsDataList.Count); + + var sectionsMapData = (MapLineData) sectionsDataList[sectionsIndex]; + var sectionsStartPointMapData = (MapPointData) sectionsDataList[sectionsStartPointIndex]; + var sectionsEndPointMapData = (MapPointData) sectionsDataList[sectionsEndPointIndex]; + + CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); + CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); + CollectionAssert.IsEmpty(sectionsMapData.Features); + + Assert.AreEqual("Vakindeling (eindpunten)", sectionsEndPointMapData.Name); + Assert.AreEqual("Vakindeling (startpunten)", sectionsStartPointMapData.Name); + Assert.AreEqual("Vakindeling", sectionsMapData.Name); + + var assemblyResultsMapDataCollection = (MapDataCollection) mapDataList[assemblyResultsIndex]; + Assert.AreEqual("Toetsoordeel", assemblyResultsMapDataCollection.Name); + List assemblyMapDataList = assemblyResultsMapDataCollection.Collection.ToList(); + Assert.AreEqual(4, assemblyMapDataList.Count); + + var combinedAssemblyMapData = (MapLineData) assemblyMapDataList[combinedAssemblyIndex]; + var simpleAssemblyMapData = (MapLineData) assemblyMapDataList[simpleAssemblyIndex]; + var detailedAssemblyMapData = (MapLineData) assemblyMapDataList[detailedAssemblyIndex]; + var tailorMadeAssemblyMapData = (MapLineData) assemblyMapDataList[tailorMadeAssemblyIndex]; + + CollectionAssert.IsEmpty(combinedAssemblyMapData.Features); + CollectionAssert.IsEmpty(simpleAssemblyMapData.Features); + CollectionAssert.IsEmpty(detailedAssemblyMapData.Features); + CollectionAssert.IsEmpty(tailorMadeAssemblyMapData.Features); + + Assert.AreEqual("Gecombineerd toetsoordeel", combinedAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel eenvoudige toets", simpleAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel gedetailleerde toets", detailedAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel toets op maat", tailorMadeAssemblyMapData.Name); + } + + /// + /// Attaches mocked observers to all map data components. + /// + /// The . + /// The map data collection containing the + /// elements. + /// An array of mocked observers attached to the data in . + private static IObserver[] AttachMapDataObservers(MockRepository mocks, IEnumerable mapData) + { + MapData[] mapDataArray = mapData.ToArray(); + + var referenceLineMapDataObserver = mocks.StrictMock(); + mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); + + var stochasticSoilModelsMapDataObserver = mocks.StrictMock(); + mapDataArray[stochasticSoilModelsIndex].Attach(stochasticSoilModelsMapDataObserver); + + var surfaceLinesMapDataObserver = mocks.StrictMock(); + mapDataArray[surfaceLinesIndex].Attach(surfaceLinesMapDataObserver); + + var hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock(); + mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver); + + var probabilisticCalculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[probabilisticCalculationsIndex].Attach(probabilisticCalculationsMapDataObserver); + + var semiProbabilisticCalculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[semiProbabilisticCalculationsIndex].Attach(semiProbabilisticCalculationsMapDataObserver); + + MapData[] sectionsCollection = ((MapDataCollection) mapDataArray[sectionsCollectionIndex]).Collection.ToArray(); + var sectionsMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsIndex].Attach(sectionsMapDataObserver); + + var sectionsStartPointMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsStartPointIndex].Attach(sectionsStartPointMapDataObserver); + + var sectionsEndPointMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsEndPointIndex].Attach(sectionsEndPointMapDataObserver); + + MapData[] assemblyResultsCollection = ((MapDataCollection) mapDataArray[assemblyResultsIndex]).Collection.ToArray(); + var simpleAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[simpleAssemblyIndex].Attach(simpleAssemblyMapDataObserver); + + var detailedAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[detailedAssemblyIndex].Attach(detailedAssemblyMapDataObserver); + + var tailorMadeAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[tailorMadeAssemblyIndex].Attach(tailorMadeAssemblyMapDataObserver); + + var combinedAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[combinedAssemblyIndex].Attach(combinedAssemblyMapDataObserver); + + return new[] + { + referenceLineMapDataObserver, + stochasticSoilModelsMapDataObserver, + surfaceLinesMapDataObserver, + hydraulicBoundaryLocationsMapDataObserver, + semiProbabilisticCalculationsMapDataObserver, + probabilisticCalculationsMapDataObserver, + sectionsMapDataObserver, + sectionsStartPointMapDataObserver, + sectionsEndPointMapDataObserver, + simpleAssemblyMapDataObserver, + detailedAssemblyMapDataObserver, + tailorMadeAssemblyMapDataObserver, + combinedAssemblyMapDataObserver + }; + } + } +} \ No newline at end of file Index: Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/PipingPluginTest.cs =================================================================== diff -u -r946da8d4431742e51b1a30ea2fcfe0243c0d9848 -rfa2295dde23d04462bdf01b6bdf9a40af554b877 --- Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision 946da8d4431742e51b1a30ea2fcfe0243c0d9848) +++ Riskeer/Piping/test/Riskeer.Piping.Plugin.Test/PipingPluginTest.cs (.../PipingPluginTest.cs) (revision fa2295dde23d04462bdf01b6bdf9a40af554b877) @@ -188,12 +188,17 @@ ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); // Assert - Assert.AreEqual(11, viewInfos.Length); + Assert.AreEqual(12, viewInfos.Length); PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(PipingCalculationsContext), typeof(PipingFailureMechanismView)); + + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(PipingFailurePathContext), + typeof(PipingFailurePathView)); PluginTestHelper.AssertViewInfoDefined( viewInfos,