Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsFailureMechanismView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsFailureMechanismView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsFailureMechanismView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/GrassCoverErosionOutwardsFailurePathView.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.Designer.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.Designer.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.Designer.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,64 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +namespace Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState +{ + partial class GrassCoverErosionOutwardsFailureMechanismView + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.riskeerMapControl = new Riskeer.Common.Forms.Views.RiskeerMapControl(); + this.SuspendLayout(); + // + // riskeerMapControl + // + this.riskeerMapControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.riskeerMapControl.Location = new System.Drawing.Point(0, 0); + this.riskeerMapControl.Name = "riskeerMapControl"; + this.riskeerMapControl.Size = new System.Drawing.Size(150, 150); + this.riskeerMapControl.TabIndex = 0; + // + // GrassCoverErosionOutwardsFailureMechanismView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.riskeerMapControl); + this.Name = "GrassCoverErosionOutwardsFailureMechanismView"; + this.ResumeLayout(false); + + } + + #endregion + + private Common.Forms.Views.RiskeerMapControl riskeerMapControl; + } +} Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,259 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Forms.Factories; +using Riskeer.Common.Forms.MapLayers; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Forms.Factories; +using Riskeer.Revetment.Data; +using GrassCoverErosionOutwardsDataResources = Riskeer.GrassCoverErosionOutwards.Data.Properties.Resources; + +namespace Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState +{ + /// + /// Hydraulic loads state view showing map data for a grass cover erosion outwards failure mechanism. + /// + public partial class GrassCoverErosionOutwardsFailureMechanismView : UserControl, IMapView + { + private HydraulicBoundaryLocationsMapLayer hydraulicBoundaryLocationsMapLayer; + + private MapLineData referenceLineMapData; + private MapLineData foreshoreProfilesMapData; + private MapLineData calculationsMapData; + + private Observer assessmentSectionObserver; + private Observer referenceLineObserver; + private Observer foreshoreProfilesObserver; + + private RecursiveObserver calculationInputObserver; + private RecursiveObserver calculationGroupObserver; + private RecursiveObserver calculationObserver; + private RecursiveObserver foreshoreProfileObserver; + + /// + /// Creates a new instance of . + /// + /// The failure mechanism to show the data for. + /// The assessment section to show the data for. + /// Thrown when any parameter is null. + public GrassCoverErosionOutwardsFailureMechanismView(GrassCoverErosionOutwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + InitializeComponent(); + + FailureMechanism = failureMechanism; + AssessmentSection = assessmentSection; + } + + /// + /// Gets the failure mechanism. + /// + public GrassCoverErosionOutwardsFailureMechanism FailureMechanism { get; } + + /// + /// Gets the assessment section. + /// + public IAssessmentSection AssessmentSection { get; } + + public object Data { get; set; } + + public IMapControl Map + { + get + { + return riskeerMapControl.MapControl; + } + } + + /// + /// Gets the . + /// + protected MapDataCollection MapDataCollection { get; private set; } + + protected override void OnLoad(EventArgs e) + { + CreateObservers(); + + CreateMapData(); + + SetAllMapDataFeatures(); + + riskeerMapControl.SetAllData(MapDataCollection, AssessmentSection.BackgroundData); + + base.OnLoad(e); + } + + protected override void Dispose(bool disposing) + { + hydraulicBoundaryLocationsMapLayer.Dispose(); + + assessmentSectionObserver.Dispose(); + referenceLineObserver.Dispose(); + foreshoreProfilesObserver.Dispose(); + foreshoreProfileObserver.Dispose(); + calculationInputObserver.Dispose(); + calculationGroupObserver.Dispose(); + calculationObserver.Dispose(); + + if (disposing) + { + components?.Dispose(); + } + + base.Dispose(disposing); + } + + /// + /// Creates the map data. + /// + protected virtual void CreateMapData() + { + hydraulicBoundaryLocationsMapLayer = new HydraulicBoundaryLocationsMapLayer(AssessmentSection); + + MapDataCollection = new MapDataCollection(GrassCoverErosionOutwardsDataResources.GrassCoverErosionOutwardsFailureMechanism_DisplayName); + referenceLineMapData = RiskeerMapDataFactory.CreateReferenceLineMapData(); + foreshoreProfilesMapData = RiskeerMapDataFactory.CreateForeshoreProfileMapData(); + calculationsMapData = RiskeerMapDataFactory.CreateCalculationsMapData(); + + MapDataCollection.Add(referenceLineMapData); + MapDataCollection.Add(hydraulicBoundaryLocationsMapLayer.MapData); + MapDataCollection.Add(foreshoreProfilesMapData); + MapDataCollection.Add(calculationsMapData); + } + + /// + /// Creates the observers. + /// + protected virtual void CreateObservers() + { + assessmentSectionObserver = new Observer(UpdateReferenceLineData) + { + Observable = AssessmentSection + }; + referenceLineObserver = new Observer(UpdateReferenceLineData) + { + Observable = AssessmentSection.ReferenceLine + }; + foreshoreProfilesObserver = new Observer(UpdateForeshoreProfilesMapData) + { + Observable = FailureMechanism.ForeshoreProfiles + }; + + calculationInputObserver = new RecursiveObserver( + UpdateCalculationsMapData, pcg => pcg.Children.Concat(pcg.Children.OfType() + .Select(pc => pc.InputParameters))) + { + Observable = FailureMechanism.CalculationsGroup + }; + calculationGroupObserver = new RecursiveObserver(UpdateCalculationsMapData, pcg => pcg.Children) + { + Observable = FailureMechanism.CalculationsGroup + }; + calculationObserver = new RecursiveObserver(UpdateCalculationsMapData, pcg => pcg.Children) + { + Observable = FailureMechanism.CalculationsGroup + }; + foreshoreProfileObserver = new RecursiveObserver(UpdateForeshoreProfilesMapData, coll => coll) + { + Observable = FailureMechanism.ForeshoreProfiles + }; + } + + /// + /// Sets all map data features. + /// + protected virtual void SetAllMapDataFeatures() + { + SetReferenceLineMapData(); + SetForeshoreProfilesMapData(); + SetCalculationsMapData(); + } + + #region Calculations MapData + + private void UpdateCalculationsMapData() + { + SetCalculationsMapData(); + calculationsMapData.NotifyObservers(); + } + + private void SetCalculationsMapData() + { + IEnumerable calculations = + FailureMechanism.CalculationsGroup.GetCalculations().Cast(); + calculationsMapData.Features = GrassCoverErosionOutwardsMapDataFeaturesFactory.CreateCalculationFeatures(calculations); + } + + #endregion + + #region AssessmentSection MapData + + private void UpdateReferenceLineData() + { + SetReferenceLineMapData(); + referenceLineMapData.NotifyObservers(); + } + + private void SetReferenceLineMapData() + { + ReferenceLine referenceLine = AssessmentSection.ReferenceLine; + referenceLineMapData.Features = RiskeerMapDataFeaturesFactory.CreateReferenceLineFeatures(referenceLine, AssessmentSection.Id, AssessmentSection.Name); + } + + #endregion + + #region Foreshore Profiles MapData + + private void UpdateForeshoreProfilesMapData() + { + SetForeshoreProfilesMapData(); + foreshoreProfilesMapData.NotifyObservers(); + } + + private void SetForeshoreProfilesMapData() + { + IEnumerable foreshoreProfiles = FailureMechanism.ForeshoreProfiles; + foreshoreProfilesMapData.Features = RiskeerMapDataFeaturesFactory.CreateForeshoreProfilesFeatures(foreshoreProfiles); + } + + #endregion + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.resx =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.resx (revision 0) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismView.resx (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismView.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismView.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Forms/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismView.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,124 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using Core.Common.Base; +using Core.Components.Gis.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Forms.Factories; +using Riskeer.Common.Forms.MapLayers; +using Riskeer.GrassCoverErosionOutwards.Data; +using GrassCoverErosionOutwardsDataResources = Riskeer.GrassCoverErosionOutwards.Data.Properties.Resources; + +namespace Riskeer.GrassCoverErosionOutwards.Forms.Views.RegistrationState +{ + /// + /// Registration state view showing map data for a grass cover erosion outwards failure mechanism. + /// + public class GrassCoverErosionOutwardsFailureMechanismView : HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismView + { + private MapLineData sectionsMapData; + private MapPointData sectionsStartPointMapData; + private MapPointData sectionsEndPointMapData; + + private NonCalculatableFailureMechanismSectionResultsMapLayer assemblyResultMapLayer; + + private Observer failureMechanismObserver; + + /// + /// Creates a new instance of . + /// + /// The failure mechanism to show the data for. + /// The assessment section to show the data for. + /// Thrown when any parameter is null. + public GrassCoverErosionOutwardsFailureMechanismView(GrassCoverErosionOutwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(failureMechanism, assessmentSection) {} + + protected override void Dispose(bool disposing) + { + failureMechanismObserver.Dispose(); + assemblyResultMapLayer.Dispose(); + + base.Dispose(disposing); + } + + protected override void CreateMapData() + { + base.CreateMapData(); + + MapDataCollection sectionsMapDataCollection = RiskeerMapDataFactory.CreateSectionsMapDataCollection(); + sectionsMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsMapData(); + sectionsStartPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); + sectionsEndPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); + + assemblyResultMapLayer = new NonCalculatableFailureMechanismSectionResultsMapLayer( + FailureMechanism, sr => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.AssembleSection(sr, FailureMechanism, AssessmentSection)); + + sectionsMapDataCollection.Add(sectionsMapData); + sectionsMapDataCollection.Add(sectionsStartPointMapData); + sectionsMapDataCollection.Add(sectionsEndPointMapData); + MapDataCollection.Insert(1, sectionsMapDataCollection); + + MapDataCollection.Insert(2, assemblyResultMapLayer.MapData); + } + + protected override void CreateObservers() + { + base.CreateObservers(); + + failureMechanismObserver = new Observer(UpdateFailureMechanismData) + { + Observable = FailureMechanism + }; + } + + protected override void SetAllMapDataFeatures() + { + base.SetAllMapDataFeatures(); + + SetSectionsMapData(); + } + + #region FailureMechanism MapData + + private void UpdateFailureMechanismData() + { + SetSectionsMapData(); + sectionsMapData.NotifyObservers(); + sectionsStartPointMapData.NotifyObservers(); + sectionsEndPointMapData.NotifyObservers(); + } + + private void SetSectionsMapData() + { + IEnumerable failureMechanismSections = FailureMechanism.Sections; + + sectionsMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(failureMechanismSections); + sectionsStartPointMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionStartPointFeatures(failureMechanismSections); + sectionsEndPointMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionEndPointFeatures(failureMechanismSections); + } + + #endregion + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -r0a988b3667d32fbae19e420aa71038bcc97d3b38 -r9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b --- Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 0a988b3667d32fbae19e420aa71038bcc97d3b38) +++ Riskeer/GrassCoverErosionOutwards/src/Riskeer.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -61,6 +61,8 @@ using Riskeer.Revetment.Service; using HydraulicLoadsStateFailureMechanismProperties = Riskeer.GrassCoverErosionOutwards.Forms.PropertyClasses.HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.GrassCoverErosionOutwards.Forms.PropertyClasses.RegistrationState.GrassCoverErosionOutwardsFailureMechanismProperties; +using HydraulicLoadsStateFailureMechanismView = Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.GrassCoverErosionOutwards.Forms.Views.RegistrationState.GrassCoverErosionOutwardsFailureMechanismView; using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; using RiskeerCommonIoResources = Riskeer.Common.IO.Properties.Resources; @@ -113,17 +115,17 @@ public override IEnumerable GetViewInfos() { - yield return new RiskeerViewInfo(() => Gui) + yield return new RiskeerViewInfo(() => Gui) { GetViewName = (view, context) => context.WrappedData.Name, - CreateInstance = context => new GrassCoverErosionOutwardsFailureMechanismView(context.WrappedData, context.Parent) + CreateInstance = context => new HydraulicLoadsStateFailureMechanismView(context.WrappedData, context.Parent) }; - yield return new RiskeerViewInfo(() => Gui) + yield return new RiskeerViewInfo(() => Gui) { GetViewName = (view, context) => context.WrappedData.Name, AdditionalDataCheck = context => context.WrappedData.InAssembly, - CreateInstance = context => new GrassCoverErosionOutwardsFailurePathView(context.WrappedData, context.Parent), + CreateInstance = context => new RegistrationStateFailureMechanismView(context.WrappedData, context.Parent), CloseForData = CloseFailurePathViewForData }; @@ -282,7 +284,7 @@ #region ViewInfos - private static bool CloseFailurePathViewForData(GrassCoverErosionOutwardsFailurePathView view, object dataToCloseFor) + private static bool CloseFailurePathViewForData(RegistrationStateFailureMechanismView view, object dataToCloseFor) { var failureMechanism = dataToCloseFor as GrassCoverErosionOutwardsFailureMechanism; Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsFailureMechanismViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsFailurePathViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,676 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState; + +namespace Riskeer.GrassCoverErosionOutwards.Forms.Test.Views.HydraulicLoadsState +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismViewTest + { + private const int referenceLineIndex = 0; + private const int hydraulicBoundaryLocationsIndex = 1; + private const int foreshoreProfilesIndex = 2; + private const int calculationsIndex = 3; + + private const int foreshoreProfileObserverIndex = 1; + private const int calculationObserverIndex = 2; + + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new GrassCoverErosionOutwardsFailureMechanismView(null, assessmentSection); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new GrassCoverErosionOutwardsFailureMechanismView(new GrassCoverErosionOutwardsFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + + Assert.AreEqual(1, view.Controls.Count); + Assert.IsInstanceOf(view.Controls[0]); + Assert.AreSame(view.Map, ((RiskeerMapControl) view.Controls[0]).MapControl); + Assert.AreEqual(DockStyle.Fill, ((Control) view.Map).Dock); + AssertEmptyMapData(view.Map.Data); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() + { + // Setup + IAssessmentSection assessmentSection = new AssessmentSectionStub(); + + // Call + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(new GrassCoverErosionOutwardsFailureMechanism(), assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var calculationA = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var calculationB = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + + var geometryPoints = new[] + { + new Point2D(0.0, 0.0), + new Point2D(2.0, 0.0), + new Point2D(4.0, 4.0), + new Point2D(6.0, 4.0) + }; + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + new FailureMechanismSection("A", geometryPoints.Take(2)), + new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), + new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) + }); + + var profile1 = new TestForeshoreProfile("profile1 ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }); + var profile2 = new TestForeshoreProfile("profile2 ID", new[] + { + new Point2D(2, 2), + new Point2D(3, 3) + }); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile1, + profile2 + }, "path"); + + failureMechanism.CalculationsGroup.Children.Add(calculationA); + failureMechanism.CalculationsGroup.Children.Add(calculationB); + + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + // Call + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + // Assert + MapDataCollection mapData = map.Data; + Assert.IsInstanceOf(mapData); + + List mapDataList = mapData.Collection.ToList(); + Assert.AreEqual(4, mapDataList.Count); + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]); + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + mapDataList[calculationsIndex]); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithAssessmentSectionData_WhenAssessmentSectionUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(new GrassCoverErosionOutwardsFailureMechanism(), assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + var referenceLineMapData = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + + // Precondition + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + + // When + assessmentSection.Name = "New name"; + assessmentSection.NotifyObservers(); + + // Then + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithReferenceLineData_WhenReferenceLineUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new List + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(new GrassCoverErosionOutwardsFailureMechanism(), assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); + + // Precondition + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + + // When + referenceLine.SetGeometry(new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }); + referenceLine.NotifyObservers(); + + // Then + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithForeshoreProfileData_WhenForeshoreProfileUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var foreshoreProfile = new TestForeshoreProfile("originalProfile ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + foreshoreProfile + }, "path"); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + + // Precondition + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + + // When + var foreshoreProfileToUpdateFrom = new TestForeshoreProfile("originalProfile ID", new[] + { + new Point2D(2, 2), + new Point2D(3, 3) + }); + foreshoreProfile.CopyProperties(foreshoreProfileToUpdateFrom); + foreshoreProfile.NotifyObservers(); + + // Then + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithForeshoreProfilesData_WhenForeshoreProfilesUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile("originalProfile ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }) + }, "path"); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + + // Precondition + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + + // When + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile("newProfile ID", new[] + { + new Point2D(2, 2), + new Point2D(3, 3) + }) + }, "path"); + failureMechanism.ForeshoreProfiles.NotifyObservers(); + + // Then + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var calculationA = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); + + // When + var calculationB = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + failureMechanism.CalculationsGroup.Children.Add(calculationB); + failureMechanism.CalculationsGroup.NotifyObservers(); + + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var calculationA = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); + + // When + calculationA.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)); + calculationA.InputParameters.NotifyObservers(); + + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var calculationA = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); + + // When + calculationA.Name = "new name"; + calculationA.NotifyObservers(); + + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 3; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; + const int updatedCalculationsIndex = calculationsIndex - 1; + + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + MapDataCollection mapData = map.Data; + + var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); + + IEnumerable mapDataCollection = mapData.Collection; + + // Precondition + var referenceLineData = (MapLineData) mapDataCollection.ElementAt(updatedReferenceLineLayerIndex); + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataCollection.ElementAt(updatedHydraulicLocationsLayerIndex); + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var foreshoreProfilesData = (MapLineData) mapDataCollection.ElementAt(updatedForeshoreProfilesLayerIndex); + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + + var calculationsData = (MapLineData) mapDataCollection.ElementAt(updatedCalculationsIndex); + Assert.AreEqual("Berekeningen", calculationsData.Name); + + var points = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(points); + assessmentSection.ReferenceLine = referenceLine; + + // Call + assessmentSection.NotifyObservers(); + + // Assert + var actualReferenceLineData = (MapLineData) mapDataCollection.ElementAt(updatedReferenceLineLayerIndex); + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataCollection.ElementAt(updatedHydraulicLocationsLayerIndex); + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualForeshoreProfilesData = (MapLineData) mapDataCollection.ElementAt(updatedForeshoreProfilesLayerIndex); + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualCalculationsData = (MapLineData) mapDataCollection.ElementAt(updatedCalculationsIndex); + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } + + private GrassCoverErosionOutwardsFailureMechanismView CreateView(GrassCoverErosionOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + + private static void AssertCalculationsMapData(IEnumerable calculations, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var calculationsMapData = (MapLineData) mapData; + GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationsArray = calculations.ToArray(); + MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray(); + Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length); + + for (var index = 0; index < calculationsArray.Length; index++) + { + MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray(); + Assert.AreEqual(1, geometries.Length); + + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = calculationsArray[index]; + CollectionAssert.AreEquivalent(new[] + { + calculation.InputParameters.ForeshoreProfile.WorldReferencePoint, + calculation.InputParameters.HydraulicBoundaryLocation.Location + }, geometries[0].PointCollections.First()); + } + + Assert.AreEqual("Berekeningen", mapData.Name); + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Grasbekleding erosie buitentalud", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(4, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var calculationsMapData = (MapLineData) mapDataList[calculationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + CollectionAssert.IsEmpty(calculationsMapData.Features); + + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesMapData.Name); + Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name); + Assert.AreEqual("Berekeningen", calculationsMapData.Name); + } + + /// + /// Attaches mocked observers to all map data components. + /// + /// The . + /// The map data collection containing the + /// elements. + /// An array of mocked observers attached to the data in . + private static IObserver[] AttachMapDataObservers(MockRepository mocks, IEnumerable mapData) + { + MapData[] mapDataArray = mapData.ToArray(); + + var referenceLineMapDataObserver = mocks.StrictMock(); + mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); + + var foreshoreProfilesMapDataObserver = mocks.StrictMock(); + mapDataArray[foreshoreProfilesIndex].Attach(foreshoreProfilesMapDataObserver); + + var calculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); + + return new[] + { + referenceLineMapDataObserver, + foreshoreProfilesMapDataObserver, + calculationsMapDataObserver + }; + } + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Forms.Test/Views/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewTest.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,423 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Forms; +using Core.Components.Gis.Geometries; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Forms.Views.RegistrationState; +using HydraulicLoadsStateFailureMechanismView = Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismView; + +namespace Riskeer.GrassCoverErosionOutwards.Forms.Test.Views.RegistrationState +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismViewTest + { + private const int referenceLineIndex = 0; + private const int sectionsCollectionIndex = 1; + private const int assemblyResultsIndex = 2; + private const int hydraulicBoundaryLocationsIndex = 3; + private const int foreshoreProfilesIndex = 4; + private const int calculationsIndex = 5; + + private const int sectionsIndex = 0; + private const int sectionsStartPointIndex = 1; + private const int sectionsEndPointIndex = 2; + + private const int sectionsObserverIndex = 0; + private const int sectionsStartPointObserverIndex = 1; + private const int sectionsEndPointObserverIndex = 2; + + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + // Assert + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + AssertEmptyMapData(view.Map.Data); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + + var calculationA = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var calculationB = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + + var geometryPoints = new[] + { + new Point2D(0.0, 0.0), + new Point2D(2.0, 0.0), + new Point2D(4.0, 4.0), + new Point2D(6.0, 4.0) + }; + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + new FailureMechanismSection("A", geometryPoints.Take(2)), + new FailureMechanismSection("B", geometryPoints.Skip(1).Take(2)), + new FailureMechanismSection("C", geometryPoints.Skip(2).Take(2)) + }); + + var profile1 = new TestForeshoreProfile("profile1 ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }); + var profile2 = new TestForeshoreProfile("profile2 ID", new[] + { + new Point2D(2, 2), + new Point2D(3, 3) + }); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + profile1, + profile2 + }, "path"); + + failureMechanism.CalculationsGroup.Children.Add(calculationA); + failureMechanism.CalculationsGroup.Children.Add(calculationB); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + // Assert + MapDataCollection mapData = map.Data; + Assert.IsInstanceOf(mapData); + + List mapDataList = mapData.Collection.ToList(); + Assert.AreEqual(6, mapDataList.Count); + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); + + IEnumerable sectionsCollection = ((MapDataCollection) mapDataList[sectionsCollectionIndex]).Collection; + MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsIndex)); + MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsStartPointIndex)); + MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsCollection.ElementAt(sectionsEndPointIndex)); + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]); + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), mapDataList[calculationsIndex]); + + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + MapDataTestHelper.AssertAssemblyMapData(failureMechanism, calculator.FailureMechanismSectionAssemblyResultOutput, mapDataList[assemblyResultsIndex]); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + IEnumerable sectionsCollection = ((MapDataCollection) map.Data.Collection.ElementAt(sectionsCollectionIndex)).Collection; + var sectionMapData = (MapLineData) sectionsCollection.ElementAt(sectionsIndex); + var sectionStartsMapData = (MapPointData) sectionsCollection.ElementAt(sectionsStartPointIndex); + var sectionsEndsMapData = (MapPointData) sectionsCollection.ElementAt(sectionsEndPointIndex); + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[sectionsObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsStartPointObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[sectionsEndPointObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // When + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + new FailureMechanismSection(string.Empty, new[] + { + new Point2D(1, 2), + new Point2D(1, 2) + }) + }); + failureMechanism.NotifyObservers(); + + // Then + MapDataTestHelper.AssertFailureMechanismSectionsMapData(failureMechanism.Sections, sectionMapData); + MapDataTestHelper.AssertFailureMechanismSectionsStartPointMapData(failureMechanism.Sections, sectionStartsMapData); + MapDataTestHelper.AssertFailureMechanismSectionsEndPointMapData(failureMechanism.Sections, sectionsEndsMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 5; + const int updatedSectionsCollectionLayerIndex = sectionsCollectionIndex - 1; + const int updatedAssemblyResultsIndex = assemblyResultsIndex - 1; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; + const int updatedCalculationsIndex = calculationsIndex - 1; + + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + GrassCoverErosionOutwardsFailureMechanismView view = CreateView(failureMechanism, assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + MapDataCollection mapData = map.Data; + + var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); + + IEnumerable mapDataList = mapData.Collection; + + // Precondition + var referenceLineData = (MapLineData) mapDataList.ElementAt(updatedReferenceLineLayerIndex); + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var sectionsData = (MapDataCollection) mapDataList.ElementAt(updatedSectionsCollectionLayerIndex); + Assert.AreEqual("Vakindeling", sectionsData.Name); + + var assemblyResultsData = (MapLineData) mapDataList.ElementAt(updatedAssemblyResultsIndex); + Assert.AreEqual("Duidingsklasse per vak", assemblyResultsData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataList.ElementAt(updatedHydraulicLocationsLayerIndex); + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var foreshoreProfilesData = (MapLineData) mapDataList.ElementAt(updatedForeshoreProfilesLayerIndex); + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + + var calculationsData = (MapLineData) mapDataList.ElementAt(updatedCalculationsIndex); + Assert.AreEqual("Berekeningen", calculationsData.Name); + + var points = new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }; + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(points); + assessmentSection.ReferenceLine = referenceLine; + + // Call + assessmentSection.NotifyObservers(); + + // Assert + var actualReferenceLineData = (MapLineData) mapDataList.ElementAt(updatedReferenceLineLayerIndex); + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + + var actualSectionsData = (MapDataCollection) mapDataList.ElementAt(updatedSectionsCollectionLayerIndex); + Assert.AreEqual("Vakindeling", actualSectionsData.Name); + + var actualAssemblyResultsData = (MapLineData) mapDataList.ElementAt(updatedAssemblyResultsIndex); + Assert.AreEqual("Duidingsklasse per vak", actualAssemblyResultsData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataList.ElementAt(updatedHydraulicLocationsLayerIndex); + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualForeshoreProfilesData = (MapLineData) mapDataList.ElementAt(updatedForeshoreProfilesLayerIndex); + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualCalculationsData = (MapLineData) mapDataList.ElementAt(updatedCalculationsIndex); + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } + + private GrassCoverErosionOutwardsFailureMechanismView CreateView(GrassCoverErosionOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + + private static void AssertCalculationsMapData(IEnumerable calculations, MapData mapData) + { + Assert.IsInstanceOf(mapData); + var calculationsMapData = (MapLineData) mapData; + GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationsArray = calculations.ToArray(); + MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray(); + Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length); + + for (var index = 0; index < calculationsArray.Length; index++) + { + MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray(); + Assert.AreEqual(1, geometries.Length); + + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = calculationsArray[index]; + CollectionAssert.AreEquivalent(new[] + { + calculation.InputParameters.ForeshoreProfile.WorldReferencePoint, + calculation.InputParameters.HydraulicBoundaryLocation.Location + }, geometries[0].PointCollections.First()); + } + + Assert.AreEqual("Berekeningen", mapData.Name); + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Grasbekleding erosie buitentalud", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(6, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var assemblyResultsMapData = (MapLineData) mapDataList[assemblyResultsIndex]; + var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var calculationsMapData = (MapLineData) mapDataList[calculationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(assemblyResultsMapData.Features); + CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + CollectionAssert.IsEmpty(calculationsMapData.Features); + + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + Assert.AreEqual("Duidingsklasse per vak", assemblyResultsMapData.Name); + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesMapData.Name); + Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name); + Assert.AreEqual("Berekeningen", calculationsMapData.Name); + + var sectionsMapDataCollection = (MapDataCollection) mapDataList[sectionsCollectionIndex]; + Assert.AreEqual("Vakindeling", sectionsMapDataCollection.Name); + List sectionsDataList = sectionsMapDataCollection.Collection.ToList(); + Assert.AreEqual(3, sectionsDataList.Count); + + var sectionsMapData = (MapLineData) sectionsDataList[sectionsIndex]; + var sectionsStartPointMapData = (MapPointData) sectionsDataList[sectionsStartPointIndex]; + var sectionsEndPointMapData = (MapPointData) sectionsDataList[sectionsEndPointIndex]; + + CollectionAssert.IsEmpty(sectionsEndPointMapData.Features); + CollectionAssert.IsEmpty(sectionsStartPointMapData.Features); + CollectionAssert.IsEmpty(sectionsMapData.Features); + + Assert.AreEqual("Vakindeling (eindpunten)", sectionsEndPointMapData.Name); + Assert.AreEqual("Vakindeling (startpunten)", sectionsStartPointMapData.Name); + Assert.AreEqual("Vakindeling", sectionsMapData.Name); + } + + /// + /// Attaches mocked observers to all map data components. + /// + /// The . + /// The map data collection containing the + /// elements. + /// An array of mocked observers attached to the data in . + private static IObserver[] AttachMapDataObservers(MockRepository mocks, IEnumerable mapData) + { + MapData[] mapDataArray = mapData.ToArray(); + + MapData[] sectionsCollection = ((MapDataCollection) mapDataArray[sectionsCollectionIndex]).Collection.ToArray(); + var sectionsMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsIndex].Attach(sectionsMapDataObserver); + + var sectionsStartPointMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsStartPointIndex].Attach(sectionsStartPointMapDataObserver); + + var sectionsEndPointMapDataObserver = mocks.StrictMock(); + sectionsCollection[sectionsEndPointIndex].Attach(sectionsEndPointMapDataObserver); + + return new[] + { + sectionsMapDataObserver, + sectionsStartPointMapDataObserver, + sectionsEndPointMapDataObserver + }; + } + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs =================================================================== diff -u -r0a988b3667d32fbae19e420aa71038bcc97d3b38 -r9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs (.../GrassCoverErosionOutwardsPluginTest.cs) (revision 0a988b3667d32fbae19e420aa71038bcc97d3b38) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/GrassCoverErosionOutwardsPluginTest.cs (.../GrassCoverErosionOutwardsPluginTest.cs) (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -36,10 +36,11 @@ using Riskeer.GrassCoverErosionOutwards.Data; using Riskeer.GrassCoverErosionOutwards.Forms.PresentationObjects; using Riskeer.GrassCoverErosionOutwards.Forms.PropertyClasses; -using Riskeer.GrassCoverErosionOutwards.Forms.Views; using Riskeer.Revetment.Forms.Views; using HydraulicLoadsStateFailureMechanismProperties = Riskeer.GrassCoverErosionOutwards.Forms.PropertyClasses.HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.GrassCoverErosionOutwards.Forms.PropertyClasses.RegistrationState.GrassCoverErosionOutwardsFailureMechanismProperties; +using HydraulicLoadsStateFailureMechanismView = Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState.GrassCoverErosionOutwardsFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.GrassCoverErosionOutwards.Forms.Views.RegistrationState.GrassCoverErosionOutwardsFailureMechanismView; namespace Riskeer.GrassCoverErosionOutwards.Plugin.Test { @@ -70,10 +71,10 @@ mockRepository.ReplayAll(); using (var plugin = new GrassCoverErosionOutwardsPlugin - { - Gui = gui - }) { + Gui = gui + }) + { // Call ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); @@ -83,12 +84,12 @@ PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(GrassCoverErosionOutwardsHydraulicLoadsContext), - typeof(GrassCoverErosionOutwardsFailureMechanismView)); + typeof(HydraulicLoadsStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(GrassCoverErosionOutwardsFailurePathContext), - typeof(GrassCoverErosionOutwardsFailurePathView)); + typeof(RegistrationStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, @@ -179,10 +180,10 @@ mocks.ReplayAll(); using (var plugin = new GrassCoverErosionOutwardsPlugin - { - Gui = gui - }) { + Gui = gui + }) + { // Call ExportInfo[] exportInfos = plugin.GetExportInfos().ToArray(); Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b refers to a dead (removed) revision in file `Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsFailurePathViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/HydraulicLoadsState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,97 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Gui.Plugin; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.TestUtil; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Forms.PresentationObjects; +using Riskeer.GrassCoverErosionOutwards.Forms.Views.HydraulicLoadsState; + +namespace Riskeer.GrassCoverErosionOutwards.Plugin.Test.ViewInfos.HydraulicLoadsState +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismViewInfoTest + { + private MockRepository mocks; + private GrassCoverErosionOutwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new GrassCoverErosionOutwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(GrassCoverErosionOutwardsFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(GrassCoverErosionOutwardsHydraulicLoadsContext), info.DataType); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsHydraulicLoadsContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var context = new GrassCoverErosionOutwardsHydraulicLoadsContext(failureMechanism, assessmentSection); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual(failureMechanism.Name, viewName); + } + + [Test] + public void CreateInstance_WithContext_ReturnGrassCoverErosionOutwardsFailureMechanismView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var context = new GrassCoverErosionOutwardsHydraulicLoadsContext(failureMechanism, assessmentSection); + + // Call + var view = (GrassCoverErosionOutwardsFailureMechanismView) info.CreateInstance(context); + + // Assert + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + } +} \ No newline at end of file Index: Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs (revision 0) +++ Riskeer/GrassCoverErosionOutwards/test/Riskeer.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/RegistrationState/GrassCoverErosionOutwardsFailureMechanismViewInfoTest.cs (revision 9f9170f3212fc97c50e3d50d443f52b0bb2b7d1b) @@ -0,0 +1,191 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Linq; +using Core.Gui.Plugin; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.TestUtil; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Forms.PresentationObjects; +using Riskeer.GrassCoverErosionOutwards.Forms.Views.RegistrationState; + +namespace Riskeer.GrassCoverErosionOutwards.Plugin.Test.ViewInfos.RegistrationState +{ + [TestFixture] + public class GrassCoverErosionOutwardsFailureMechanismViewInfoTest + { + private MockRepository mocks; + private GrassCoverErosionOutwardsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new GrassCoverErosionOutwardsPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(GrassCoverErosionOutwardsFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(GrassCoverErosionOutwardsFailurePathContext), info.DataType); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsFailurePathContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var context = new GrassCoverErosionOutwardsFailurePathContext(failureMechanism, assessmentSection); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual(failureMechanism.Name, viewName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void AdditionalDataCheck_Always_ReturnTrueOnlyIfFailureMechanismInAssembly(bool inAssembly) + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + InAssembly = inAssembly + }; + + var context = new GrassCoverErosionOutwardsFailurePathContext(failureMechanism, assessmentSection); + + // Call + bool result = info.AdditionalDataCheck(context); + + // Assert + Assert.AreEqual(inAssembly, result); + mocks.VerifyAll(); + } + + [Test] + public void CreateInstance_WithContext_ReturnGrassCoverErosionOutwardsFailureMechanismView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var context = new GrassCoverErosionOutwardsFailurePathContext(failureMechanism, assessmentSection); + + // Call + var view = (GrassCoverErosionOutwardsFailureMechanismView) info.CreateInstance(context); + + // Assert + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var otherAssessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherAssessmentSection); + + // Assert + Assert.IsFalse(closeForData); + + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var otherGrassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherGrassCoverErosionOutwardsFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var view = new GrassCoverErosionOutwardsFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } +} \ No newline at end of file