// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets 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.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 Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.TestUtil; using Ringtoets.Common.Forms.Views; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Forms.Views; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Forms.Test.Views { [TestFixture] public class MacroStabilityInwardsFailureMechanismViewTest { private const int referenceLineIndex = 0; private const int stochasticSoilModelsIndex = 1; private const int surfaceLinesIndex = 2; private const int sectionsIndex = 3; private const int sectionsStartPointIndex = 4; private const int sectionsEndPointIndex = 5; private const int hydraulicBoundaryLocationsIndex = 6; private const int calculationsIndex = 7; [Test] public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); // Call TestDelegate call = () => new MacroStabilityInwardsFailureMechanismView(null, assessmentSection); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void Constructor_ExpectedValues() { // Setup var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var assessmentSection = new ObservableTestAssessmentSectionStub(); // Call using (var view = new MacroStabilityInwardsFailureMechanismView(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, ((RingtoetsMapControl) 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 ObservableTestAssessmentSectionStub(); // Call using (var view = new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { // Assert MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); } } [Test] public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup MacroStabilityInwardsStochasticSoilModel stochasticSoilModel1 = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name1", new[] { new Point2D(1.0, 2.0), new Point2D(1.1, 2.2) }); MacroStabilityInwardsStochasticSoilModel stochasticSoilModel2 = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("name2", new[] { new Point2D(3.0, 4.0), new Point2D(3.3, 4.4) }); var surfaceLineA = new MacroStabilityInwardsSurfaceLine("Line A"); surfaceLineA.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.0), new Point3D(3.0, 0.0, 1.7) }); var surfaceLineB = new MacroStabilityInwardsSurfaceLine("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 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) }; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); const string arbitraryFilePath = "path"; failureMechanism.SurfaceLines.AddRange(new[] { surfaceLineA, surfaceLineB }, arbitraryFilePath); failureMechanism.AddSection(new FailureMechanismSection("A", geometryPoints.Take(2))); failureMechanism.AddSection(new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2))); failureMechanism.AddSection(new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2))); failureMechanism.StochasticSoilModels.AddRange(new[] { stochasticSoilModel1, stochasticSoilModel2 }, arbitraryFilePath); MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); calculationA.InputParameters.SurfaceLine = surfaceLineA; MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); 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 ObservableTestAssessmentSectionStub { ReferenceLine = referenceLine }; assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); // Call using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, assessmentSection)) { IMapControl map = ((RingtoetsMapControl) 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]); MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, mapDataList[sectionsIndex]); MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, mapDataList[sectionsStartPointIndex]); MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, mapDataList[sectionsEndPointIndex]); MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection.HydraulicBoundaryDatabase.Locations, mapDataList[hydraulicBoundaryLocationsIndex]); AssertStochasticSoilModelsMapData(failureMechanism.StochasticSoilModels, mapDataList[stochasticSoilModelsIndex]); AssertCalculationsMapData(failureMechanism.Calculations.Cast(), mapDataList[calculationsIndex]); } } [Test] public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationsUpdatedAndNotified_ThenMapDataUpdated() { // Given var assessmentSection = new ObservableTestAssessmentSectionStub(); assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); using (var view = new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection.HydraulicBoundaryDatabase.Locations, hydraulicBoundaryLocationsMapData); // When assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)); assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection.HydraulicBoundaryDatabase.Locations, 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 ObservableTestAssessmentSectionStub(); assessmentSection.AddHydraulicBoundaryLocation(hydraulicBoundaryLocation); using (var view = new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[hydraulicBoundaryLocationsIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); // Precondition MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); // When HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection); calculation.Output = new TestHydraulicBoundaryLocationOutput(new Random(21).NextDouble()); calculation.NotifyObservers(); // Then MapDataTestHelper.AssertHydraulicBoundaryLocationOutputsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); mocks.VerifyAll(); } } [Test] public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdated() { // Given var assessmentSection = new ObservableTestAssessmentSectionStub { ReferenceLine = new ReferenceLine() }; assessmentSection.ReferenceLine.SetGeometry(new List { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); using (var view = new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { IMapControl map = ((RingtoetsMapControl) 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 assessmentSection.ReferenceLine.SetGeometry(new List { new Point2D(2.0, 5.0), new Point2D(4.0, 3.0) }); assessmentSection.NotifyObservers(); // Then MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); mocks.VerifyAll(); } } [Test] public void GivenViewWithSurfaceLinesData_WhenSurfaceLinesUpdatedAndNotified_ThenMapDataUpdatedAndObserverNotified() { // Given var failureMechanism = new MacroStabilityInwardsFailureMechanism(); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var surfaceLine = new MacroStabilityInwardsSurfaceLine(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_ThenMapDataUpdatedAndObserverNotified() { // Given var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.SurfaceLines.AddRange(new[] { surfaceLine }, "path"); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) 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 MacroStabilityInwardsFailureMechanism(); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var sectionMapData = (MapLineData) map.Data.Collection.ElementAt(sectionsIndex); var sectionStartsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsStartPointIndex); var sectionsEndsMapData = (MapPointData) map.Data.Collection.ElementAt(sectionsEndPointIndex); var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[sectionsIndex].Expect(obs => obs.UpdateObserver()); observers[sectionsStartPointIndex].Expect(obs => obs.UpdateObserver()); observers[sectionsEndPointIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); // When failureMechanism.AddSection(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_ThenMapDataUpdatedAndObserverNotified() { // Given var failureMechanism = new MacroStabilityInwardsFailureMechanism(); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; 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[] { MacroStabilityInwardsStochasticSoilModelTestFactory.CreateValidStochasticSoilModel("", new[] { new Point2D(1, 2), new Point2D(1, 2) }) }, "path"); failureMechanism.StochasticSoilModels.NotifyObservers(); // Then AssertStochasticSoilModelsMapData(failureMechanism.StochasticSoilModels, stochasticSoilModelMapData); mocks.VerifyAll(); } } [Test] public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated() { // Given var surfaceLineA = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLineA.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.0), new Point3D(3.0, 0.0, 1.7) }); surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); calculationA.InputParameters.SurfaceLine = surfaceLineA; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculationA); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var surfaceLineB = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLineB.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.5), new Point3D(3.0, 0.0, 1.8) }); surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); calculationB.InputParameters.SurfaceLine = surfaceLineB; var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); // When failureMechanism.CalculationsGroup.Children.Add(calculationB); failureMechanism.CalculationsGroup.NotifyObservers(); // Then AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); mocks.VerifyAll(); } } [Test] public void GivenViewWithCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated() { // Given var surfaceLineA = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLineA.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.0), new Point3D(3.0, 0.0, 1.7) }); surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); calculationA.InputParameters.SurfaceLine = surfaceLineA; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculationA); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var surfaceLineB = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLineB.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.5), new Point3D(3.0, 0.0, 1.8) }); surfaceLineB.ReferenceLineIntersectionWorldPoint = new Point2D(1.5, 1.5); var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); // When calculationA.InputParameters.SurfaceLine = surfaceLineB; calculationA.InputParameters.NotifyObservers(); // Then AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); mocks.VerifyAll(); } } [Test] public void GivenViewWithCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated() { // Given var surfaceLineA = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLineA.SetGeometry(new[] { new Point3D(0.0, 0.0, 1.0), new Point3D(3.0, 0.0, 1.7) }); surfaceLineA.ReferenceLineIntersectionWorldPoint = new Point2D(1.3, 1.3); MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(); calculationA.InputParameters.SurfaceLine = surfaceLineA; var failureMechanism = new MacroStabilityInwardsFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculationA); using (var view = new MacroStabilityInwardsFailureMechanismView(failureMechanism, new ObservableTestAssessmentSectionStub())) { IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); observers[calculationsIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); // When calculationA.Name = "new name"; calculationA.NotifyObservers(); // Then AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); mocks.VerifyAll(); } } [Test] public void UpdateObserver_DataUpdated_MapLayersSameOrder() { // Setup const int updatedRefenceLineLayerIndex = referenceLineIndex + 7; const int updatedSurfaceLineLayerIndex = surfaceLinesIndex - 1; const int updatedSectionsLayerIndex = sectionsIndex - 1; const int updateSectionStartLayerIndex = sectionsStartPointIndex - 1; const int updatedSectionEndLayerIndex = sectionsEndPointIndex - 1; const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; const int updatedStochasticSoilModelsLayerIndex = stochasticSoilModelsIndex - 1; const int updatedCalculationsIndex = calculationsIndex - 1; var assessmentSection = new ObservableTestAssessmentSectionStub(); using (var view = new MacroStabilityInwardsFailureMechanismView(new MacroStabilityInwardsFailureMechanism(), assessmentSection)) { IMapControl map = ((RingtoetsMapControl) 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[updatedRefenceLineLayerIndex]; Assert.AreEqual("Referentielijn", referenceLineData.Name); var surfaceLineData = (MapLineData) mapDataList[updatedSurfaceLineLayerIndex]; Assert.AreEqual("Profielschematisaties", surfaceLineData.Name); var sectionsData = (MapLineData) mapDataList[updatedSectionsLayerIndex]; Assert.AreEqual("Vakindeling", sectionsData.Name); var sectionStartsData = (MapPointData) mapDataList[updateSectionStartLayerIndex]; Assert.AreEqual("Vakindeling (startpunten)", sectionStartsData.Name); var sectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex]; Assert.AreEqual("Vakindeling (eindpunten)", sectionEndsData.Name); var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicLocationsData.Name); var stochasticSoilModelsData = (MapLineData) mapDataList[updatedStochasticSoilModelsLayerIndex]; Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsData.Name); var calculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; Assert.AreEqual("Berekeningen", calculationsData.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[updatedRefenceLineLayerIndex]; Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); var actualSurfaceLineData = (MapLineData) mapDataList[updatedSurfaceLineLayerIndex]; Assert.AreEqual("Profielschematisaties", actualSurfaceLineData.Name); var actualSectionsData = (MapLineData) mapDataList[updatedSectionsLayerIndex]; Assert.AreEqual("Vakindeling", actualSectionsData.Name); var actualSectionStartsData = (MapPointData) mapDataList[updateSectionStartLayerIndex]; Assert.AreEqual("Vakindeling (startpunten)", actualSectionStartsData.Name); var actualSectionEndsData = (MapPointData) mapDataList[updatedSectionEndLayerIndex]; Assert.AreEqual("Vakindeling (eindpunten)", actualSectionEndsData.Name); var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; Assert.AreEqual("Hydraulische randvoorwaarden", actualHydraulicLocationsData.Name); var actualStochasticSoilModelsData = (MapLineData) mapDataList[updatedStochasticSoilModelsLayerIndex]; Assert.AreEqual("Stochastische ondergrondmodellen", actualStochasticSoilModelsData.Name); var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; Assert.AreEqual("Berekeningen", actualCalculationsData.Name); } } private static void AssertSurfaceLinesMapData(IEnumerable surfaceLines, MapData mapData) { Assert.IsInstanceOf(mapData); var surfaceLinesMapData = (MapLineData) mapData; MapFeature[] surfaceLineFeatures = surfaceLinesMapData.Features.ToArray(); MacroStabilityInwardsSurfaceLine[] surfaceLinesArray = surfaceLines.ToArray(); Assert.AreEqual(surfaceLinesArray.Length, surfaceLineFeatures.Length); for (var index = 0; index < surfaceLinesArray.Length; index++) { Assert.AreEqual(1, surfaceLineFeatures[index].MapGeometries.Count()); MacroStabilityInwardsSurfaceLine 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(); MacroStabilityInwardsStochasticSoilModel[] stochasticSoilModelsArray = soilModels.ToArray(); Assert.AreEqual(stochasticSoilModelsArray.Length, soilModelsFeatures.Length); for (var index = 0; index < stochasticSoilModelsArray.Length; index++) { Assert.AreEqual(1, soilModelsFeatures[index].MapGeometries.Count()); MacroStabilityInwardsStochasticSoilModel 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 AssertCalculationsMapData(IEnumerable calculations, MapData mapData) { Assert.IsInstanceOf(mapData); var calculationsMapData = (MapLineData) mapData; MacroStabilityInwardsCalculationScenario[] 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); MacroStabilityInwardsCalculationScenario calculation = calculationsArray[index]; CollectionAssert.AreEquivalent(new[] { calculation.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint, calculation.InputParameters.HydraulicBoundaryLocation.Location }, geometries[0].PointCollections.First()); } Assert.AreEqual("Berekeningen", mapData.Name); } private static void AssertEmptyMapData(MapDataCollection mapDataCollection) { Assert.AreEqual("Dijken en dammen - Macrostabiliteit binnenwaarts", mapDataCollection.Name); List mapDataList = mapDataCollection.Collection.ToList(); Assert.AreEqual(8, mapDataList.Count); var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; var sectionsMapData = (MapLineData) mapDataList[sectionsIndex]; var stochasticSoilModelsMapData = (MapLineData) mapDataList[stochasticSoilModelsIndex]; var surfaceLinesMapData = (MapLineData) mapDataList[surfaceLinesIndex]; var sectionsStartPointMapData = (MapPointData) mapDataList[sectionsStartPointIndex]; var sectionsEndPointMapData = (MapPointData) mapDataList[sectionsEndPointIndex]; var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; var calculationsMapData = (MapLineData) mapDataList[calculationsIndex]; CollectionAssert.IsEmpty(referenceLineMapData.Features); CollectionAssert.IsEmpty(sectionsMapData.Features); CollectionAssert.IsEmpty(stochasticSoilModelsMapData.Features); CollectionAssert.IsEmpty(surfaceLinesMapData.Features); CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); CollectionAssert.IsEmpty(calculationsMapData.Features); Assert.AreEqual("Referentielijn", referenceLineMapData.Name); Assert.AreEqual("Vakindeling", sectionsMapData.Name); Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsMapData.Name); Assert.AreEqual("Profielschematisaties", surfaceLinesMapData.Name); Assert.AreEqual("Vakindeling (startpunten)", sectionsStartPointMapData.Name); Assert.AreEqual("Vakindeling (eindpunten)", sectionsEndPointMapData.Name); Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicBoundaryLocationsMapData.Name); Assert.AreEqual("Berekeningen", calculationsMapData.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 stochasticSoilModelMapDataObserver = mocks.StrictMock(); mapDataArray[stochasticSoilModelsIndex].Attach(stochasticSoilModelMapDataObserver); var surfaceLineMapDataObserver = mocks.StrictMock(); mapDataArray[surfaceLinesIndex].Attach(surfaceLineMapDataObserver); var sectionsMapDataObserver = mocks.StrictMock(); mapDataArray[sectionsIndex].Attach(sectionsMapDataObserver); var sectionsStartPointMapDataObserver = mocks.StrictMock(); mapDataArray[sectionsStartPointIndex].Attach(sectionsStartPointMapDataObserver); var sectionsEndPointMapDataObserver = mocks.StrictMock(); mapDataArray[sectionsEndPointIndex].Attach(sectionsEndPointMapDataObserver); var hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock(); mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver); var calculationsMapDataObserver = mocks.StrictMock(); mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); return new[] { referenceLineMapDataObserver, stochasticSoilModelMapDataObserver, surfaceLineMapDataObserver, sectionsMapDataObserver, sectionsStartPointMapDataObserver, sectionsEndPointMapDataObserver, hydraulicBoundaryLocationsMapDataObserver, calculationsMapDataObserver }; } } }