Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs =================================================================== diff -u -rd705284acf98d459d09b5b2afd48ec3a629c9a3f -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision d705284acf98d459d09b5b2afd48ec3a629c9a3f) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Plugin/ClosingStructuresPlugin.cs (.../ClosingStructuresPlugin.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -314,8 +314,10 @@ { var builder = new RingtoetsContextMenuBuilder(Gui.Get(closingStructuresFailureMechanismContext, treeViewControl)); - return builder.AddToggleRelevancyOfFailureMechanismItem(closingStructuresFailureMechanismContext, RemoveAllViewsForItem) + return builder.AddOpenItem() .AddSeparator() + .AddToggleRelevancyOfFailureMechanismItem(closingStructuresFailureMechanismContext, RemoveAllViewsForItem) + .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem(closingStructuresFailureMechanismContext, ValidateAll, ValidateAllDataAvailableAndGetErrorMessageForCalculationsInFailureMechanism) Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r2b26e7134b3918e67f8b23a6db3f90fad0d4f12e -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision 2b26e7134b3918e67f8b23a6db3f90fad0d4f12e) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/TreeNodeInfos/ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs (.../ClosingStructureFailureMechanismContextTreeNodeInfoTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -55,12 +55,12 @@ [TestFixture] public class ClosingStructureFailureMechanismContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuRelevancyIndexWhenRelevant = 0; + private const int contextMenuRelevancyIndexWhenRelevant = 2; private const int contextMenuRelevancyIndexWhenNotRelevant = 0; - private const int contextMenuValidateAllIndex = 2; - private const int contextMenuCalculateAllIndex = 3; - private const int contextMenuClearAllIndex = 4; + private const int contextMenuValidateAllIndex = 4; + private const int contextMenuCalculateAllIndex = 5; + private const int contextMenuClearAllIndex = 6; private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); @@ -200,6 +200,8 @@ var guiMock = mocksRepository.StrictMock(); var menuBuilderMock = mocksRepository.StrictMock(); + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -284,7 +286,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView)) { // Assert - Assert.AreEqual(10, menu.Items.Count); + Assert.AreEqual(12, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant, "I&s relevant", Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFactory.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFactory.cs (.../RingtoetsMapDataFactory.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFactory.cs (.../RingtoetsMapDataFactory.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -24,6 +24,7 @@ using System.Drawing.Drawing2D; using Core.Components.Gis.Data; using Core.Components.Gis.Style; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; @@ -115,7 +116,7 @@ { return new MapLineData(Resources.DikeProfiles_DisplayName) { - Style = new LineStyle(Color.DarkSeaGreen, 2, DashStyle.Solid) + Style = new LineStyle(Color.SaddleBrown, 2, DashStyle.Solid) }; } @@ -127,8 +128,20 @@ { return new MapLineData(Resources.ForeshoreProfiles_DisplayName) { - Style = new LineStyle(Color.LightSeaGreen, 2, DashStyle.Solid) + Style = new LineStyle(Color.DarkOrange, 2, DashStyle.Solid) }; } + + /// + /// Create with default styling for collections of . + /// + /// The created . + public static MapPointData CreateStructuresMapData() + { + return new MapPointData(Resources.StructuresCollection_DisplayName) + { + Style = new PointStyle(Color.DarkSeaGreen, 15, PointSymbol.Square) + }; + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs (.../RingtoetsMapDataFeaturesFactory.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs (.../RingtoetsMapDataFeaturesFactory.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -26,6 +26,7 @@ using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Core.Components.Gis.Geometries; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; @@ -67,10 +68,7 @@ { foreach (var location in hydraulicBoundaryDatabase.Locations) { - var feature = GetAsSingleMapFeature(new[] - { - location.Location - }); + var feature = GetAsSingleMapFeature(location.Location); feature.MetaData["ID"] = location.Id; feature.MetaData["Name"] = location.Name; @@ -133,7 +131,7 @@ } /// - /// Create features for the foreshore and dike geometry of the . + /// Create features for the geometry of the . /// /// The profiles to create features for. /// An array of features or an empty array when is null or empty. @@ -147,6 +145,11 @@ return dikeProfiles.Select(dikeProfile => GetAsSingleMapFeature(GetWorldPoints(dikeProfile))).ToArray(); } + /// + /// Create features for the geometry of the . + /// + /// The profiles to create features for. + /// An array of features or an empty array when is null or empty. public static MapFeature[] CreateForeshoreProfilesFeatures(IEnumerable foreshoreProfiles) { if (foreshoreProfiles == null || !foreshoreProfiles.Any()) @@ -157,6 +160,21 @@ return foreshoreProfiles.Select(foreshoreProfile => GetAsSingleMapFeature(GetWorldPoints(foreshoreProfile))).ToArray(); } + /// + /// Create features for the geometry of the . + /// + /// The profiles to create features for. + /// An array of features or an empty array when is null or empty. + public static MapFeature[] CreateStructuresFeatures(IEnumerable structures) + { + if (structures == null || !structures.Any()) + { + return new MapFeature[0]; + } + + return structures.Select(structure => GetAsSingleMapFeature(structure.Location)).ToArray(); + } + private static Point2D[] GetWorldPoints(DikeProfile dikeProfile) { return AdvancedMath2D.FromXToXY( @@ -185,5 +203,16 @@ }) }); } + + private static MapFeature GetAsSingleMapFeature(Point2D point) + { + return new MapFeature(new[] + { + new MapGeometry(new[] + { + new [] { point } + }) + }); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFactoryTest.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFactoryTest.cs (.../RingtoetsMapDataFactoryTest.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFactoryTest.cs (.../RingtoetsMapDataFactoryTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -103,7 +103,7 @@ // Assert Assert.IsEmpty(data.Features); Assert.AreEqual(RingtoetsCommonFormsResources.DikeProfiles_DisplayName, data.Name); - AssertEqualStyle(data.Style, Color.DarkSeaGreen, 2, DashStyle.Solid); + AssertEqualStyle(data.Style, Color.SaddleBrown, 2, DashStyle.Solid); } [Test] @@ -115,9 +115,21 @@ // Assert Assert.IsEmpty(data.Features); Assert.AreEqual(RingtoetsCommonFormsResources.ForeshoreProfiles_DisplayName, data.Name); - AssertEqualStyle(data.Style, Color.LightSeaGreen, 2, DashStyle.Solid); + AssertEqualStyle(data.Style, Color.DarkOrange, 2, DashStyle.Solid); } + [Test] + public void CreateStructuresMapData_ReturnsEmptyMapPointDataWithDefaultStyling() + { + // Call + MapPointData data = RingtoetsMapDataFactory.CreateStructuresMapData(); + + // Assert + Assert.IsEmpty(data.Features); + Assert.AreEqual(RingtoetsCommonFormsResources.StructuresCollection_DisplayName, data.Name); + AssertEqualStyle(data.Style, Color.DarkSeaGreen, 15, PointSymbol.Square); + } + private static string GetSectionPointDisplayName(string name) { return string.Format("{0} ({1})", Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsFailureMechanismViewTest.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (.../GrassCoverErosionOutwardsFailureMechanismViewTest.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (.../GrassCoverErosionOutwardsFailureMechanismViewTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -585,7 +585,6 @@ CollectionAssert.IsEmpty(referenceLineMapData.Features); CollectionAssert.IsEmpty(sectionsMapData.Features); CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); - CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); CollectionAssert.IsEmpty(hydraulicBoundaryDatabaseMapData.Features); Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj =================================================================== diff -u -rbc4c4000ca4a850b49a88156ca2b919ea690494b -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision bc4c4000ca4a850b49a88156ca2b919ea690494b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Ringtoets.HeightStructures.Forms.csproj (.../Ringtoets.HeightStructures.Forms.csproj) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -51,6 +51,12 @@ + + UserControl + + + HeightStructuresFailureMechanismView.cs + UserControl @@ -84,6 +90,21 @@ Core.Common.Utils False + + {5a91174a-fb95-4c9d-9ca5-81c0b8d4361a} + Core.Components.DotSpatial.Forms + False + + + {4A06DF0D-5D75-4BAD-A95A-A3DB9B7C4AD5} + Core.Components.Gis.Forms + False + + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data @@ -99,6 +120,11 @@ Ringtoets.Common.Utils False + + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} + Ringtoets.HydraRing.Data + False + {1c0017d8-35b5-4ca0-8fc7-a83f46dbdc99} Ringtoets.HeightStructures.Data @@ -110,6 +136,11 @@ Copying.licenseheader + + + HeightStructuresFailureMechanismView.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -85,6 +85,14 @@ public override IEnumerable GetViewInfos() { + yield return new ViewInfo + { + GetViewName = (view, mechanism) => mechanism.WrappedData.Name, + Image = RingtoetsCommonFormsResources.CalculationIcon, + CloseForData = CloseHeightStructuresFailureMechanismViewForData, + AdditionalDataCheck = context => context.WrappedData.IsRelevant + }; + yield return new ViewInfo< HeightStructuresScenariosContext, CalculationGroup, @@ -230,8 +238,23 @@ #region ViewInfo - #region HeightStructuresFailureMechanismResultView ViewInfo + # region HeightStructuresFailureMechanismView ViewInfo + private bool CloseHeightStructuresFailureMechanismViewForData(HeightStructuresFailureMechanismView view, object o) + { + var assessmentSection = o as IAssessmentSection; + var failureMechanism = o as HeightStructuresFailureMechanism; + + var viewFailureMechanismContext = (HeightStructuresFailureMechanismContext)view.Data; + var viewFailureMechanism = viewFailureMechanismContext.WrappedData; + + return assessmentSection != null + ? ReferenceEquals(viewFailureMechanismContext.Parent, assessmentSection) + : ReferenceEquals(viewFailureMechanism, failureMechanism); + } + + # endregion + #region HeightStructuresScenariosView ViewInfo private static bool CloseScenariosViewForData(HeightStructuresScenariosView view, object removedData) @@ -257,6 +280,8 @@ #endregion + #region HeightStructuresFailureMechanismResultView ViewInfo + private static bool CloseFailureMechanismResultViewForData(HeightStructuresFailureMechanismResultView view, object o) { var assessmentSection = o as IAssessmentSection; @@ -362,8 +387,10 @@ { var builder = new RingtoetsContextMenuBuilder(Gui.Get(context, treeViewControl)); - return builder.AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem) + return builder.AddOpenItem() .AddSeparator() + .AddToggleRelevancyOfFailureMechanismItem(context, RemoveAllViewsForItem) + .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem( context, ValidateAll, Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj =================================================================== diff -u -rbc4c4000ca4a850b49a88156ca2b919ea690494b -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj (.../Ringtoets.HeightStructures.Plugin.csproj) (revision bc4c4000ca4a850b49a88156ca2b919ea690494b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/Ringtoets.HeightStructures.Plugin.csproj (.../Ringtoets.HeightStructures.Plugin.csproj) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -65,6 +65,11 @@ Core.Common.Gui False + + {4a06df0d-5d75-4bad-a95a-a3db9b7c4ad5} + Core.Components.Gis.Forms + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj =================================================================== diff -u -r98f01944e8ac182e2a1e9b1ed4deb48a07952529 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision 98f01944e8ac182e2a1e9b1ed4deb48a07952529) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Ringtoets.HeightStructures.Forms.Test.csproj (.../Ringtoets.HeightStructures.Forms.Test.csproj) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -80,6 +80,7 @@ + @@ -121,6 +122,18 @@ {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {5A91174A-FB95-4C9D-9CA5-81C0B8D4361A} + Core.Components.DotSpatial.Forms + + + {4A06DF0D-5D75-4BAD-A95A-A3DB9B7C4AD5} + Core.Components.Gis.Forms + + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r2b26e7134b3918e67f8b23a6db3f90fad0d4f12e -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision 2b26e7134b3918e67f8b23a6db3f90fad0d4f12e) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -55,11 +55,13 @@ [TestFixture] public class HeightStructuresFailureMechanismContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuRelevancyIndexWhenRelevant = 0; + private const int contextMenuRelevancyIndexWhenRelevant = 2; private const int contextMenuRelevancyIndexWhenNotRelevant = 0; - private const int contextMenuValidateAllIndex = 2; - private const int contextMenuCalculateAllIndex = 3; - private const int contextMenuClearAllIndex = 4; + + private const int contextMenuValidateAllIndex = 4; + private const int contextMenuCalculateAllIndex = 5; + private const int contextMenuClearAllIndex = 6; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private MockRepository mocksRepository; @@ -188,6 +190,8 @@ var guiMock = mocksRepository.StrictMock(); var menuBuilderMock = mocksRepository.StrictMock(); + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -273,7 +277,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView)) { // Assert - Assert.AreEqual(10, menu.Items.Count); + Assert.AreEqual(12, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant, RingtoetsCommonFormsResources.FailureMechanismContextMenuStrip_Is_relevant, Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -0,0 +1,684 @@ +// 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.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Components.DotSpatial.Forms; +using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Contribution; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Data; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; +using HeightStructuresDataResources = Ringtoets.HeightStructures.Data.Properties.Resources; + +namespace Ringtoets.HeightStructures.Forms.Test.Views +{ + [TestFixture] + public class HeightStructuresFailureMechanismViewTest + { + private const int referenceLineIndex = 0; + private const int sectionsIndex = 1; + private const int sectionsStartPointIndex = 2; + private const int sectionsEndPointIndex = 3; + private const int hydraulicBoundaryDatabaseIndex = 4; + private const int foreshoreProfilesIndex = 5; + private const int structuresIndex = 6; + + [Test] + public void DefaultConstructor_DefaultValues() + { + // Call + using (var view = new HeightStructuresFailureMechanismView()) + { + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNotNull(view.Map); + Assert.IsNull(view.Data); + } + } + + [Test] + public void DefaultConstructor_Always_AddMapControlWithCollectionOfEmptyMapData() + { + // Call + using (var view = new HeightStructuresFailureMechanismView()) + { + // Assert + Assert.AreEqual(1, view.Controls.Count); + Assert.AreSame(view.Map, view.Controls[0]); + Assert.AreEqual(DockStyle.Fill, ((Control)view.Map).Dock); + Assert.AreEqual(HeightStructuresDataResources.HeightStructuresFailureMechanism_DisplayName, view.Map.Data.Name); + AssertEmptyMapData(view.Map.Data); + } + } + + [Test] + public void Data_HeightStructuresFailureMechanismContext_DataSet() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), new TestAssessmentSection()); + + // Call + view.Data = failureMechanismContext; + + // Assert + Assert.AreSame(failureMechanismContext, view.Data); + } + } + + [Test] + public void Data_OtherThanHeightStructuresFailureMechanismContext_DataNull() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var data = new object(); + + // Call + view.Data = data; + + // Assert + Assert.IsNull(view.Data); + } + } + + [Test] + public void Data_SetToNull_MapDataCleared() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), new TestAssessmentSection()); + + view.Data = failureMechanismContext; + + // Precondition + Assert.AreEqual(7, view.Map.Data.Collection.Count()); + + // Call + view.Data = null; + + // Assert + Assert.IsNull(view.Data); + Assert.IsNull(view.Map.Data); + } + } + + [Test] + public void Data_EmptyHeightStructuresFailureMechanismContext_NoMapDataSet() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), new TestAssessmentSection()); + + // Call + view.Data = failureMechanismContext; + + // Assert + Assert.AreSame(failureMechanismContext, view.Data); + AssertEmptyMapData(view.Map.Data); + } + } + + [Test] + public void Data_HeightStructuresFailureMechanismContext_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + 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 hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + hydraulicBoundaryDatabase.Locations.Add(new HydraulicBoundaryLocation(1, "test", 1.0, 2.0)); + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + var assessmentSection = new TestAssessmentSection + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase, + ReferenceLine = referenceLine + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + 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.ForeshoreProfiles.Add(new TestForeshoreProfile()); + failureMechanism.ForeshoreProfiles.Add(new TestForeshoreProfile()); + + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + view.Data = failureMechanismContext; + + // Assert + Assert.AreSame(failureMechanismContext, view.Data); + + var mapData = map.Data; + Assert.IsInstanceOf(mapData); + + var mapDataList = mapData.Collection.ToList(); + Assert.AreEqual(7, mapDataList.Count); + AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + AssertFailureMechanismSectionsMapData(failureMechanism.Sections, mapDataList[sectionsIndex]); + AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, mapDataList[sectionsStartPointIndex]); + AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, mapDataList[sectionsEndPointIndex]); + AssertHydraulicBoundaryLocationsMapData(assessmentSection.HydraulicBoundaryDatabase, mapDataList[hydraulicBoundaryDatabaseIndex]); + AssertForeshoreProfiles(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]); + } + } + + [Test] + public void UpdateObserver_HydraulicBoundaryDatabaseUpdated_MapDataUpdated() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var hydraulicBoundaryDatabase1 = new HydraulicBoundaryDatabase + { + Locations = + { + new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + } + }; + var hydraulicBoundaryDatabase2 = new HydraulicBoundaryDatabase + { + Locations = + { + new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) + } + }; + + var assessmentSection = new TestAssessmentSection + { + HydraulicBoundaryDatabase = hydraulicBoundaryDatabase1 + }; + + var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), assessmentSection); + + view.Data = failureMechanismContext; + + var hydraulicBoundaryDatabaseMapData = map.Data.Collection.ElementAt(hydraulicBoundaryDatabaseIndex); + + // Precondition + AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase1, hydraulicBoundaryDatabaseMapData); + + // Call + assessmentSection.HydraulicBoundaryDatabase = hydraulicBoundaryDatabase2; + assessmentSection.NotifyObservers(); + + // Assert + AssertHydraulicBoundaryLocationsMapData(hydraulicBoundaryDatabase2, hydraulicBoundaryDatabaseMapData); + } + } + + [Test] + public void UpdateObserver_ReferenceLineUpdated_MapDataUpdated() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var points1 = new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }; + + var points2 = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; + + var assessmentSection = new TestAssessmentSection + { + ReferenceLine = new ReferenceLine() + }; + assessmentSection.ReferenceLine.SetGeometry(points1); + + var failureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), assessmentSection); + + view.Data = failureMechanismContext; + + var referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); + + // Precondition + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + + // Call + assessmentSection.ReferenceLine.SetGeometry(points2); + assessmentSection.NotifyObservers(); + + // Assert + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + } + } + + [Test] + public void UpdateObserver_FailureMechanismSectionsUpdated_MapDataUpdated() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, new TestAssessmentSection()); + + view.Data = failureMechanismContext; + + var sectionMapData = (MapLineData)map.Data.Collection.ElementAt(sectionsIndex); + var sectionStartsMapData = (MapPointData)map.Data.Collection.ElementAt(sectionsStartPointIndex); + var sectionsEndsMapData = (MapPointData)map.Data.Collection.ElementAt(sectionsEndPointIndex); + + // Call + failureMechanism.AddSection(new FailureMechanismSection(string.Empty, new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + })); + failureMechanism.NotifyObservers(); + + // Assert + AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData); + AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData); + AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData); + } + } + + [Test] + public void UpdateObserver_ForeshoreProfilesUpdated_MapDataUpdated() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, new TestAssessmentSection()); + + failureMechanism.ForeshoreProfiles.Add(new TestForeshoreProfile()); + + view.Data = failureMechanismContext; + + var foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + + // Precondition + AssertForeshoreProfiles(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + + // Call + failureMechanism.ForeshoreProfiles.Add(new TestForeshoreProfile()); + failureMechanism.ForeshoreProfiles.NotifyObservers(); + + // Assert + AssertForeshoreProfiles(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + } + } + + [Test] + public void UpdateObserver_StructuresUpdated_MapDataUpdated() + { + // Setup + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, new TestAssessmentSection()); + + failureMechanism.ForeshoreProfiles.Add(new TestForeshoreProfile()); + + view.Data = failureMechanismContext; + + var structuresData = map.Data.Collection.ElementAt(structuresIndex); + + // Precondition + AssertStructures(failureMechanism.HeightStructures, structuresData); + + // Call + failureMechanism.HeightStructures.Add(new TestHeightStructure()); + failureMechanism.HeightStructures.NotifyObservers(); + + // Assert + AssertStructures(failureMechanism.HeightStructures, structuresData); + } + } + + [Test] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedRefenceLineLayerIndex = referenceLineIndex + 6; + const int updatedSectionsLayerIndex = sectionsIndex - 1; + const int updateSectionStartLayerIndex = sectionsStartPointIndex - 1; + const int updatedSectionEndLayerIndex = sectionsEndPointIndex - 1; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryDatabaseIndex - 1; + const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; + const int updatedStructuresLayerIndex = structuresIndex- 1; + + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var assessmentSection = new TestAssessmentSection(); + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); + + view.Data = failureMechanismContext; + + var mapData = map.Data; + + var dataToMove = (MapLineData)map.Data.Collection.ElementAt(referenceLineIndex); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); + + var mapDataList = mapData.Collection.ToList(); + + // Precondition + var referenceLineData = (MapLineData)mapDataList[updatedRefenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.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 foreshoreProfilesData = (MapLineData)mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + + var structuresData = (MapPointData)mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", structuresData.Name); + + var points = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; + ReferenceLine referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(points); + assessmentSection.ReferenceLine = referenceLine; + + // Call + assessmentSection.NotifyObservers(); + + // Call + var actualReferenceLineData = (MapLineData)mapDataList[updatedRefenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", actualReferenceLineData.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 actualForeshoreProfilesData = (MapLineData)mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualStructuresData = (MapPointData)mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", actualStructuresData.Name); + } + } + + [Test] + public void NotifyObservers_DataUpdatedNotifyObserversOnOldData_NoUpdateInViewData() + { + // Setup + IAssessmentSection oldAssessmentSection = new TestAssessmentSection(); + IAssessmentSection newAssessmentSection = new TestAssessmentSection(); + + newAssessmentSection.ReferenceLine = new ReferenceLine(); + newAssessmentSection.ReferenceLine.SetGeometry(new[] + { + new Point2D(2, 4), + new Point2D(3, 4) + }); + + var oldHeightStructuresFailureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), oldAssessmentSection); + var newHeightStructuresFailureMechanismContext = new HeightStructuresFailureMechanismContext(new HeightStructuresFailureMechanism(), newAssessmentSection); + using (var view = new HeightStructuresFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + view.Data = oldHeightStructuresFailureMechanismContext; + view.Data = newHeightStructuresFailureMechanismContext; + MapData dataBeforeUpdate = map.Data; + + newAssessmentSection.ReferenceLine.SetGeometry(Enumerable.Empty()); + + // Call + oldAssessmentSection.NotifyObservers(); + + // Assert + Assert.AreEqual(dataBeforeUpdate, map.Data); + } + } + + private static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var referenceLineData = (MapLineData)mapData; + if (referenceLine == null) + { + CollectionAssert.IsEmpty(referenceLineData.Features.First().MapGeometries.First().PointCollections.First()); + } + else + { + CollectionAssert.AreEqual(referenceLine.Points, referenceLineData.Features.First().MapGeometries.First().PointCollections.First()); + } + Assert.AreEqual("Referentielijn", mapData.Name); + } + + private static void AssertForeshoreProfiles(IEnumerable foreshoreProfiles, MapData mapData) + { + Assert.NotNull(foreshoreProfiles, "foreshoreProfiles should never be null."); + + var foreshoreProfilesData = (MapLineData)mapData; + var foreshoreProfileArray = foreshoreProfiles.ToArray(); + + Assert.AreEqual(foreshoreProfileArray.Length, foreshoreProfilesData.Features.Length); + + for (int i = 0; i < foreshoreProfileArray.Length; i++) + { + var profileDataA = foreshoreProfilesData.Features.ElementAt(i).MapGeometries.First(); + CollectionAssert.AreEquivalent(foreshoreProfileArray[0].Geometry, profileDataA.PointCollections.First()); + } + + Assert.AreEqual("Voorlandprofielen", mapData.Name); + } + + private static void AssertStructures(IEnumerable structures, MapData mapData) + { + Assert.NotNull(structures, "structures should never be null."); + + var structuresData = (MapPointData)mapData; + var structuresArray = structures.ToArray(); + + Assert.AreEqual(structuresArray.Length, structuresData.Features.Length); + + for (int i = 0; i < structuresArray.Length; i++) + { + var profileDataA = structuresData.Features.ElementAt(i).MapGeometries.First(); + Assert.AreEqual(structuresArray[0].Location, profileDataA.PointCollections.First().First()); + } + + Assert.AreEqual("Kunstwerken", mapData.Name); + } + + private static void AssertHydraulicBoundaryLocationsMapData(HydraulicBoundaryDatabase database, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var hydraulicLocationsMapData = (MapPointData)mapData; + if (database == null) + { + CollectionAssert.IsEmpty(hydraulicLocationsMapData.Features.First().MapGeometries.First().PointCollections.First()); + } + else + { + CollectionAssert.AreEqual(database.Locations.Select(hrp => hrp.Location), hydraulicLocationsMapData.Features.First().MapGeometries.First().PointCollections.First()); + } + Assert.AreEqual("Hydraulische randvoorwaarden", mapData.Name); + } + + private static void AssertFailureMechanismSectionsMapData(IEnumerable sections, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var sectionsMapLinesData = (MapLineData)mapData; + var sectionMapLinesFeatures = sectionsMapLinesData.Features.ToArray(); + Assert.AreEqual(1, sectionMapLinesFeatures.Length); + + var geometries = sectionMapLinesFeatures.First().MapGeometries.ToArray(); + var sectionsArray = sections.ToArray(); + Assert.AreEqual(sectionsArray.Length, geometries.Length); + + for (int index = 0; index < sectionsArray.Length; index++) + { + var failureMechanismSection = sectionsArray[index]; + CollectionAssert.AreEquivalent(failureMechanismSection.Points, geometries[index].PointCollections.First()); + } + Assert.AreEqual("Vakindeling", mapData.Name); + } + + private static void AssertFailureMechanismSectionsStartPointMapData(IEnumerable sections, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var sectionsStartPointData = (MapPointData)mapData; + CollectionAssert.AreEqual(sections.Select(s => s.GetStart()), sectionsStartPointData.Features.First().MapGeometries.First().PointCollections.First()); + Assert.AreEqual("Vakindeling (startpunten)", mapData.Name); + } + + private static void AssertFailureMechanismSectionsEndPointMapData(IEnumerable sections, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var sectionsStartPointData = (MapPointData)mapData; + CollectionAssert.AreEqual(sections.Select(s => s.GetLast()), sectionsStartPointData.Features.First().MapGeometries.First().PointCollections.First()); + Assert.AreEqual("Vakindeling (eindpunten)", mapData.Name); + } + + private static void AssertEmptyMapData(MapDataCollection mapData) + { + Assert.IsInstanceOf(mapData); + + var mapDataList = mapData.Collection.ToList(); + + Assert.AreEqual(7, mapDataList.Count); + + var referenceLineMapData = (MapLineData)mapDataList[referenceLineIndex]; + var sectionsMapData = (MapLineData)mapDataList[sectionsIndex]; + var foreshoreProfilesMapData = (MapLineData)mapDataList[foreshoreProfilesIndex]; + var structuresMapData = (MapPointData)mapDataList[structuresIndex]; + var sectionsStartPointMapData = (MapPointData)mapDataList[sectionsStartPointIndex]; + var sectionsEndPointMapData = (MapPointData)mapDataList[sectionsEndPointIndex]; + var hydraulicBoundaryDatabaseMapData = (MapPointData)mapDataList[hydraulicBoundaryDatabaseIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(sectionsMapData.Features); + CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); + CollectionAssert.IsEmpty(structuresMapData.Features); + CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); + CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryDatabaseMapData.Features); + + Assert.AreEqual(RingtoetsCommonDataResources.ReferenceLine_DisplayName, referenceLineMapData.Name); + Assert.AreEqual(RingtoetsCommonFormsResources.FailureMechanism_Sections_DisplayName, sectionsMapData.Name); + Assert.AreEqual(GetSectionPointDisplayName(RingtoetsCommonFormsResources.FailureMechanismSections_StartPoints_DisplayName), sectionsStartPointMapData.Name); + Assert.AreEqual(GetSectionPointDisplayName(RingtoetsCommonFormsResources.FailureMechanismSections_EndPoints_DisplayName), sectionsEndPointMapData.Name); + Assert.AreEqual(RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName, hydraulicBoundaryDatabaseMapData.Name); + } + + private static string GetSectionPointDisplayName(string name) + { + return string.Format("{0} ({1})", + RingtoetsCommonFormsResources.FailureMechanism_Sections_DisplayName, + name); + } + + private class TestAssessmentSection : Observable, IAssessmentSection + { + public string Id { get; set; } + public string Name { get; set; } + public string Comments { get; set; } + public AssessmentSectionComposition Composition { get; private set; } + public ReferenceLine ReferenceLine { get; set; } + public FailureMechanismContribution FailureMechanismContribution { get; private set; } + public HydraulicBoundaryDatabase HydraulicBoundaryDatabase { get; set; } + + public IEnumerable GetFailureMechanisms() + { + yield break; + } + + public void ChangeComposition(AssessmentSectionComposition newComposition) + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r5724d9646d808c712d3bd87ecc89d8e23426c83f -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 5724d9646d808c712d3bd87ecc89d8e23426c83f) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using System.Linq; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -28,6 +29,7 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; @@ -146,10 +148,24 @@ ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); // Assert - Assert.AreEqual(2, viewInfos.Length); + Assert.AreEqual(3, viewInfos.Length); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(HeightStructuresFailureMechanismResultView))); - Assert.IsTrue(viewInfos.Any(vi => vi.ViewType == typeof(HeightStructuresScenariosView))); + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(HeightStructuresFailureMechanismContext), + typeof(HeightStructuresFailureMechanismView)); + + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(FailureMechanismSectionResultContext), + typeof(IEnumerable), + typeof(HeightStructuresFailureMechanismResultView)); + + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(HeightStructuresScenariosContext), + typeof(CalculationGroup), + typeof(HeightStructuresScenariosView)); } mocks.VerifyAll(); } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj =================================================================== diff -u -r2d5e2d09b0cb1a7f48e1b0a067d332347c89d4a8 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision 2d5e2d09b0cb1a7f48e1b0a067d332347c89d4a8) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/Ringtoets.HeightStructures.Plugin.Test.csproj (.../Ringtoets.HeightStructures.Plugin.Test.csproj) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -55,6 +55,7 @@ Properties\GlobalAssembly.cs + @@ -92,6 +93,10 @@ {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {4a06df0d-5d75-4bad-a95a-a3db9b7c4ad5} + Core.Components.Gis.Forms + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresFailureMechanismViewInfoTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresFailureMechanismViewInfoTest.cs (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -0,0 +1,209 @@ +// 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.Linq; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Forms.Views; +using HeightStructuresDataResources = Ringtoets.HeightStructures.Data.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.HeightStructures.Plugin.Test.ViewInfos +{ + [TestFixture] + public class HeightStructuresFailureMechanismViewInfoTest + { + private MockRepository mocks; + private HeightStructuresPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(HeightStructuresFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(HeightStructuresFailureMechanismContext), info.DataType); + Assert.AreEqual(typeof(HeightStructuresFailureMechanismContext), info.ViewDataType); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculationIcon, info.Image); + } + + [Test] + public void GetViewName_WithHeightStructuresFailureMechanism_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var view = new HeightStructuresFailureMechanismView()) + { + // Call + string viewName = info.GetViewName(view, failureMechanismContext); + + // Assert + Assert.AreEqual(failureMechanism.Name, viewName); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + var otherAssessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var view = new HeightStructuresFailureMechanismView + { + Data = failureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, otherAssessmentSectionMock); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var view = new HeightStructuresFailureMechanismView + { + Data = failureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSectionMock); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var otherHeightStructuresFailureMechanism = new HeightStructuresFailureMechanism(); + + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var view = new HeightStructuresFailureMechanismView + { + Data = failureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, otherHeightStructuresFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var failureMechanismContext = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); + + using (var view = new HeightStructuresFailureMechanismView + { + Data = failureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void AdditionalDataCheck_Always_ReturnTrueOnlyIfFailureMechanismRelevant(bool isRelevant) + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism + { + IsRelevant = isRelevant + }; + + var context = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + bool result = info.AdditionalDataCheck(context); + + // Assert + Assert.AreEqual(isRelevant, result); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -r01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -374,8 +374,10 @@ { var builder = new RingtoetsContextMenuBuilder(Gui.Get(failureMechanismContext, treeViewControl)); - return builder.AddToggleRelevancyOfFailureMechanismItem(failureMechanismContext, RemoveAllViewsForItem) + return builder.AddOpenItem() .AddSeparator() + .AddToggleRelevancyOfFailureMechanismItem(failureMechanismContext, RemoveAllViewsForItem) + .AddSeparator() .AddValidateAllCalculationsInFailureMechanismItem( failureMechanismContext, ValidateAll, Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision 01aa3a0cf07a91607a5d4b5e37f2e98c1fc00430) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -53,11 +53,13 @@ [TestFixture] public class StabilityPointStructuresFailureMechanismContextTreeNodeInfoTest : NUnitFormTest { - private const int contextMenuRelevancyIndexWhenRelevant = 0; + private const int contextMenuRelevancyIndexWhenRelevant = 2; private const int contextMenuRelevancyIndexWhenNotRelevant = 0; - private const int contextMenuValidateAllIndex = 2; - private const int contextMenuCalculateAllIndex = 3; - private const int contextMenuClearAllIndex = 4; + + private const int contextMenuValidateAllIndex = 4; + private const int contextMenuCalculateAllIndex = 5; + private const int contextMenuClearAllIndex = 6; + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "HydraulicBoundaryDatabaseImporter"); private MockRepository mocksRepository; @@ -199,6 +201,8 @@ var guiMock = mocksRepository.StrictMock(); var menuBuilderMock = mocksRepository.StrictMock(); + menuBuilderMock.Expect(mb => mb.AddOpenItem()).Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); @@ -290,7 +294,7 @@ using (ContextMenuStrip menu = info.ContextMenuStrip(failureMechanismContext, assessmentSectionMock, treeView)) { // Assert - Assert.AreEqual(10, menu.Items.Count); + Assert.AreEqual(12, menu.Items.Count); TestHelper.AssertContextMenuStripContainsItem(menu, contextMenuRelevancyIndexWhenRelevant, "I&s relevant", Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/Views/StabilityStoneCoverFailureMechanismViewTest.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/Views/StabilityStoneCoverFailureMechanismViewTest.cs (.../StabilityStoneCoverFailureMechanismViewTest.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Forms.Test/Views/StabilityStoneCoverFailureMechanismViewTest.cs (.../StabilityStoneCoverFailureMechanismViewTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -585,7 +585,6 @@ CollectionAssert.IsEmpty(referenceLineMapData.Features); CollectionAssert.IsEmpty(sectionsMapData.Features); CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); - CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); CollectionAssert.IsEmpty(hydraulicBoundaryDatabaseMapData.Features); Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs =================================================================== diff -u -rf718135c08ce7b90cc0eaf40bfb83c9af48a1776 -rf724e2a23cc180381b736c4da1318d87398e5758 --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewTest.cs) (revision f718135c08ce7b90cc0eaf40bfb83c9af48a1776) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewTest.cs) (revision f724e2a23cc180381b736c4da1318d87398e5758) @@ -585,7 +585,6 @@ CollectionAssert.IsEmpty(referenceLineMapData.Features); CollectionAssert.IsEmpty(sectionsMapData.Features); CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); - CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); CollectionAssert.IsEmpty(hydraulicBoundaryDatabaseMapData.Features);