Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.Designer.cs =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.Designer.cs (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.Designer.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -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.HeightStructures.Forms.Views.CalculationsState +{ + partial class HeightStructuresFailureMechanismView + { + /// + /// 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; + // + // HeightStructuresFailureMechanismView + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.riskeerMapControl); + this.Name = "HeightStructuresFailureMechanismView"; + this.ResumeLayout(false); + + } + + #endregion + + private Common.Forms.Views.RiskeerMapControl riskeerMapControl; + } +} Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.cs =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.cs (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -0,0 +1,282 @@ +// 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; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Forms.Factories; +using Riskeer.Common.Forms.MapLayers; +using Riskeer.HeightStructures.Data; +using HeightStructuresDataResources = Riskeer.HeightStructures.Data.Properties.Resources; + +namespace Riskeer.HeightStructures.Forms.Views.CalculationsState +{ + /// + /// Calculations state view showing map data for a height structures failure mechanism. + /// + public partial class HeightStructuresFailureMechanismView : UserControl, IMapView + { + private HydraulicBoundaryLocationsMapLayer hydraulicBoundaryLocationsMapLayer; + + private MapLineData referenceLineMapData; + private MapLineData foreshoreProfilesMapData; + private MapPointData structuresMapData; + private MapLineData calculationsMapData; + + private Observer assessmentSectionObserver; + private Observer referenceLineObserver; + private Observer foreshoreProfilesObserver; + private Observer structuresObserver; + + private RecursiveObserver calculationInputObserver; + private RecursiveObserver calculationGroupObserver; + private RecursiveObserver> calculationObserver; + private RecursiveObserver foreshoreProfileObserver; + private RecursiveObserver, HeightStructure> structureObserver; + + /// + /// 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 HeightStructuresFailureMechanismView(HeightStructuresFailureMechanism 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 HeightStructuresFailureMechanism 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(); + structuresObserver.Dispose(); + structureObserver.Dispose(); + + if (disposing) + { + components?.Dispose(); + } + + base.Dispose(disposing); + } + + protected virtual void CreateMapData() + { + hydraulicBoundaryLocationsMapLayer = new HydraulicBoundaryLocationsMapLayer(AssessmentSection); + + MapDataCollection = new MapDataCollection(HeightStructuresDataResources.HeightStructuresFailureMechanism_DisplayName); + referenceLineMapData = RiskeerMapDataFactory.CreateReferenceLineMapData(); + foreshoreProfilesMapData = RiskeerMapDataFactory.CreateForeshoreProfileMapData(); + calculationsMapData = RiskeerMapDataFactory.CreateCalculationsMapData(); + structuresMapData = RiskeerMapDataFactory.CreateStructuresMapData(); + + MapDataCollection.Add(referenceLineMapData); + MapDataCollection.Add(hydraulicBoundaryLocationsMapLayer.MapData); + MapDataCollection.Add(foreshoreProfilesMapData); + MapDataCollection.Add(structuresMapData); + MapDataCollection.Add(calculationsMapData); + } + + protected virtual void CreateObservers() + { + assessmentSectionObserver = new Observer(UpdateReferenceLineMapData) + { + Observable = AssessmentSection + }; + referenceLineObserver = new Observer(UpdateReferenceLineMapData) + { + Observable = AssessmentSection.ReferenceLine + }; + foreshoreProfilesObserver = new Observer(UpdateForeshoreProfilesMapData) + { + Observable = FailureMechanism.ForeshoreProfiles + }; + structuresObserver = new Observer(UpdateStructuresMapData) + { + Observable = FailureMechanism.HeightStructures + }; + + 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 + }; + structureObserver = new RecursiveObserver, HeightStructure>(UpdateStructuresMapData, coll => coll) + { + Observable = FailureMechanism.HeightStructures + }; + } + + protected virtual void SetAllMapDataFeatures() + { + SetReferenceLineMapData(); + SetForeshoreProfilesMapData(); + SetStructuresMapData(); + SetCalculationsMapData(); + } + + #region Calculations MapData + + private void UpdateCalculationsMapData() + { + SetCalculationsMapData(); + calculationsMapData.NotifyObservers(); + } + + private void SetCalculationsMapData() + { + IEnumerable> calculations = + FailureMechanism.CalculationsGroup.GetCalculations().Cast>(); + calculationsMapData.Features = RiskeerMapDataFeaturesFactory.CreateStructureCalculationsFeatures(calculations); + } + + #endregion + + #region AssessmentSection MapData + + private void UpdateReferenceLineMapData() + { + SetReferenceLineMapData(); + referenceLineMapData.NotifyObservers(); + } + + private void SetReferenceLineMapData() + { + ReferenceLine referenceLine = AssessmentSection.ReferenceLine; + referenceLineMapData.Features = RiskeerMapDataFeaturesFactory.CreateReferenceLineFeatures(referenceLine, AssessmentSection.Id, AssessmentSection.Name); + } + + #endregion + + #region Structures MapData + + private void UpdateStructuresMapData() + { + SetStructuresMapData(); + structuresMapData.NotifyObservers(); + } + + private void SetStructuresMapData() + { + IEnumerable structures = FailureMechanism.HeightStructures; + structuresMapData.Features = RiskeerMapDataFeaturesFactory.CreateStructuresFeatures(structures); + } + + #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/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.resx =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.resx (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/CalculationsState/HeightStructuresFailureMechanismView.resx (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -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 Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.resx'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/HeightStructuresFailurePathView.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/RegistrationState/HeightStructuresFailureMechanismView.cs =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/RegistrationState/HeightStructuresFailureMechanismView.cs (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/Views/RegistrationState/HeightStructuresFailureMechanismView.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -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.Data.Structures; +using Riskeer.Common.Forms.Factories; +using Riskeer.Common.Forms.MapLayers; +using Riskeer.HeightStructures.Data; +using HeightStructuresDataResources = Riskeer.HeightStructures.Data.Properties.Resources; + +namespace Riskeer.HeightStructures.Forms.Views.RegistrationState +{ + /// + /// Registration state view showing map data for a height structures failure mechanism. + /// + public class HeightStructuresFailureMechanismView : CalculationsState.HeightStructuresFailureMechanismView + { + private MapLineData sectionsMapData; + private MapPointData sectionsStartPointMapData; + private MapPointData sectionsEndPointMapData; + + private CalculatableFailureMechanismSectionResultsMapLayer assemblyResultsMapLayer; + + 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 HeightStructuresFailureMechanismView(HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(failureMechanism, assessmentSection) {} + + protected override void Dispose(bool disposing) + { + failureMechanismObserver.Dispose(); + assemblyResultsMapLayer.Dispose(); + + base.Dispose(disposing); + } + + protected override void CreateMapData() + { + base.CreateMapData(); + + MapDataCollection sectionsMapDataCollection = RiskeerMapDataFactory.CreateSectionsMapDataCollection(); + sectionsMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsMapData(); + sectionsStartPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); + sectionsEndPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); + + assemblyResultsMapLayer = new CalculatableFailureMechanismSectionResultsMapLayer( + FailureMechanism, sr => StructuresFailureMechanismAssemblyFactory.AssembleSection(sr, FailureMechanism, AssessmentSection)); + + sectionsMapDataCollection.Add(sectionsMapData); + sectionsMapDataCollection.Add(sectionsStartPointMapData); + sectionsMapDataCollection.Add(sectionsEndPointMapData); + MapDataCollection.Insert(1, sectionsMapDataCollection); + + MapDataCollection.Insert(2, assemblyResultsMapLayer.MapData); + } + + protected override void CreateObservers() + { + base.CreateObservers(); + + failureMechanismObserver = new Observer(UpdateFailureMechanismMapData) + { + Observable = FailureMechanism + }; + } + + protected override void SetAllMapDataFeatures() + { + base.SetAllMapDataFeatures(); + + SetSectionsMapData(); + } + + #region FailureMechanism MapData + + private void UpdateFailureMechanismMapData() + { + 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/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r14174f04f6c78b47f5663373e3b6f9e68847646b -r49dcec749045c1b5350496fd6c26cbc1256938dc --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 14174f04f6c78b47f5663373e3b6f9e68847646b) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -63,6 +63,8 @@ using Riskeer.HeightStructures.Service; using CalculationsStateFailureMechanismProperties = Riskeer.HeightStructures.Forms.PropertyClasses.CalculationsState.HeightStructuresFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.HeightStructures.Forms.PropertyClasses.RegistrationState.HeightStructuresFailureMechanismProperties; +using CalculationsStateFailureMechanismView = Riskeer.HeightStructures.Forms.Views.CalculationsState.HeightStructuresFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.HeightStructures.Forms.Views.RegistrationState.HeightStructuresFailureMechanismView; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources; using RiskeerCommonIOResources = Riskeer.Common.IO.Properties.Resources; @@ -163,17 +165,17 @@ public override IEnumerable GetViewInfos() { - yield return new RiskeerViewInfo(() => Gui) + yield return new RiskeerViewInfo(() => Gui) { GetViewName = (view, context) => context.WrappedData.Name, - CreateInstance = context => new HeightStructuresFailureMechanismView(context.WrappedData, context.Parent) + CreateInstance = context => new CalculationsStateFailureMechanismView(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 HeightStructuresFailurePathView(context.WrappedData, context.Parent), + CreateInstance = context => new RegistrationStateFailureMechanismView(context.WrappedData, context.Parent), CloseForData = CloseFailurePathViewForData }; @@ -292,7 +294,7 @@ #region ViewInfos - private static bool CloseFailurePathViewForData(HeightStructuresFailurePathView view, object dataToCloseFor) + private static bool CloseFailurePathViewForData(RegistrationStateFailureMechanismView view, object dataToCloseFor) { var failureMechanism = dataToCloseFor as HeightStructuresFailureMechanism; Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/CalculationsState/HeightStructuresFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/CalculationsState/HeightStructuresFailureMechanismViewTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/CalculationsState/HeightStructuresFailureMechanismViewTest.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -0,0 +1,734 @@ +// 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.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Data.TestUtil; +using Riskeer.HeightStructures.Forms.Views.CalculationsState; + +namespace Riskeer.HeightStructures.Forms.Test.Views.CalculationsState +{ + [TestFixture] + public class HeightStructuresFailureMechanismViewTest + { + private const int referenceLineIndex = 0; + private const int hydraulicBoundaryLocationsIndex = 1; + private const int foreshoreProfilesIndex = 2; + private const int structuresIndex = 3; + private const int calculationsIndex = 4; + + private const int foreshoreProfilesObserverIndex = 1; + private const int structuresObserverIndex = 2; + private const int calculationObserverIndex = 3; + + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + void Call() => new HeightStructuresFailureMechanismView(null, assessmentSection); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new HeightStructuresFailureMechanismView(new HeightStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + HeightStructuresFailureMechanismView 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 + HeightStructuresFailureMechanismView view = CreateView(new HeightStructuresFailureMechanism(), assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var calculationA = new StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 1.3, 2.3), + Structure = new TestHeightStructure(new Point2D(1.2, 2.3)) + } + }; + + var calculationB = new StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 7.7, 12.6), + Structure = new TestHeightStructure(new Point2D(2.7, 2.0)) + } + }; + + var geometryPoints = new[] + { + new Point2D(0.0, 0.0), + new Point2D(2.0, 0.0), + new Point2D(4.0, 4.0), + new Point2D(6.0, 4.0) + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + 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 + HeightStructuresFailureMechanismView 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(5, 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 + }; + + HeightStructuresFailureMechanismView view = CreateView(new HeightStructuresFailureMechanism(), 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 + }; + + HeightStructuresFailureMechanismView view = CreateView(new HeightStructuresFailureMechanism(), 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 HeightStructuresFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + foreshoreProfile + }, "path"); + + HeightStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfilesObserverIndex].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 HeightStructuresFailureMechanism(); + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile("originalProfile ID", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }) + }, "path"); + + HeightStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfilesObserverIndex].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 GivenViewWithStructureData_WhenStructureUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var structure = new TestHeightStructure(new Point2D(0, 0), "Id"); + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.HeightStructures.AddRange(new[] + { + structure + }, "path"); + + HeightStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[structuresObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData structuresData = map.Data.Collection.ElementAt(structuresIndex); + + // Precondition + MapDataTestHelper.AssertStructuresMapData(failureMechanism.HeightStructures, + structuresData); + + // When + structure.CopyProperties(new TestHeightStructure(new Point2D(1, 1), "Id")); + structure.NotifyObservers(); + + // Then + MapDataTestHelper.AssertStructuresMapData(failureMechanism.HeightStructures, + structuresData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithStructuresData_WhenStructuresUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.HeightStructures.AddRange(new[] + { + new TestHeightStructure(new Point2D(0, 0), "Id1") + }, "path"); + + HeightStructuresFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[structuresObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData structuresData = map.Data.Collection.ElementAt(structuresIndex); + + // Precondition + MapDataTestHelper.AssertStructuresMapData(failureMechanism.HeightStructures, + structuresData); + + // When + failureMechanism.HeightStructures.AddRange(new[] + { + new TestHeightStructure(new Point2D(1, 1), "Id2") + }, "some path"); + failureMechanism.HeightStructures.NotifyObservers(); + + // Then + MapDataTestHelper.AssertStructuresMapData(failureMechanism.HeightStructures, + structuresData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var calculationA = new StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 1.3, 2.3), + Structure = new TestHeightStructure(new Point2D(1.2, 2.3)) + } + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + HeightStructuresFailureMechanismView 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 StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 7.7, 12.6), + Structure = new TestHeightStructure(new Point2D(2.7, 2.0)) + } + }; + + 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 StructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 1.3, 2.3), + Structure = new TestHeightStructure(new Point2D(1.2, 2.3)) + } + }; + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.CalculationsGroup.Children.Add(calculationA); + + HeightStructuresFailureMechanismView 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.Structure = new TestHeightStructure(new Point2D(2.7, 2.0)); + calculationA.InputParameters.NotifyObservers(); + + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast>(), calculationMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void NotifyObservers_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 4; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; + const int updatedStructuresLayerIndex = structuresIndex - 1; + const int updatedCalculationsIndex = calculationsIndex - 1; + + var assessmentSection = new AssessmentSectionStub(); + + HeightStructuresFailureMechanismView view = CreateView(new HeightStructuresFailureMechanism(), 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); + + List mapDataList = mapData.Collection.ToList(); + + // Precondition + var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + + var structuresData = (MapPointData) mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", structuresData.Name); + + var calculationsData = (MapLineData) mapDataList[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[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualStructuresData = (MapPointData) mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", actualStructuresData.Name); + + var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } + + private HeightStructuresFailureMechanismView CreateView(HeightStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new HeightStructuresFailureMechanismView(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; + StructuresCalculation[] 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); + + StructuresCalculation calculation = calculationsArray[index]; + CollectionAssert.AreEquivalent(new[] + { + calculation.InputParameters.Structure.Location, + calculation.InputParameters.HydraulicBoundaryLocation.Location + }, geometries[0].PointCollections.First()); + } + + Assert.AreEqual("Berekeningen", mapData.Name); + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Hoogte kunstwerk", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(5, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; + var structuresMapData = (MapPointData) mapDataList[structuresIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var calculationsMapData = (MapLineData) mapDataList[calculationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); + CollectionAssert.IsEmpty(structuresMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + CollectionAssert.IsEmpty(calculationsMapData.Features); + + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesMapData.Name); + Assert.AreEqual("Kunstwerken", structuresMapData.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 structuresMapDataObserver = mocks.StrictMock(); + mapDataArray[structuresIndex].Attach(structuresMapDataObserver); + + var calculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); + + return new[] + { + referenceLineMapDataObserver, + foreshoreProfilesMapDataObserver, + structuresMapDataObserver, + calculationsMapDataObserver + }; + } + } +} \ No newline at end of file Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/HeightStructuresFailurePathViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/RegistrationState/HeightStructuresFailureMechanismViewTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/RegistrationState/HeightStructuresFailureMechanismViewTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/Views/RegistrationState/HeightStructuresFailureMechanismViewTest.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -0,0 +1,441 @@ +// 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.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Data.TestUtil; +using Riskeer.HeightStructures.Forms.Views.RegistrationState; +using CalculationsStateFailureMechanismView = Riskeer.HeightStructures.Forms.Views.CalculationsState.HeightStructuresFailureMechanismView; + +namespace Riskeer.HeightStructures.Forms.Test.Views.RegistrationState +{ + [TestFixture] + public class HeightStructuresFailureMechanismViewTest + { + 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 structuresIndex = 5; + private const int calculationsIndex = 6; + + 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 HeightStructuresFailureMechanism(); + var assessmentSection = new AssessmentSectionStub(); + + // Call + HeightStructuresFailureMechanismView 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 StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 1.3, 2.3), + Structure = new TestHeightStructure(new Point2D(1.2, 2.3)) + } + }; + + var calculationB = new StructuresCalculationScenario + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 7.7, 12.6), + Structure = new TestHeightStructure(new Point2D(2.7, 2.0)) + } + }; + + var geometryPoints = new[] + { + new Point2D(0.0, 0.0), + new Point2D(2.0, 0.0), + new Point2D(4.0, 4.0), + new Point2D(6.0, 4.0) + }; + + var failureMechanism = new HeightStructuresFailureMechanism(); + 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 + HeightStructuresFailureMechanismView 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(7, 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 HeightStructuresFailureMechanism(); + + HeightStructuresFailureMechanismView 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 NotifyObservers_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 6; + const int updatedSectionCollectionIndex = sectionsCollectionIndex - 1; + const int updatedAssemblyResultsIndex = assemblyResultsIndex - 1; + const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; + const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; + const int updatedStructuresLayerIndex = structuresIndex - 1; + const int updatedCalculationsIndex = calculationsIndex - 1; + + var assessmentSection = new AssessmentSectionStub(); + + HeightStructuresFailureMechanismView view = CreateView(new HeightStructuresFailureMechanism(), 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); + + List mapDataList = mapData.Collection.ToList(); + + // Precondition + var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var sectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; + Assert.AreEqual("Vakindeling", sectionsData.Name); + + var assemblyResultsData = (MapLineData) mapDataList[updatedAssemblyResultsIndex]; + Assert.AreEqual("Duidingsklasse per vak", assemblyResultsData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + + var structuresData = (MapPointData) mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", structuresData.Name); + + var calculationsData = (MapLineData) mapDataList[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[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + + var actualSectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; + Assert.AreEqual("Vakindeling", actualSectionsData.Name); + + var actualAssemblyResultsData = (MapLineData) mapDataList[updatedAssemblyResultsIndex]; + Assert.AreEqual("Duidingsklasse per vak", actualAssemblyResultsData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualStructuresData = (MapPointData) mapDataList[updatedStructuresLayerIndex]; + Assert.AreEqual("Kunstwerken", actualStructuresData.Name); + + var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } + + private HeightStructuresFailureMechanismView CreateView(HeightStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new HeightStructuresFailureMechanismView(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; + StructuresCalculation[] 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); + + StructuresCalculation calculation = calculationsArray[index]; + CollectionAssert.AreEquivalent(new[] + { + calculation.InputParameters.Structure.Location, + calculation.InputParameters.HydraulicBoundaryLocation.Location + }, geometries[0].PointCollections.First()); + } + + Assert.AreEqual("Berekeningen", mapData.Name); + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Hoogte kunstwerk", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(7, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var assemblyResultsMapData = (MapLineData) mapDataList[assemblyResultsIndex]; + var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; + var structuresMapData = (MapPointData) mapDataList[structuresIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var calculationsMapData = (MapLineData) mapDataList[calculationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(assemblyResultsMapData.Features); + CollectionAssert.IsEmpty(foreshoreProfilesMapData.Features); + CollectionAssert.IsEmpty(structuresMapData.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("Kunstwerken", structuresMapData.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/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r14174f04f6c78b47f5663373e3b6f9e68847646b -r49dcec749045c1b5350496fd6c26cbc1256938dc --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 14174f04f6c78b47f5663373e3b6f9e68847646b) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -40,6 +40,8 @@ using Riskeer.HeightStructures.Forms.Views; using CalculationsStateFailureMechanismProperties = Riskeer.HeightStructures.Forms.PropertyClasses.CalculationsState.HeightStructuresFailureMechanismProperties; using RegistrationStateFailureMechanismProperties = Riskeer.HeightStructures.Forms.PropertyClasses.RegistrationState.HeightStructuresFailureMechanismProperties; +using CalculationsStateFailureMechanismView = Riskeer.HeightStructures.Forms.Views.CalculationsState.HeightStructuresFailureMechanismView; +using RegistrationStateFailureMechanismView = Riskeer.HeightStructures.Forms.Views.RegistrationState.HeightStructuresFailureMechanismView; namespace Riskeer.HeightStructures.Plugin.Test { @@ -146,12 +148,12 @@ PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(HeightStructuresCalculationsContext), - typeof(HeightStructuresFailureMechanismView)); + typeof(CalculationsStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(HeightStructuresFailurePathContext), - typeof(HeightStructuresFailurePathView)); + typeof(RegistrationStateFailureMechanismView)); PluginTestHelper.AssertViewInfoDefined( viewInfos, Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/CalculationsState/HeightStructuresFailureMechanismViewInfoTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/CalculationsState/HeightStructuresFailureMechanismViewInfoTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/CalculationsState/HeightStructuresFailureMechanismViewInfoTest.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -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.HeightStructures.Data; +using Riskeer.HeightStructures.Forms.PresentationObjects; +using Riskeer.HeightStructures.Forms.Views.CalculationsState; + +namespace Riskeer.HeightStructures.Plugin.Test.ViewInfos.CalculationsState +{ + [TestFixture] + public class HeightStructuresFailureMechanismViewInfoTest + { + private MockRepository mocks; + private HeightStructuresPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(HeightStructuresFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(HeightStructuresCalculationsContext), info.DataType); + Assert.AreEqual(typeof(HeightStructuresCalculationsContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var context = new HeightStructuresCalculationsContext(failureMechanism, assessmentSection); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual(failureMechanism.Name, viewName); + } + + [Test] + public void CreateInstance_WithContext_ReturnHeightStructuresFailureMechanismView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var context = new HeightStructuresCalculationsContext(failureMechanism, assessmentSection); + + // Call + var view = (HeightStructuresFailureMechanismView) info.CreateInstance(context); + + // Assert + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + } +} \ No newline at end of file Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresFailureMechanismViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 49dcec749045c1b5350496fd6c26cbc1256938dc refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/HeightStructuresFailurePathViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/RegistrationState/HeightStructuresFailurePathViewInfoTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/RegistrationState/HeightStructuresFailurePathViewInfoTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/ViewInfos/RegistrationState/HeightStructuresFailurePathViewInfoTest.cs (revision 49dcec749045c1b5350496fd6c26cbc1256938dc) @@ -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.HeightStructures.Data; +using Riskeer.HeightStructures.Forms.PresentationObjects; +using Riskeer.HeightStructures.Forms.Views.RegistrationState; + +namespace Riskeer.HeightStructures.Plugin.Test.ViewInfos.RegistrationState +{ + [TestFixture] + public class HeightStructuresFailurePathViewInfoTest + { + private MockRepository mocks; + private HeightStructuresPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + mocks = new MockRepository(); + plugin = new HeightStructuresPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(HeightStructuresFailureMechanismView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(HeightStructuresFailurePathContext), info.DataType); + Assert.AreEqual(typeof(HeightStructuresFailurePathContext), info.ViewDataType); + } + + [Test] + public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() + { + // Setup + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var context = new HeightStructuresFailurePathContext(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 HeightStructuresFailureMechanism + { + InAssembly = inAssembly + }; + + var context = new HeightStructuresFailurePathContext(failureMechanism, assessmentSection); + + // Call + bool result = info.AdditionalDataCheck(context); + + // Assert + Assert.AreEqual(inAssembly, result); + mocks.VerifyAll(); + } + + [Test] + public void CreateInstance_WithContext_ReturnHeightStructuresFailureMechanismView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var context = new HeightStructuresFailurePathContext(failureMechanism, assessmentSection); + + // Call + var view = (HeightStructuresFailureMechanismView) 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 HeightStructuresFailureMechanism(); + + var view = new HeightStructuresFailureMechanismView(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 HeightStructuresFailureMechanism(); + + var view = new HeightStructuresFailureMechanismView(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 HeightStructuresFailureMechanism(); + var otherHeightStructuresFailureMechanism = new HeightStructuresFailureMechanism(); + + var view = new HeightStructuresFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, otherHeightStructuresFailureMechanism); + + // Assert + Assert.IsFalse(closeForData); + } + + [Test] + public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new HeightStructuresFailureMechanism(); + + var view = new HeightStructuresFailureMechanismView(failureMechanism, assessmentSection); + + // Call + bool closeForData = info.CloseForData(view, failureMechanism); + + // Assert + Assert.IsTrue(closeForData); + } + } +} \ No newline at end of file