Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r0bcae8b23e2364c988df54e70695322b5a8c9829 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs (.../GrassCoverErosionInwardsFailureMechanismView.cs) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismView.cs (.../GrassCoverErosionInwardsFailureMechanismView.cs) (revision 0bcae8b23e2364c988df54e70695322b5a8c9829) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections; using System.Collections.Generic; using System.Windows.Forms; using Core.Common.Base; @@ -39,7 +38,7 @@ namespace Ringtoets.GrassCoverErosionInwards.Forms.Views { /// - /// This class is a view showing map data for a GrassCoverErosionInwards failure mechanism. + /// This class is a view showing map data for a grass cover erosion inwards failure mechanism. /// public partial class GrassCoverErosionInwardsFailureMechanismView : UserControl, IMapView { Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r0bcae8b23e2364c988df54e70695322b5a8c9829 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision 0bcae8b23e2364c988df54e70695322b5a8c9829) @@ -31,7 +31,9 @@ using NUnit.Framework; 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.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; @@ -190,6 +192,9 @@ grassCoverErosionInwardsFailureMechanism.AddSection(new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2))); grassCoverErosionInwardsFailureMechanism.AddSection(new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2))); + grassCoverErosionInwardsFailureMechanism.DikeProfiles.Add(new TestDikeProfile()); + grassCoverErosionInwardsFailureMechanism.DikeProfiles.Add(new TestDikeProfile()); + var grassCoverErosionInwardsContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSection); // Call @@ -208,6 +213,7 @@ AssertFailureMechanismSectionsStartPointMapData(grassCoverErosionInwardsFailureMechanism.Sections, mapDataList[sectionsStartPointIndex]); AssertFailureMechanismSectionsEndPointMapData(grassCoverErosionInwardsFailureMechanism.Sections, mapDataList[sectionsEndPointIndex]); AssertHydraulicBoundaryLocationsMapData(assessmentSection.HydraulicBoundaryDatabase, mapDataList[hydraulicBoundaryDatabaseIndex]); + AssertDikeProfiles(grassCoverErosionInwardsFailureMechanism.DikeProfiles, mapDataList[dikeProfilesIndex]); } } @@ -334,6 +340,35 @@ } [Test] + public void UpdateObserver_DikeProfilesUpdated_MapDataUpdated() + { + // Setup + using (var view = new GrassCoverErosionInwardsFailureMechanismView()) + { + var map = (MapControl)view.Controls[0]; + + var grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, new TestAssessmentSection()); + + grassCoverErosionInwardsFailureMechanism.DikeProfiles.Add(new TestDikeProfile()); + + view.Data = grassCoverErosionInwardsContext; + + var dikeProfileData = map.Data.Collection.ElementAt(dikeProfilesIndex); + + // Precondition + AssertDikeProfiles(grassCoverErosionInwardsFailureMechanism.DikeProfiles, dikeProfileData); + + // Call + grassCoverErosionInwardsFailureMechanism.DikeProfiles.Add(new TestDikeProfile()); + grassCoverErosionInwardsFailureMechanism.DikeProfiles.NotifyObservers(); + + // Assert + AssertDikeProfiles(grassCoverErosionInwardsFailureMechanism.DikeProfiles, dikeProfileData); + } + } + + [Test] public void UpdateObserver_DataUpdated_MapLayersSameOrder() { // Setup @@ -463,6 +498,28 @@ Assert.AreEqual("Referentielijn", mapData.Name); } + private static void AssertDikeProfiles(IEnumerable dikeProfiles, MapData mapData) + { + Assert.NotNull(dikeProfiles, "dikeProfiles should never be null."); + Assert.IsInstanceOf(mapData); + var dikeProfilesData = (MapLineData) mapData; + Assert.AreEqual(2, dikeProfilesData.Features.Length); + + var foreshoreProfileData = dikeProfilesData.Features.ElementAt(0).MapGeometries.ToArray(); + var dikeProfileData = dikeProfilesData.Features.ElementAt(1).MapGeometries.ToArray(); + var dikeProfileArray = dikeProfiles.ToArray(); + Assert.AreEqual(dikeProfileArray.Length, foreshoreProfileData.Length); + Assert.AreEqual(dikeProfileArray.Length, dikeProfileData.Length); + + for (int index = 0; index < dikeProfileArray.Length; index++) + { + var dikeProfile = dikeProfileArray.ElementAt(index); + CollectionAssert.AreEquivalent(dikeProfile.DikeGeometry, dikeProfileData[index].PointCollections.First()); + CollectionAssert.AreEquivalent(dikeProfile.ForeshoreProfile.Geometry, foreshoreProfileData[index].PointCollections.First()); + } + Assert.AreEqual("Dijkprofielen", mapData.Name); + } + private static void AssertHydraulicBoundaryLocationsMapData(HydraulicBoundaryDatabase database, MapData mapData) { Assert.IsInstanceOf(mapData); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r0bcae8b23e2364c988df54e70695322b5a8c9829 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Plugin.Test.csproj) (revision 0bcae8b23e2364c988df54e70695322b5a8c9829) @@ -60,6 +60,7 @@ + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ViewInfos/GrassCoverErosionInwardsFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ViewInfos/GrassCoverErosionInwardsFailureMechanismViewInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ViewInfos/GrassCoverErosionInwardsFailureMechanismViewInfoTest.cs (revision 0bcae8b23e2364c988df54e70695322b5a8c9829) @@ -0,0 +1,210 @@ +// 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.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; +using Ringtoets.GrassCoverErosionInwards.Forms.Views; +using GrassCoverErosionInwardsDataResources = Ringtoets.GrassCoverErosionInwards.Data.Properties.Resources; +using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismViewInfoTest + { + private MockRepository mocks; + private GrassCoverErosionInwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new GrassCoverErosionInwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(GrassCoverErosionInwardsFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(GrassCoverErosionInwardsFailureMechanismContext), info.DataType); + Assert.AreEqual(typeof(GrassCoverErosionInwardsFailureMechanismContext), info.ViewDataType); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.CalculationIcon, info.Image); + } + + [Test] + public void GetViewName_WithGrassCoverErosionInwardsFailureMechanism_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsFailureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSectionMock); + + using (var view = new GrassCoverErosionInwardsFailureMechanismView()) + { + // Call + string viewName = info.GetViewName(view, grassCoverErosionInwardsFailureMechanismContext); + + // Assert + Assert.AreEqual(grassCoverErosionInwardsFailureMechanism.Name, viewName); + } + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + var otherAssessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsFailureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSectionMock); + + using (var view = new GrassCoverErosionInwardsFailureMechanismView + { + Data = grassCoverErosionInwardsFailureMechanismContext + }) + { + // 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 grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsFailureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSectionMock); + + using (var view = new GrassCoverErosionInwardsFailureMechanismView + { + Data = grassCoverErosionInwardsFailureMechanismContext + }) + { + // 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 grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var otherGrassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var grassCoverErosionInwardsFailureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSectionMock); + + using (var view = new GrassCoverErosionInwardsFailureMechanismView + { + Data = grassCoverErosionInwardsFailureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, otherGrassCoverErosionInwardsFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSectionMock = mocks.Stub(); + mocks.ReplayAll(); + + var grassCoverErosionInwardsFailureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var grassCoverErosionInwardsFailureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(grassCoverErosionInwardsFailureMechanism, assessmentSectionMock); + + using (var view = new GrassCoverErosionInwardsFailureMechanismView + { + Data = grassCoverErosionInwardsFailureMechanismContext + }) + { + // Call + bool closeForData = info.CloseForData(view, grassCoverErosionInwardsFailureMechanism); + + // 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 GrassCoverErosionInwardsFailureMechanism + { + IsRelevant = isRelevant + }; + + var context = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + // Call + bool result = info.AdditionalDataCheck(context); + + // Assert + Assert.AreEqual(isRelevant, result); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ViewInfos/PipingFailureMechanismViewInfoTest.cs =================================================================== diff -u -r2aeb951ddc6e2137897569a2de4c55c9fb7e2420 -r0bcae8b23e2364c988df54e70695322b5a8c9829 --- Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ViewInfos/PipingFailureMechanismViewInfoTest.cs (.../PipingFailureMechanismViewInfoTest.cs) (revision 2aeb951ddc6e2137897569a2de4c55c9fb7e2420) +++ Ringtoets/Piping/test/Ringtoets.Piping.Plugin.Test/ViewInfos/PipingFailureMechanismViewInfoTest.cs (.../PipingFailureMechanismViewInfoTest.cs) (revision 0bcae8b23e2364c988df54e70695322b5a8c9829) @@ -65,7 +65,7 @@ } [Test] - public void GetViewName_WithPipingFailureMechanism_ReturnsTextFromResources() + public void GetViewName_WithPipingFailureMechanism_ReturnsNameOfFailureMechanism() { // Setup var assessmentSectionMock = mocks.Stub();