Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.Designer.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.Designer.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.Designer.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -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.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState +{ + partial class WaveImpactAsphaltCoverFailureMechanismView + { + /// + /// 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; + // + // WaveImpactAsphaltCoverFailureMechanismView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.riskeerMapControl); + this.Name = "WaveImpactAsphaltCoverFailureMechanismView"; + this.ResumeLayout(false); + + } + + #endregion + + private Common.Forms.Views.RiskeerMapControl riskeerMapControl; + } +} Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -0,0 +1,257 @@ +// 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.Revetment.Data; +using Riskeer.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.Factories; +using WaveImpactAsphaltCoverDataResources = Riskeer.WaveImpactAsphaltCover.Data.Properties.Resources; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState +{ + /// + /// Hydraulic loads state view showing map data for a wave impact asphalt cover failure mechanism. + /// + public partial class WaveImpactAsphaltCoverFailureMechanismView : 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 WaveImpactAsphaltCoverFailureMechanismView(WaveImpactAsphaltCoverFailureMechanism 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 WaveImpactAsphaltCoverFailureMechanism 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(WaveImpactAsphaltCoverDataResources.WaveImpactAsphaltCoverFailureMechanism_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 = WaveImpactAsphaltCoverMapDataFeaturesFactory.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/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.resx =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.resx (revision 0) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismView.resx (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -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/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismView.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismView.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismView.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -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.WaveImpactAsphaltCover.Data; +using WaveImpactAsphaltCoverDataResources = Riskeer.WaveImpactAsphaltCover.Data.Properties.Resources; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Views.RegistrationState +{ + /// + /// Registration state view showing map data for a wave impact asphalt cover failure mechanism. + /// + public class WaveImpactAsphaltCoverFailureMechanismView : HydraulicLoadsState.WaveImpactAsphaltCoverFailureMechanismView + { + 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 WaveImpactAsphaltCoverFailureMechanismView(WaveImpactAsphaltCoverFailureMechanism 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 => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.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 Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailurePathView.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs =================================================================== diff -u -r5319a71f64c1faa285332c83df061eb511d93c59 -rac7f4c3eecc95a1f469ceb08178b77965742b974 --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 5319a71f64c1faa285332c83df061eb511d93c59) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -59,10 +59,12 @@ using Riskeer.WaveImpactAsphaltCover.IO.Configurations; using Riskeer.WaveImpactAsphaltCover.IO.Exporters; using Riskeer.WaveImpactAsphaltCover.Service; -using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources; -using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; using HydraulicLoadsStateFailureMechanismProperties = Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses.HydraulicLoadsState.WaveImpactAsphaltCoverFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses.RegistrationState.WaveImpactAsphaltCoverFailureMechanismProperties; +using HydraulicLoadsStateFailureMechanismView = Riskeer.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState.WaveImpactAsphaltCoverFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.WaveImpactAsphaltCover.Forms.Views.RegistrationState.WaveImpactAsphaltCoverFailureMechanismView; +using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.WaveImpactAsphaltCover.Plugin { @@ -93,17 +95,17 @@ public override IEnumerable GetViewInfos() { - yield return new RiskeerViewInfo(() => Gui) + yield return new RiskeerViewInfo(() => Gui) { GetViewName = (view, context) => context.WrappedData.Name, - CreateInstance = context => new WaveImpactAsphaltCoverFailureMechanismView(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 WaveImpactAsphaltCoverFailurePathView(context.WrappedData, context.Parent), + CreateInstance = context => new RegistrationStateFailureMechanismView(context.WrappedData, context.Parent), CloseForData = CloseFailurePathViewForData }; @@ -280,7 +282,7 @@ #region ViewInfos - private static bool CloseFailurePathViewForData(WaveImpactAsphaltCoverFailurePathView view, object dataToCloseFor) + private static bool CloseFailurePathViewForData(RegistrationStateFailureMechanismView view, object dataToCloseFor) { var failureMechanism = dataToCloseFor as WaveImpactAsphaltCoverFailureMechanism; @@ -463,17 +465,14 @@ foreach (ICalculationBase item in nodeData.WrappedData.Children) { - var calculation = item as WaveImpactAsphaltCoverWaveConditionsCalculation; - var group = item as CalculationGroup; - - if (calculation != null) + if (item is WaveImpactAsphaltCoverWaveConditionsCalculation calculation) { childNodeObjects.Add(new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, nodeData.WrappedData, nodeData.FailureMechanism, nodeData.AssessmentSection)); } - else if (group != null) + else if (item is CalculationGroup @group) { childNodeObjects.Add(new WaveImpactAsphaltCoverCalculationGroupContext(group, nodeData.WrappedData, Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -0,0 +1,681 @@ +// 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.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Test.Views.HydraulicLoadsState +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismViewTest + { + 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 WaveImpactAsphaltCoverFailureMechanismView(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 WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + WaveImpactAsphaltCoverFailureMechanismView 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 + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + 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 WaveImpactAsphaltCoverFailureMechanism(); + 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 + }; + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) + }); + + // Call + WaveImpactAsphaltCoverFailureMechanismView 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 + }; + + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), 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 + }; + + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), 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 WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + foreshoreProfile + }, "path"); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile("originalProfile ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }) + }, "path"); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverWaveConditionsCalculation + { + 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 WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverFailureMechanism(); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverFailureMechanismView CreateView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new WaveImpactAsphaltCoverFailureMechanismView(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; + WaveImpactAsphaltCoverWaveConditionsCalculation[] 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); + + WaveImpactAsphaltCoverWaveConditionsCalculation 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("Golfklappen op asfaltbekleding", 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/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -0,0 +1,428 @@ +// 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.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.Views.RegistrationState; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Test.Views.RegistrationState +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismViewTest + { + 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 WaveImpactAsphaltCoverFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + WaveImpactAsphaltCoverFailureMechanismView 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 calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.3, 1.3)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + 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 WaveImpactAsphaltCoverFailureMechanism(); + 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 + }; + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) + }); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + // Call + WaveImpactAsphaltCoverFailureMechanismView 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]); + + 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.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); + 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 WaveImpactAsphaltCoverFailureMechanism(); + + WaveImpactAsphaltCoverFailureMechanismView 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 WaveImpactAsphaltCoverFailureMechanism(); + + WaveImpactAsphaltCoverFailureMechanismView 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 sectionsData = (MapDataCollection) mapDataCollection.ElementAt(updatedSectionsCollectionLayerIndex); + Assert.AreEqual("Vakindeling", sectionsData.Name); + + var assemblyResultsData = (MapLineData) mapDataCollection.ElementAt(updatedAssemblyResultsIndex); + Assert.AreEqual("Duidingsklasse per vak", assemblyResultsData.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 actualSectionsData = (MapDataCollection) mapDataCollection.ElementAt(updatedSectionsCollectionLayerIndex); + Assert.AreEqual("Vakindeling", actualSectionsData.Name); + + var actualAssemblyResultsData = (MapLineData) mapDataCollection.ElementAt(updatedAssemblyResultsIndex); + Assert.AreEqual("Duidingsklasse per vak", actualAssemblyResultsData.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 WaveImpactAsphaltCoverFailureMechanismView CreateView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new WaveImpactAsphaltCoverFailureMechanismView(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; + WaveImpactAsphaltCoverWaveConditionsCalculation[] 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); + + WaveImpactAsphaltCoverWaveConditionsCalculation 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("Golfklappen op asfaltbekleding", 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 Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailurePathViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/HydraulicLoadsState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -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.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.PresentationObjects; +using Riskeer.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState; + +namespace Riskeer.WaveImpactAsphaltCover.Plugin.Test.ViewInfos.HydraulicLoadsState +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismViewInfoTest + { + private MockRepository mocks; + private WaveImpactAsphaltCoverPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new WaveImpactAsphaltCoverPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveImpactAsphaltCoverFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(WaveImpactAsphaltCoverHydraulicLoadsContext), info.DataType); + Assert.AreEqual(typeof(WaveImpactAsphaltCoverHydraulicLoadsContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + var context = new WaveImpactAsphaltCoverHydraulicLoadsContext(failureMechanism, assessmentSection); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual(failureMechanism.Name, viewName); + } + + [Test] + public void CreateInstance_WithContext_ReturnWaveImpactAsphaltCoverFailureMechanismView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var context = new WaveImpactAsphaltCoverHydraulicLoadsContext(failureMechanism, assessmentSection); + + // Call + var view = (WaveImpactAsphaltCoverFailureMechanismView) info.CreateInstance(context); + + // Assert + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + } +} \ No newline at end of file Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/RegistrationState/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -0,0 +1,193 @@ +// 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.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.PresentationObjects; +using Riskeer.WaveImpactAsphaltCover.Forms.Views.RegistrationState; + +namespace Riskeer.WaveImpactAsphaltCover.Plugin.Test.ViewInfos.RegistrationState +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailureMechanismViewInfoTest + { + private MockRepository mocks; + private WaveImpactAsphaltCoverPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new WaveImpactAsphaltCoverPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveImpactAsphaltCoverFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(WaveImpactAsphaltCoverFailurePathContext), info.DataType); + Assert.AreEqual(typeof(WaveImpactAsphaltCoverFailurePathContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + var context = new WaveImpactAsphaltCoverFailurePathContext(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 WaveImpactAsphaltCoverFailureMechanism + { + InAssembly = inAssembly + }; + + var context = new WaveImpactAsphaltCoverFailurePathContext(failureMechanism, assessmentSection); + + // Call + bool result = info.AdditionalDataCheck(context); + + // Assert + Assert.AreEqual(inAssembly, result); + mocks.VerifyAll(); + } + + [Test] + public void CreateInstance_WithContext_ReturnWaveImpactAsphaltCoverFailurePathView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var context = new WaveImpactAsphaltCoverFailurePathContext(failureMechanism, assessmentSection); + + // Call + var view = (WaveImpactAsphaltCoverFailureMechanismView) 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 WaveImpactAsphaltCoverFailureMechanism(); + + var view = new WaveImpactAsphaltCoverFailureMechanismView(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 WaveImpactAsphaltCoverFailureMechanism(); + + var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + + mocks.VerifyAll(); + } + + [Test] + public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + var otherWaveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherWaveImpactAsphaltCoverFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } +} \ No newline at end of file Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ac7f4c3eecc95a1f469ceb08178b77965742b974 refers to a dead (removed) revision in file `Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailurePathViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/WaveImpactAsphaltCoverPluginTest.cs =================================================================== diff -u -r5319a71f64c1faa285332c83df061eb511d93c59 -rac7f4c3eecc95a1f469ceb08178b77965742b974 --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/WaveImpactAsphaltCoverPluginTest.cs (.../WaveImpactAsphaltCoverPluginTest.cs) (revision 5319a71f64c1faa285332c83df061eb511d93c59) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/WaveImpactAsphaltCoverPluginTest.cs (.../WaveImpactAsphaltCoverPluginTest.cs) (revision ac7f4c3eecc95a1f469ceb08178b77965742b974) @@ -38,9 +38,10 @@ using Riskeer.WaveImpactAsphaltCover.Data; using Riskeer.WaveImpactAsphaltCover.Forms.PresentationObjects; using Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses; -using Riskeer.WaveImpactAsphaltCover.Forms.Views; using HydraulicLoadsStateFailureMechanismProperties = Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses.HydraulicLoadsState.WaveImpactAsphaltCoverFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses.RegistrationState.WaveImpactAsphaltCoverFailureMechanismProperties; +using HydraulicLoadsStateFailureMechanismView = Riskeer.WaveImpactAsphaltCover.Forms.Views.HydraulicLoadsState.WaveImpactAsphaltCoverFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.WaveImpactAsphaltCover.Forms.Views.RegistrationState.WaveImpactAsphaltCoverFailureMechanismView; namespace Riskeer.WaveImpactAsphaltCover.Plugin.Test { @@ -105,10 +106,10 @@ mockRepository.ReplayAll(); using (var plugin = new WaveImpactAsphaltCoverPlugin - { - Gui = gui - }) { + Gui = gui + }) + { // Call ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); @@ -118,12 +119,12 @@ PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(WaveImpactAsphaltCoverHydraulicLoadsContext), - typeof(WaveImpactAsphaltCoverFailureMechanismView)); + typeof(HydraulicLoadsStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(WaveImpactAsphaltCoverFailurePathContext), - typeof(WaveImpactAsphaltCoverFailurePathView)); + typeof(RegistrationStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, @@ -180,10 +181,10 @@ mocks.ReplayAll(); using (var plugin = new WaveImpactAsphaltCoverPlugin - { - Gui = gui - }) { + Gui = gui + }) + { // Call ExportInfo[] exportInfos = plugin.GetExportInfos().ToArray();