Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -r184de624feae0c0a051e34298d66e304d073daf5 -re0e813ab11c3b35020a785cebf275366cd2eaf9d --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 184de624feae0c0a051e34298d66e304d073daf5) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -90,6 +90,7 @@ + UserControl Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingChartDataFactory.cs (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -0,0 +1,68 @@ +// Copyright (C) Stichting Deltares 2016. 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.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Charting.Data; +using Core.Components.Charting.Styles; +using Ringtoets.Piping.Primitives; +using Resources = Ringtoets.Piping.Forms.Properties.Resources; + +namespace Ringtoets.Piping.Forms.Views +{ + /// + /// Factory for creating based on information used as input in the piping failure mechanism. + /// + public static class PipingChartDataFactory + { + /// + /// Create a instance with a name, but without data. + /// + /// The name of the . + /// An empty object. + public static ChartLineData CreateEmptyLineData(string name) + { + return new ChartLineData(Enumerable.Empty(), name); + } + + /// + /// Create with default styling based on the . + /// + /// The for which to create / + /// based on the . + /// Thrown when is null. + public static ChartData Create(RingtoetsPipingSurfaceLine surfaceLine) + { + if (surfaceLine == null) + { + throw new ArgumentNullException("surfaceLine"); + } + + return new ChartLineData(surfaceLine.ProjectGeometryToLZ(), Resources.RingtoetsPipingSurfaceLine_DisplayName) + { + Style = new ChartLineStyle(Color.SaddleBrown, 2, DashStyle.Solid) + }; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingInputView.cs =================================================================== diff -u -r0fdde49cfbdc5a411fac387d6a99484f05112700 -re0e813ab11c3b35020a785cebf275366cd2eaf9d --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingInputView.cs (.../PipingInputView.cs) (revision 0fdde49cfbdc5a411fac387d6a99484f05112700) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingInputView.cs (.../PipingInputView.cs) (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -21,8 +21,10 @@ using System.Windows.Forms; using Core.Common.Base; +using Core.Components.Charting.Data; using Core.Components.Charting.Forms; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; namespace Ringtoets.Piping.Forms.Views { @@ -34,6 +36,8 @@ private PipingInput data; private PipingCalculationScenario calculation; + private ChartData surfaceLineData; + /// /// Creates a new instance of . /// @@ -68,7 +72,12 @@ } set { - data = value as PipingInput; + var newValue = value as PipingInput; + + DetachFromData(); + data = newValue; + SetDataToChart(); + AttachToData(); } } @@ -83,19 +92,62 @@ public void UpdateObserver() { SetChartTitle(); + SetDataToChart(); } private void SetChartTitle() { - chartControl.ChartTitle = calculation.Name; + if (calculation != null) + { + chartControl.ChartTitle = calculation.Name; + } } + + private void SetDataToChart() + { + if (data != null) + { + surfaceLineData = AddOrUpdateChartData(surfaceLineData, GetSurfaceLineChartData()); + } + chartControl.Data.NotifyObservers(); + } + + private ChartData GetSurfaceLineChartData() + { + if (data == null || data.SurfaceLine == null) + { + return PipingChartDataFactory.CreateEmptyLineData(Resources.RingtoetsPipingSurfaceLine_DisplayName); + } + + return PipingChartDataFactory.Create(data.SurfaceLine); + } + + private ChartData AddOrUpdateChartData(ChartData oldChartData, ChartData newChartData) + { + if (oldChartData != null) + { + chartControl.Data.Remove(oldChartData); + } + if (newChartData != null) + { + chartControl.Data.Add(newChartData); + } + + return newChartData; + } + private void DetachFromData() { if (calculation != null) { calculation.Detach(this); } + + if (data != null) + { + data.Detach(this); + } } private void AttachToData() @@ -104,6 +156,11 @@ { calculation.Attach(this); } + + if (data != null) + { + data.Attach(this); + } } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj =================================================================== diff -u -re5eb6aafecb6223ded5109bc1f76b4d3b35e21ed -re0e813ab11c3b35020a785cebf275366cd2eaf9d --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision e5eb6aafecb6223ded5109bc1f76b4d3b35e21ed) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Ringtoets.Piping.Forms.Test.csproj (.../Ringtoets.Piping.Forms.Test.csproj) (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -98,6 +98,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingChartDataFactoryTest.cs (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -0,0 +1,104 @@ +// Copyright (C) Stichting Deltares 2016. 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.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Charting.Data; +using Core.Components.Charting.Styles; +using NUnit.Framework; +using Ringtoets.Piping.Forms.Properties; +using Ringtoets.Piping.Forms.Views; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Forms.Test.Views +{ + [TestFixture] + public class PipingChartDataFactoryTest + { + [Test] + public void CreateEmptyLineData_Always_ReturnEmptyChartLineDataWithNameSet() + { + // Setup + const string name = ""; + + // Call + ChartLineData mapData = PipingChartDataFactory.CreateEmptyLineData(name); + + // Assert + Assert.AreEqual(name, mapData.Name); + Assert.IsEmpty(mapData.Points); + } + + [Test] + public void Create_NoSurfaceLine_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => PipingChartDataFactory.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("surfaceLine", exception.ParamName); + } + + [Test] + public void Create_GivenSurfaceLine_ReturnsChartDataWithDefaultStyling() + { + // Setup + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + + // Call + ChartData data = PipingChartDataFactory.Create(surfaceLine); + + // Assert + Assert.IsInstanceOf(data); + ChartLineData chartLineData = (ChartLineData) data; + Assert.AreEqual(2, chartLineData.Points.Count()); + Assert.AreEqual(Resources.RingtoetsPipingSurfaceLine_DisplayName, data.Name); + + AssertEqualPointCollections(surfaceLine.ProjectGeometryToLZ(), chartLineData.Points); + + AssertEqualStyle(chartLineData.Style, Color.SaddleBrown, 2, DashStyle.Solid); + } + + private void AssertEqualPointCollections(IEnumerable points, IEnumerable chartPoints) + { + CollectionAssert.AreEqual(points.Select(p => new Point2D(p.X, p.Y)), chartPoints); + } + + private void AssertEqualStyle(ChartLineStyle lineStyle, Color color, int width, DashStyle style) + { + Assert.AreEqual(color, lineStyle.Color); + Assert.AreEqual(width, lineStyle.Width); + Assert.AreEqual(style, lineStyle.Style); + } + } +} Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs =================================================================== diff -u -r9f4fd0f8b9c2aa65c16de47b3063282e81e4a6c3 -re0e813ab11c3b35020a785cebf275366cd2eaf9d --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision 9f4fd0f8b9c2aa65c16de47b3063282e81e4a6c3) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingFailureMechanismViewTest.cs (.../PipingFailureMechanismViewTest.cs) (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -49,478 +49,498 @@ public void DefaultConstructor_DefaultValues() { // Call - var view = new PipingFailureMechanismView(); - - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsNotNull(view.Map); - Assert.IsNull(view.Data); + using (var view = new PipingFailureMechanismView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNotNull(view.Map); + Assert.IsNull(view.Data); + } } [Test] public void DefaultConstructor_Always_AddsMapControlWithEmptyCollectionData() { // Call - var view = new PipingFailureMechanismView(); - - // Assert - Assert.AreEqual(1, view.Controls.Count); - var mapObject = view.Controls[0] as MapControl; - Assert.NotNull(mapObject); - Assert.AreEqual(DockStyle.Fill, mapObject.Dock); - Assert.IsNotNull(mapObject.Data); - CollectionAssert.IsEmpty(mapObject.Data.List); + using (var view = new PipingFailureMechanismView()) + { + // Assert + Assert.AreEqual(1, view.Controls.Count); + var mapObject = view.Controls[0] as MapControl; + Assert.NotNull(mapObject); + Assert.AreEqual(DockStyle.Fill, mapObject.Dock); + Assert.IsNotNull(mapObject.Data); + CollectionAssert.IsEmpty(mapObject.Data.List); + } } [Test] public void Data_EmptyAssessmentSection_NoMapDataSet() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - var mocks = new MockRepository(); - var assessmentSectionMock = mocks.Stub(); - mocks.ReplayAll(); + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); - // Call - view.Data = pipingContext; + // Call + view.Data = pipingContext; - // Assert - var mapData = map.Data; + // Assert + var mapData = map.Data; - Assert.AreEqual(7, mapData.List.Count); + Assert.AreEqual(7, mapData.List.Count); - var referenceLineData = mapData.List[referenceLineLayerIndex] as FeatureBasedMapData; - Assert.NotNull(referenceLineData); - Assert.IsEmpty(referenceLineData.Features); - Assert.AreEqual("Referentielijn", referenceLineData.Name); + var referenceLineData = mapData.List[referenceLineLayerIndex] as FeatureBasedMapData; + Assert.NotNull(referenceLineData); + Assert.IsEmpty(referenceLineData.Features); + Assert.AreEqual("Referentielijn", referenceLineData.Name); - var surfaceLineData = mapData.List[surfaceLinesLayerIndex] as FeatureBasedMapData; - Assert.NotNull(surfaceLineData); - Assert.IsEmpty(surfaceLineData.Features); - Assert.AreEqual("Profielschematisaties", surfaceLineData.Name); + var surfaceLineData = mapData.List[surfaceLinesLayerIndex] as FeatureBasedMapData; + Assert.NotNull(surfaceLineData); + Assert.IsEmpty(surfaceLineData.Features); + Assert.AreEqual("Profielschematisaties", surfaceLineData.Name); - var sectionsData = mapData.List[sectionsLayerIndex] as FeatureBasedMapData; - Assert.NotNull(sectionsData); - Assert.IsEmpty(sectionsData.Features); - Assert.AreEqual("Vakindeling", sectionsData.Name); + var sectionsData = mapData.List[sectionsLayerIndex] as FeatureBasedMapData; + Assert.NotNull(sectionsData); + Assert.IsEmpty(sectionsData.Features); + Assert.AreEqual("Vakindeling", sectionsData.Name); - var sectionStartsData = mapData.List[sectionStartsLayerIndex] as FeatureBasedMapData; - Assert.NotNull(sectionStartsData); - Assert.IsEmpty(sectionStartsData.Features); - Assert.AreEqual("Vakindeling (startpunten)", sectionStartsData.Name); + var sectionStartsData = mapData.List[sectionStartsLayerIndex] as FeatureBasedMapData; + Assert.NotNull(sectionStartsData); + Assert.IsEmpty(sectionStartsData.Features); + Assert.AreEqual("Vakindeling (startpunten)", sectionStartsData.Name); - var sectionEndsData = mapData.List[sectionEndsLayerIndex] as FeatureBasedMapData; - Assert.NotNull(sectionEndsData); - Assert.IsEmpty(sectionEndsData.Features); - Assert.AreEqual("Vakindeling (eindpunten)", sectionEndsData.Name); + var sectionEndsData = mapData.List[sectionEndsLayerIndex] as FeatureBasedMapData; + Assert.NotNull(sectionEndsData); + Assert.IsEmpty(sectionEndsData.Features); + Assert.AreEqual("Vakindeling (eindpunten)", sectionEndsData.Name); - var hydraulicLocationsData = mapData.List[hydraulicLocationsLayerIndex] as FeatureBasedMapData; - Assert.NotNull(hydraulicLocationsData); - Assert.IsEmpty(hydraulicLocationsData.Features); - Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicLocationsData.Name); + var hydraulicLocationsData = mapData.List[hydraulicLocationsLayerIndex] as FeatureBasedMapData; + Assert.NotNull(hydraulicLocationsData); + Assert.IsEmpty(hydraulicLocationsData.Features); + Assert.AreEqual("Hydraulische randvoorwaarden", hydraulicLocationsData.Name); - var stochasticSoilModelsData = mapData.List[stochasticSoilModelsLayerIndex] as FeatureBasedMapData; - Assert.NotNull(stochasticSoilModelsData); - Assert.IsEmpty(stochasticSoilModelsData.Features); - Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsData.Name); + var stochasticSoilModelsData = mapData.List[stochasticSoilModelsLayerIndex] as FeatureBasedMapData; + Assert.NotNull(stochasticSoilModelsData); + Assert.IsEmpty(stochasticSoilModelsData.Features); + Assert.AreEqual("Stochastische ondergrondmodellen", stochasticSoilModelsData.Name); - mocks.VerifyAll(); + mocks.VerifyAll(); + } } [Test] public void Data_SetMapData_MapDataSet() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; - - var refereceGeometryPoints = new[] + using (var view = new PipingFailureMechanismView()) { - 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 map = (MapControl) view.Controls[0]; - var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); - hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + var refereceGeometryPoints = 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 referenceLine = new ReferenceLine(); - referenceLine.SetGeometry(new[] - { - new Point2D(1.0, 2.0), - new Point2D(2.0, 1.0) - }); + var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); - var mocks = new MockRepository(); - var assessmentSectionMock = mocks.Stub(); - assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; - assessmentSectionMock.ReferenceLine = referenceLine; - mocks.ReplayAll(); + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); - var stochasticSoilModel = new StochasticSoilModel(0, "", ""); - stochasticSoilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 2.0), - new Point2D(1.1, 2.2) - }); + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.Stub(); + assessmentSectionMock.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase; + assessmentSectionMock.ReferenceLine = referenceLine; + mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); - pipingFailureMechanism.SurfaceLines.Add(new RingtoetsPipingSurfaceLine()); - pipingFailureMechanism.AddSection(new FailureMechanismSection("A", refereceGeometryPoints.Take(2))); - pipingFailureMechanism.AddSection(new FailureMechanismSection("B", refereceGeometryPoints.Skip(1).Take(2))); - pipingFailureMechanism.AddSection(new FailureMechanismSection("C", refereceGeometryPoints.Skip(2).Take(2))); - pipingFailureMechanism.StochasticSoilModels.Add(stochasticSoilModel); + var stochasticSoilModel = new StochasticSoilModel(0, "", ""); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 2.0), + new Point2D(1.1, 2.2) + }); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.SurfaceLines.Add(new RingtoetsPipingSurfaceLine()); + pipingFailureMechanism.AddSection(new FailureMechanismSection("A", refereceGeometryPoints.Take(2))); + pipingFailureMechanism.AddSection(new FailureMechanismSection("B", refereceGeometryPoints.Skip(1).Take(2))); + pipingFailureMechanism.AddSection(new FailureMechanismSection("C", refereceGeometryPoints.Skip(2).Take(2))); + pipingFailureMechanism.StochasticSoilModels.Add(stochasticSoilModel); - // Call - view.Data = pipingContext; + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); - // Assert - Assert.AreSame(pipingContext, view.Data); - Assert.IsInstanceOf(map.Data); - var mapData = map.Data; - Assert.IsNotNull(mapData); + // Call + view.Data = pipingContext; - Assert.AreEqual(7, mapData.List.Count); - AssertReferenceMapData(assessmentSectionMock.ReferenceLine, mapData.List[referenceLineLayerIndex]); - AssertSurfacelinesMapData(pipingFailureMechanism.SurfaceLines, mapData.List[surfaceLinesLayerIndex]); - AssertFailureMechanismSectionsMapData(pipingFailureMechanism.Sections, mapData.List[sectionsLayerIndex]); - AssertFailureMechanismSectionsStartPointMapData(pipingFailureMechanism.Sections, mapData.List[sectionStartsLayerIndex]); - AssertFailureMechanismSectionsEndPointMapData(pipingFailureMechanism.Sections, mapData.List[sectionEndsLayerIndex]); - AssertHydraulicBoundaryLocationsMapData(assessmentSectionMock.HydraulicBoundaryDatabase, mapData.List[hydraulicLocationsLayerIndex]); - AssertStochasticSoilModelsMapData(pipingFailureMechanism.StochasticSoilModels, mapData.List[stochasticSoilModelsLayerIndex]); + // Assert + Assert.AreSame(pipingContext, view.Data); + Assert.IsInstanceOf(map.Data); + var mapData = map.Data; + Assert.IsNotNull(mapData); - mocks.VerifyAll(); + Assert.AreEqual(7, mapData.List.Count); + AssertReferenceMapData(assessmentSectionMock.ReferenceLine, mapData.List[referenceLineLayerIndex]); + AssertSurfacelinesMapData(pipingFailureMechanism.SurfaceLines, mapData.List[surfaceLinesLayerIndex]); + AssertFailureMechanismSectionsMapData(pipingFailureMechanism.Sections, mapData.List[sectionsLayerIndex]); + AssertFailureMechanismSectionsStartPointMapData(pipingFailureMechanism.Sections, mapData.List[sectionStartsLayerIndex]); + AssertFailureMechanismSectionsEndPointMapData(pipingFailureMechanism.Sections, mapData.List[sectionEndsLayerIndex]); + AssertHydraulicBoundaryLocationsMapData(assessmentSectionMock.HydraulicBoundaryDatabase, mapData.List[hydraulicLocationsLayerIndex]); + AssertStochasticSoilModelsMapData(pipingFailureMechanism.StochasticSoilModels, mapData.List[stochasticSoilModelsLayerIndex]); + + mocks.VerifyAll(); + } } [Test] public void UpdateObserver_HydraulicBoundaryDatabaseUpdated_SetNewMapData() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - var hydraulicBoundaryDatabase1 = new HydraulicBoundaryDatabase(); - hydraulicBoundaryDatabase1.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + var hydraulicBoundaryDatabase1 = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase1.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); - var assessmentSection = new TestAssessmentSection - { - HydraulicBoundaryDatabase = hydraulicBoundaryDatabase1 - }; + var assessmentSection = new TestAssessmentSection + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase1 + }; - var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); + var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); - view.Data = pipingContext; - var mapData = map.Data; + view.Data = pipingContext; + var mapData = map.Data; - var mapDataElementBeforeUpdate = (MapPointData)mapData.List.ElementAt(hydraulicLocationsLayerIndex); - var geometryBeforeUpdate = mapDataElementBeforeUpdate.Features.First().MapGeometries.First().PointCollections.First(); + var mapDataElementBeforeUpdate = (MapPointData) mapData.List.ElementAt(hydraulicLocationsLayerIndex); + var geometryBeforeUpdate = mapDataElementBeforeUpdate.Features.First().MapGeometries.First().PointCollections.First(); - // Precondition - Assert.AreEqual(new Point2D(1.0, 2.0), geometryBeforeUpdate.First()); + // Precondition + Assert.AreEqual(new Point2D(1.0, 2.0), geometryBeforeUpdate.First()); - var hydraulicBoundaryDatabase2 = new HydraulicBoundaryDatabase(); - hydraulicBoundaryDatabase2.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)); + var hydraulicBoundaryDatabase2 = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase2.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)); - assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase2; + assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase2; - // Call - assessmentSection.NotifyObservers(); + // Call + assessmentSection.NotifyObservers(); - // Assert - Assert.IsInstanceOf(map.Data); - Assert.AreEqual(mapData, map.Data); - CollectionAssert.AreEquivalent(mapData.List, map.Data.List); + // Assert + Assert.IsInstanceOf(map.Data); + Assert.AreEqual(mapData, map.Data); + CollectionAssert.AreEquivalent(mapData.List, map.Data.List); - var mapDataElementAfterUpdate = (MapPointData)map.Data.List.ElementAt(hydraulicLocationsLayerIndex); - var geometryAfterUpdate = mapDataElementAfterUpdate.Features.First().MapGeometries.First().PointCollections.First(); + var mapDataElementAfterUpdate = (MapPointData) map.Data.List.ElementAt(hydraulicLocationsLayerIndex); + var geometryAfterUpdate = mapDataElementAfterUpdate.Features.First().MapGeometries.First().PointCollections.First(); - Assert.AreEqual(new Point2D(2.0, 3.0), geometryAfterUpdate.First()); + Assert.AreEqual(new Point2D(2.0, 3.0), geometryAfterUpdate.First()); + } } [Test] public void UpdateObserver_ReferenceLineUpdated_SetNewMapData() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; - - var points = new List + using (var view = new PipingFailureMechanismView()) { - new Point2D(1.0, 2.0), - new Point2D(2.0, 1.0) - }; + var map = (MapControl) view.Controls[0]; - var pointsUpdate = new List - { - new Point2D(2.0, 5.0), - new Point2D(4.0, 3.0) - }; + var points = new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }; - var assessmentSection = new TestAssessmentSection - { - ReferenceLine = new ReferenceLine() - }; - assessmentSection.ReferenceLine.SetGeometry(points); + var pointsUpdate = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; - var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); + var assessmentSection = new TestAssessmentSection + { + ReferenceLine = new ReferenceLine() + }; + assessmentSection.ReferenceLine.SetGeometry(points); - view.Data = pipingContext; - var mapData = map.Data; + var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); - var mapDataElementBeforeUpdate = (MapLineData)mapData.List.ElementAt(referenceLineLayerIndex); - var geometryBeforeUpdate = mapDataElementBeforeUpdate.Features.First().MapGeometries.First().PointCollections.First(); + view.Data = pipingContext; + var mapData = map.Data; - // Precondition - CollectionAssert.AreEquivalent(points, geometryBeforeUpdate); + var mapDataElementBeforeUpdate = (MapLineData) mapData.List.ElementAt(referenceLineLayerIndex); + var geometryBeforeUpdate = mapDataElementBeforeUpdate.Features.First().MapGeometries.First().PointCollections.First(); - assessmentSection.ReferenceLine.SetGeometry(pointsUpdate); + // Precondition + CollectionAssert.AreEquivalent(points, geometryBeforeUpdate); - // Call - assessmentSection.NotifyObservers(); + assessmentSection.ReferenceLine.SetGeometry(pointsUpdate); - // Assert - Assert.IsInstanceOf(map.Data); - Assert.AreEqual(mapData, map.Data); - CollectionAssert.AreEquivalent(mapData.List, map.Data.List); + // Call + assessmentSection.NotifyObservers(); - var mapDataElementAfterUpdate = (MapLineData)map.Data.List.ElementAt(referenceLineLayerIndex); - var geometryAfterUpdate = mapDataElementAfterUpdate.Features.First().MapGeometries.First().PointCollections.First(); + // Assert + Assert.IsInstanceOf(map.Data); + Assert.AreEqual(mapData, map.Data); + CollectionAssert.AreEquivalent(mapData.List, map.Data.List); - CollectionAssert.AreEquivalent(pointsUpdate, geometryAfterUpdate); + var mapDataElementAfterUpdate = (MapLineData) map.Data.List.ElementAt(referenceLineLayerIndex); + var geometryAfterUpdate = mapDataElementAfterUpdate.Features.First().MapGeometries.First().PointCollections.First(); + + CollectionAssert.AreEquivalent(pointsUpdate, geometryAfterUpdate); + } } [Test] public void UpdateObserver_SurfaceLinesUpdated_SetNewMapData() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - var mocks = new MockRepository(); - var assessmentSectionMock = mocks.Stub(); - mocks.ReplayAll(); + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); - view.Data = pipingContext; - var oldSurfaceLineData = (FeatureBasedMapData) map.Data.List.ElementAt(surfaceLinesLayerIndex); + view.Data = pipingContext; + var oldSurfaceLineData = (FeatureBasedMapData) map.Data.List.ElementAt(surfaceLinesLayerIndex); - var surfaceLine = new RingtoetsPipingSurfaceLine(); - surfaceLine.SetGeometry(new Collection - { - new Point3D(1, 2, 3), - new Point3D(1, 2, 3) - }); - pipingFailureMechanism.SurfaceLines.Add(surfaceLine); + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new Collection + { + new Point3D(1, 2, 3), + new Point3D(1, 2, 3) + }); + pipingFailureMechanism.SurfaceLines.Add(surfaceLine); - // Call - pipingFailureMechanism.NotifyObservers(); + // Call + pipingFailureMechanism.NotifyObservers(); - // Assert - var surfaceLineData = (FeatureBasedMapData) map.Data.List.ElementAt(surfaceLinesLayerIndex); - Assert.AreNotEqual(oldSurfaceLineData, surfaceLineData); - Assert.IsInstanceOf(map.Data); + // Assert + var surfaceLineData = (FeatureBasedMapData) map.Data.List.ElementAt(surfaceLinesLayerIndex); + Assert.AreNotEqual(oldSurfaceLineData, surfaceLineData); + Assert.IsInstanceOf(map.Data); - mocks.VerifyAll(); + mocks.VerifyAll(); + } } [Test] public void UpdateObserver_FailureMechanismSectionsUpdated_SetNewMapData() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - var mocks = new MockRepository(); - var assessmentSectionMock = mocks.Stub(); - mocks.ReplayAll(); + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); - view.Data = pipingContext; - var oldSectionsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionsLayerIndex); - var oldSectionStartsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionStartsLayerIndex); - var oldSectionEndsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionEndsLayerIndex); + view.Data = pipingContext; + var oldSectionsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionsLayerIndex); + var oldSectionStartsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionStartsLayerIndex); + var oldSectionEndsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionEndsLayerIndex); - var section = new FailureMechanismSection(string.Empty, new[] - { - new Point2D(1, 2), - new Point2D(1, 2) - }); - pipingFailureMechanism.AddSection(section); + var section = new FailureMechanismSection(string.Empty, new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + }); + pipingFailureMechanism.AddSection(section); - // Call - pipingFailureMechanism.NotifyObservers(); + // Call + pipingFailureMechanism.NotifyObservers(); - // Assert - var sectionsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionsLayerIndex); - var sectionStartsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionStartsLayerIndex); - var sectionEndsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionEndsLayerIndex); - Assert.AreNotEqual(oldSectionsData, sectionsData); - Assert.AreNotEqual(oldSectionStartsData, sectionStartsData); - Assert.AreNotEqual(oldSectionEndsData, sectionEndsData); - Assert.IsInstanceOf(map.Data); + // Assert + var sectionsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionsLayerIndex); + var sectionStartsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionStartsLayerIndex); + var sectionEndsData = (FeatureBasedMapData) map.Data.List.ElementAt(sectionEndsLayerIndex); + Assert.AreNotEqual(oldSectionsData, sectionsData); + Assert.AreNotEqual(oldSectionStartsData, sectionStartsData); + Assert.AreNotEqual(oldSectionEndsData, sectionEndsData); + Assert.IsInstanceOf(map.Data); - mocks.VerifyAll(); + mocks.VerifyAll(); + } } [Test] public void UpdateObserver_StochasticSoilModelsUpdated_SetNewMapData() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - var mocks = new MockRepository(); - var assessmentSectionMock = mocks.Stub(); - mocks.ReplayAll(); + var mocks = new MockRepository(); + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); - var pipingFailureMechanism = new PipingFailureMechanism(); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); + var pipingFailureMechanism = new PipingFailureMechanism(); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSectionMock); - view.Data = pipingContext; - var oldStochasticSoilModelData = (FeatureBasedMapData) map.Data.List.ElementAt(stochasticSoilModelsLayerIndex); + view.Data = pipingContext; + var oldStochasticSoilModelData = (FeatureBasedMapData) map.Data.List.ElementAt(stochasticSoilModelsLayerIndex); - var stochasticSoilModel = new StochasticSoilModel(0, "", ""); - stochasticSoilModel.Geometry.AddRange(new[] - { - new Point2D(1, 2), - new Point2D(1, 2) - }); - pipingFailureMechanism.StochasticSoilModels.Add(stochasticSoilModel); + var stochasticSoilModel = new StochasticSoilModel(0, "", ""); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + }); + pipingFailureMechanism.StochasticSoilModels.Add(stochasticSoilModel); - // Call - pipingFailureMechanism.StochasticSoilModels.NotifyObservers(); + // Call + pipingFailureMechanism.StochasticSoilModels.NotifyObservers(); - // Assert - var stochasticSoilModelData = (FeatureBasedMapData) map.Data.List.ElementAt(stochasticSoilModelsLayerIndex); - Assert.AreNotEqual(oldStochasticSoilModelData, stochasticSoilModelData); - Assert.IsInstanceOf(map.Data); + // Assert + var stochasticSoilModelData = (FeatureBasedMapData) map.Data.List.ElementAt(stochasticSoilModelsLayerIndex); + Assert.AreNotEqual(oldStochasticSoilModelData, stochasticSoilModelData); + Assert.IsInstanceOf(map.Data); - mocks.VerifyAll(); + mocks.VerifyAll(); + } } [Test] public void UpdateObserver_OtherAssessmentSectionUpdated_MapDataNotUpdated() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; - - var assessmentSection = new TestAssessmentSection + using (var view = new PipingFailureMechanismView()) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), - ReferenceLine = new ReferenceLine() - }; - assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); - assessmentSection.ReferenceLine.SetGeometry(new List - { - new Point2D(1.0, 2.0), - new Point2D(2.0, 1.0) - }); + var map = (MapControl) view.Controls[0]; - var stochasticSoilModel = new StochasticSoilModel(0, "", ""); - stochasticSoilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 2.0), - new Point2D(1.1, 2.2) - }); - var pipingFailureMechanism = new PipingFailureMechanism(); - pipingFailureMechanism.StochasticSoilModels.AddRange(new[] - { - stochasticSoilModel - }); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); + var assessmentSection = new TestAssessmentSection + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), + ReferenceLine = new ReferenceLine() + }; + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + assessmentSection.ReferenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); - view.Data = pipingContext; + var stochasticSoilModel = new StochasticSoilModel(0, "", ""); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 2.0), + new Point2D(1.1, 2.2) + }); + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); - var assessmentSection2 = new TestAssessmentSection - { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), - ReferenceLine = new ReferenceLine() - }; - assessmentSection2.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)); - assessmentSection.ReferenceLine.SetGeometry(new List - { - new Point2D(2.0, 1.0), - new Point2D(4.0, 3.0) - }); + view.Data = pipingContext; - // Call - assessmentSection2.NotifyObservers(); + var assessmentSection2 = new TestAssessmentSection + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), + ReferenceLine = new ReferenceLine() + }; + assessmentSection2.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0)); + assessmentSection.ReferenceLine.SetGeometry(new List + { + new Point2D(2.0, 1.0), + new Point2D(4.0, 3.0) + }); - // Assert - Assert.AreEqual(pipingContext, view.Data); - Assert.IsInstanceOf(map.Data); + // Call + assessmentSection2.NotifyObservers(); + + // Assert + Assert.AreEqual(pipingContext, view.Data); + Assert.IsInstanceOf(map.Data); + } } [Test] public void UpdateObserver_DataNull_MapDataNotUpdated() { // Setup - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; - - var assessmentSection = new TestAssessmentSection + using (var view = new PipingFailureMechanismView()) { - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), - ReferenceLine = new ReferenceLine() - }; - assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); - assessmentSection.ReferenceLine.SetGeometry(new List - { - new Point2D(1.0, 2.0), - new Point2D(2.0, 1.0) - }); + var map = (MapControl) view.Controls[0]; - var stochasticSoilModel = new StochasticSoilModel(0, "", ""); - stochasticSoilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 2.0), - new Point2D(1.1, 2.2) - }); + var assessmentSection = new TestAssessmentSection + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(), + ReferenceLine = new ReferenceLine() + }; + assessmentSection.HydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + assessmentSection.ReferenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); - var pipingFailureMechanism = new PipingFailureMechanism(); - pipingFailureMechanism.StochasticSoilModels.AddRange(new[] - { - stochasticSoilModel - }); - var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); + var stochasticSoilModel = new StochasticSoilModel(0, "", ""); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 2.0), + new Point2D(1.1, 2.2) + }); - view.Data = pipingContext; + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }); + var pipingContext = new PipingFailureMechanismContext(pipingFailureMechanism, assessmentSection); - view.Data = null; - MapData dataBeforeUpdate = map.Data; + view.Data = pipingContext; - assessmentSection.ReferenceLine = new ReferenceLine(); - assessmentSection.ReferenceLine.SetGeometry(new List - { - new Point2D(2.0, 5.0), - new Point2D(34.0, 2.0) - }); + view.Data = null; + MapData dataBeforeUpdate = map.Data; - // Call - assessmentSection.NotifyObservers(); + assessmentSection.ReferenceLine = new ReferenceLine(); + assessmentSection.ReferenceLine.SetGeometry(new List + { + new Point2D(2.0, 5.0), + new Point2D(34.0, 2.0) + }); - // Assert - Assert.AreEqual(dataBeforeUpdate, map.Data); + // Call + assessmentSection.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, map.Data); + } } [Test] @@ -539,20 +559,22 @@ var oldPipingFailureMechanismContext = new PipingFailureMechanismContext(new PipingFailureMechanism(), oldAssessmentSectionMock); var newPipingFailureMechanismContext = new PipingFailureMechanismContext(new PipingFailureMechanism(), newAssessmentSectionMock); - var view = new PipingFailureMechanismView(); - var map = (MapControl) view.Controls[0]; + using (var view = new PipingFailureMechanismView()) + { + var map = (MapControl) view.Controls[0]; - view.Data = oldPipingFailureMechanismContext; - view.Data = newPipingFailureMechanismContext; - MapData dataBeforeUpdate = map.Data; + view.Data = oldPipingFailureMechanismContext; + view.Data = newPipingFailureMechanismContext; + MapData dataBeforeUpdate = map.Data; - newAssessmentSectionMock.ReferenceLine.SetGeometry(Enumerable.Empty()); + newAssessmentSectionMock.ReferenceLine.SetGeometry(Enumerable.Empty()); - // Call - oldAssessmentSectionMock.NotifyObservers(); + // Call + oldAssessmentSectionMock.NotifyObservers(); - // Assert - Assert.AreEqual(dataBeforeUpdate, map.Data); + // Assert + Assert.AreEqual(dataBeforeUpdate, map.Data); + } } private const int referenceLineLayerIndex = 0; Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs =================================================================== diff -u -rf816a8ef737d38b4f044855b73abf3ea32b79422 -re0e813ab11c3b35020a785cebf275366cd2eaf9d --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs (.../PipingInputViewTest.cs) (revision f816a8ef737d38b4f044855b73abf3ea32b79422) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Views/PipingInputViewTest.cs (.../PipingInputViewTest.cs) (revision e0e813ab11c3b35020a785cebf275366cd2eaf9d) @@ -19,13 +19,17 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Linq; using System.Windows.Forms; +using Core.Common.Base.Geometry; +using Core.Components.Charting.Data; using Core.Components.Charting.Forms; using Core.Components.OxyPlot.Forms; using NUnit.Framework; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.Properties; using Ringtoets.Piping.Forms.Views; +using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Forms.Test.Views { @@ -36,75 +40,418 @@ public void DefaultConstructor_DefaultValues() { // Call - PipingInputView view = new PipingInputView(); - - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsNotNull(view.Chart); - Assert.IsNull(view.Data); + using (PipingInputView view = new PipingInputView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNotNull(view.Chart); + Assert.IsNull(view.Data); + } } [Test] - public void DefaultConstructor_Always_AddChartControl() + public void DefaultConstructor_Always_AddChartControlWithEmptyCollectionData() { // Call - PipingInputView view = new PipingInputView(); - - // Assert - Assert.AreEqual(1, view.Controls.Count); - ChartControl chartControl = view.Controls[0] as ChartControl; - Assert.IsNotNull(chartControl); - Assert.AreEqual(DockStyle.Fill, chartControl.Dock); - Assert.IsNotNull(chartControl.Data); - Assert.AreEqual(Resources.PipingInputView_Distance_DisplayName, chartControl.BottomAxisTitle); - Assert.AreEqual(Resources.PipingInputView_Height_DisplayName, chartControl.LeftAxisTitle); + using (PipingInputView view = new PipingInputView()) + { + // Assert + Assert.AreEqual(1, view.Controls.Count); + ChartControl chartControl = view.Controls[0] as ChartControl; + Assert.IsNotNull(chartControl); + Assert.AreEqual(DockStyle.Fill, chartControl.Dock); + Assert.IsNotNull(chartControl.Data); + CollectionAssert.IsEmpty(chartControl.Data.List); + Assert.AreEqual(Resources.PipingInputView_Distance_DisplayName, chartControl.BottomAxisTitle); + Assert.AreEqual(Resources.PipingInputView_Height_DisplayName, chartControl.LeftAxisTitle); + } } [Test] public void Data_PipingInput_DataSet() { // Setup - PipingInput input = new PipingInput(new GeneralPipingInput()); - PipingInputView view = new PipingInputView(); + using (PipingInputView view = new PipingInputView()) + { + PipingInput input = new PipingInput(new GeneralPipingInput()); - // Call - view.Data = input; + // Call + view.Data = input; - // Assert - Assert.AreSame(input, view.Data); + // Assert + Assert.AreSame(input, view.Data); + } } [Test] public void Data_OtherThanPipingInput_DataNull() { // Setup - object input = new object(); - PipingInputView view = new PipingInputView(); + using (PipingInputView view = new PipingInputView()) + { + object input = new object(); - // Call - view.Data = input; + // Call + view.Data = input; - // Assert - Assert.IsNull(view.Data); + // Assert + Assert.IsNull(view.Data); + } } [Test] public void Calculation_Always_SetsCalculationAndUpdateChartTitle() { // Setup - PipingCalculationScenario calculation = new PipingCalculationScenario(new GeneralPipingInput()) + using (PipingInputView view = new PipingInputView()) { - Name = "Test name" - }; - PipingInputView view = new PipingInputView(); + PipingCalculationScenario calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = "Test name" + }; - // Call - view.Calculation = calculation; + // Call + view.Calculation = calculation; - // Assert - Assert.AreSame(calculation, view.Calculation); - Assert.AreEqual(calculation.Name, view.Chart.ChartTitle); + // Assert + Assert.AreSame(calculation, view.Calculation); + Assert.AreEqual(calculation.Name, view.Chart.ChartTitle); + } } + + [Test] + public void Data_SetChartData_ChartDataSet() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + // Call + view.Data = pipingInput; + + // Assert + Assert.AreSame(pipingInput, view.Data); + Assert.IsInstanceOf(view.Chart.Data); + var chartData = view.Chart.Data; + Assert.IsNotNull(chartData); + + Assert.AreEqual(1, chartData.List.Count); + AssertSurfaceLineChartData(surfaceLine, chartData.List[0]); + } + } + + [Test] + public void UpdateObservers_CalculationNotSet_ChartTitleNotUpdated() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var pipingInput = new PipingInput(new GeneralPipingInput()); + view.Data = pipingInput; + + // Precondition + Assert.IsNull(view.Chart.ChartTitle); + + // Call + pipingInput.NotifyObservers(); + + // Assert + Assert.IsNull(view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObservers_CalculationNameUpdated_ChartTitleUpdated() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var initialName = "Initial name"; + var updatedName = "Updated name"; + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = initialName + }; + + view.Calculation = calculation; + + // Precondition + Assert.AreEqual(initialName, view.Chart.ChartTitle); + + calculation.Name = updatedName; + + // Call + calculation.NotifyObservers(); + + // Assert + Assert.AreEqual(updatedName, view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObservers_OtherCalculationNameUpdated_ChartTitleNotUpdated() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var initialName = "Initial name"; + var updatedName = "Updated name"; + + var calculation1 = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = initialName + }; + var calculation2 = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = initialName + }; + + view.Calculation = calculation1; + + // Precondition + Assert.AreEqual(initialName, view.Chart.ChartTitle); + + calculation2.Name = updatedName; + + // Call + calculation1.NotifyObservers(); + + // Assert + Assert.AreEqual(initialName, view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObservers_CalculationUpdatedNotifyObserversOnOldData_NoUpdateInViewData() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var initialName = "Initial name"; + var updatedName = "Updated name"; + + var calculation = new PipingCalculationScenario(new GeneralPipingInput()) + { + Name = initialName + }; + + view.Calculation = calculation; + + // Precondition + Assert.AreEqual(initialName, view.Chart.ChartTitle); + + view.Calculation = null; + + calculation.Name = updatedName; + + // Call + calculation.NotifyObservers(); + + // Assert + Assert.AreEqual(initialName, view.Chart.ChartTitle); + } + } + + [Test] + public void UpdateObservers_CalculationSurfaceLineUpdated_SetNewChartData() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + + var pipingInput = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + view.Data = pipingInput; + ChartLineData oldSurfaceLineChartData = (ChartLineData) view.Chart.Data.List[0]; + + var points2 = new[] + { + new Point3D(3.5, 2.3, 8.0), + new Point3D(6.9, 2.0, 2.0) + }; + + var surfaceLine2 = new RingtoetsPipingSurfaceLine(); + surfaceLine2.SetGeometry(points2); + + pipingInput.SurfaceLine = surfaceLine2; + + // Call + pipingInput.NotifyObservers(); + + // Assert + ChartLineData newSurfaceLineChartData = (ChartLineData)view.Chart.Data.List[0]; + Assert.AreNotEqual(oldSurfaceLineChartData, newSurfaceLineChartData); + AssertSurfaceLineChartData(surfaceLine2, newSurfaceLineChartData); + } + } + + [Test] + public void UpdateObserver_OtherPipingInputUpdated_ChartDataNotUpdated() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + var input1 = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + var input2 = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + view.Data = input1; + + var points2 = new[] + { + new Point3D(3.5, 2.3, 8.0), + new Point3D(6.9, 2.0, 2.0) + }; + + var surfaceLine2 = new RingtoetsPipingSurfaceLine(); + surfaceLine2.SetGeometry(points2); + + input2.SurfaceLine = surfaceLine2; + + // Call + input2.NotifyObservers(); + + // Assert + Assert.AreEqual(input1, view.Data); + } + } + + [Test] + public void UpdateObserver_DataNull_ChartDataNotUpdated() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + var input = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + + view.Data = input; + + ChartData dataBeforeUpdate = view.Chart.Data; + + view.Data = null; + + var points2 = new[] + { + new Point3D(3.5, 2.3, 8.0), + new Point3D(6.9, 2.0, 2.0) + }; + + var surfaceLine2 = new RingtoetsPipingSurfaceLine(); + surfaceLine2.SetGeometry(points2); + + input.SurfaceLine = surfaceLine2; + + // Call + input.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, view.Chart.Data); + } + } + + [Test] + public void NotifyObservers_DataUpdatedNotifyObserversOnOldData_NoUpdateInViewData() + { + // Setup + using (PipingInputView view = new PipingInputView()) + { + var points = new[] + { + new Point3D(1.2, 2.3, 4.0), + new Point3D(2.7, 2.0, 6.0) + }; + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(points); + var input1 = new PipingInput(new GeneralPipingInput()) + { + SurfaceLine = surfaceLine + }; + var input2 = new PipingInput(new GeneralPipingInput()); + + view.Data = input1; + ChartData dataBeforeUpdate = view.Chart.Data; + + view.Data = input2; + + var points2 = new[] + { + new Point3D(3.5, 2.3, 8.0), + new Point3D(6.9, 2.0, 2.0) + }; + + var surfaceLine2 = new RingtoetsPipingSurfaceLine(); + surfaceLine2.SetGeometry(points2); + + input1.SurfaceLine = surfaceLine2; + + // Call + input1.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, view.Chart.Data); + } + } + + private void AssertSurfaceLineChartData(RingtoetsPipingSurfaceLine surfaceLine, ChartData chartData) + { + Assert.IsInstanceOf(chartData); + ChartLineData surfaceLineChartData = (ChartLineData) chartData; + + Assert.AreEqual(surfaceLine.Points.Length, surfaceLineChartData.Points.Count()); + CollectionAssert.AreEqual(surfaceLine.ProjectGeometryToLZ(), surfaceLineChartData.Points); + Assert.AreEqual(Resources.RingtoetsPipingSurfaceLine_DisplayName, chartData.Name); + } } } \ No newline at end of file