Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.cs =================================================================== diff -u -r4f4daebe59ab925c98cef039101ec70544530bbe -r7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.cs (.../WaveImpactAsphaltCoverFailureMechanismView.cs) (revision 4f4daebe59ab925c98cef039101ec70544530bbe) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailureMechanismView.cs (.../WaveImpactAsphaltCoverFailureMechanismView.cs) (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -29,7 +29,6 @@ using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.DikeProfiles; -using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.Hydraulics; using Riskeer.Common.Forms.Factories; using Riskeer.Common.Forms.Helpers; @@ -45,22 +44,11 @@ /// public partial class WaveImpactAsphaltCoverFailureMechanismView : UserControl, IMapView { - private MapDataCollection mapDataCollection; private MapLineData referenceLineMapData; private MapPointData hydraulicBoundaryLocationsMapData; private MapLineData foreshoreProfilesMapData; private MapLineData calculationsMapData; - private MapLineData sectionsMapData; - private MapPointData sectionsStartPointMapData; - private MapPointData sectionsEndPointMapData; - - private MapLineData simpleAssemblyMapData; - private MapLineData detailedAssemblyMapData; - private MapLineData tailorMadeAssemblyMapData; - private MapLineData combinedAssemblyMapData; - - private Observer failureMechanismObserver; private Observer assessmentSectionObserver; private Observer referenceLineObserver; private Observer hydraulicBoundaryLocationsObserver; @@ -78,7 +66,6 @@ private RecursiveObserver calculationGroupObserver; private RecursiveObserver calculationObserver; private RecursiveObserver foreshoreProfileObserver; - private RecursiveObserver, WaveImpactAsphaltCoverFailureMechanismSectionResult> sectionResultObserver; /// /// Creates a new instance of . @@ -87,7 +74,7 @@ /// The assessment section to show the data for. /// Thrown when any parameter is null. public WaveImpactAsphaltCoverFailureMechanismView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + IAssessmentSection assessmentSection) { if (failureMechanism == null) { @@ -103,12 +90,6 @@ FailureMechanism = failureMechanism; AssessmentSection = assessmentSection; - - CreateObservers(); - - CreateMapData(); - SetMapDataFeatures(); - riskeerMapControl.SetAllData(mapDataCollection, AssessmentSection.BackgroundData); } /// @@ -131,9 +112,26 @@ } } + /// + /// 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) { - failureMechanismObserver.Dispose(); assessmentSectionObserver.Dispose(); referenceLineObserver.Dispose(); waterLevelCalculationsForFactorizedSignalingNormObserver.Dispose(); @@ -150,7 +148,6 @@ calculationInputObserver.Dispose(); calculationGroupObserver.Dispose(); calculationObserver.Dispose(); - sectionResultObserver.Dispose(); if (disposing) { @@ -160,49 +157,29 @@ base.Dispose(disposing); } - private void CreateMapData() + /// + /// Creates the map data. + /// + protected virtual void CreateMapData() { - mapDataCollection = new MapDataCollection(WaveImpactAsphaltCoverDataResources.WaveImpactAsphaltCoverFailureMechanism_DisplayName); + MapDataCollection = new MapDataCollection(WaveImpactAsphaltCoverDataResources.WaveImpactAsphaltCoverFailureMechanism_DisplayName); referenceLineMapData = RiskeerMapDataFactory.CreateReferenceLineMapData(); hydraulicBoundaryLocationsMapData = RiskeerMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); foreshoreProfilesMapData = RiskeerMapDataFactory.CreateForeshoreProfileMapData(); calculationsMapData = RiskeerMapDataFactory.CreateCalculationsMapData(); - MapDataCollection sectionsMapDataCollection = RiskeerMapDataFactory.CreateSectionsMapDataCollection(); - sectionsMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsMapData(); - sectionsStartPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); - sectionsEndPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); + MapDataCollection.Add(referenceLineMapData); - MapDataCollection assemblyMapDataCollection = AssemblyMapDataFactory.CreateAssemblyMapDataCollection(); - tailorMadeAssemblyMapData = AssemblyMapDataFactory.CreateTailorMadeAssemblyMapData(); - detailedAssemblyMapData = AssemblyMapDataFactory.CreateDetailedAssemblyMapData(); - simpleAssemblyMapData = AssemblyMapDataFactory.CreateSimpleAssemblyMapData(); - combinedAssemblyMapData = AssemblyMapDataFactory.CreateCombinedAssemblyMapData(); - - mapDataCollection.Add(referenceLineMapData); - - sectionsMapDataCollection.Add(sectionsMapData); - sectionsMapDataCollection.Add(sectionsStartPointMapData); - sectionsMapDataCollection.Add(sectionsEndPointMapData); - mapDataCollection.Add(sectionsMapDataCollection); - - assemblyMapDataCollection.Add(tailorMadeAssemblyMapData); - assemblyMapDataCollection.Add(detailedAssemblyMapData); - assemblyMapDataCollection.Add(simpleAssemblyMapData); - assemblyMapDataCollection.Add(combinedAssemblyMapData); - mapDataCollection.Add(assemblyMapDataCollection); - - mapDataCollection.Add(hydraulicBoundaryLocationsMapData); - mapDataCollection.Add(foreshoreProfilesMapData); - mapDataCollection.Add(calculationsMapData); + MapDataCollection.Add(hydraulicBoundaryLocationsMapData); + MapDataCollection.Add(foreshoreProfilesMapData); + MapDataCollection.Add(calculationsMapData); } - private void CreateObservers() + /// + /// Creates the observers. + /// + protected virtual void CreateObservers() { - failureMechanismObserver = new Observer(UpdateFailureMechanismData) - { - Observable = FailureMechanism - }; assessmentSectionObserver = new Observer(UpdateReferenceLineData) { Observable = AssessmentSection @@ -255,53 +232,28 @@ { Observable = FailureMechanism.ForeshoreProfiles }; - - sectionResultObserver = new RecursiveObserver, - WaveImpactAsphaltCoverFailureMechanismSectionResult>(UpdateAssemblyMapData, sr => sr) - { - Observable = FailureMechanism.SectionResults - }; } - private void SetMapDataFeatures() + /// + /// Sets all map data features. + /// + protected virtual void SetAllMapDataFeatures() { SetReferenceLineMapData(); - SetSectionsMapData(); SetHydraulicBoundaryLocationsMapData(); SetForeshoreProfilesMapData(); SetCalculationsMapData(); - SetAssemblyMapData(); } - #region Assembly MapData - - private void UpdateAssemblyMapData() - { - SetAssemblyMapData(); - simpleAssemblyMapData.NotifyObservers(); - detailedAssemblyMapData.NotifyObservers(); - tailorMadeAssemblyMapData.NotifyObservers(); - combinedAssemblyMapData.NotifyObservers(); - } - - private void SetAssemblyMapData() - { - simpleAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(FailureMechanism); - detailedAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(FailureMechanism); - tailorMadeAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(FailureMechanism); - combinedAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(FailureMechanism); - } - - #endregion - #region Calculations MapData - private void UpdateCalculationsMapData() + /// + /// Updates the calculations map data. + /// + protected virtual void UpdateCalculationsMapData() { SetCalculationsMapData(); calculationsMapData.NotifyObservers(); - - UpdateAssemblyMapData(); } private void SetCalculationsMapData() @@ -344,29 +296,6 @@ #endregion - #region FailureMechanism MapData - - private void UpdateFailureMechanismData() - { - SetSectionsMapData(); - sectionsMapData.NotifyObservers(); - sectionsStartPointMapData.NotifyObservers(); - sectionsEndPointMapData.NotifyObservers(); - - UpdateAssemblyMapData(); - } - - private void SetSectionsMapData() - { - IEnumerable failureMechanismSections = FailureMechanism.Sections; - - sectionsMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(failureMechanismSections); - sectionsStartPointMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionStartPointFeatures(failureMechanismSections); - sectionsEndPointMapData.Features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionEndPointFeatures(failureMechanismSections); - } - - #endregion - #region Foreshore Profiles MapData private void UpdateForeshoreProfilesMapData() Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailurePathView.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailurePathView.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Forms/Views/WaveImpactAsphaltCoverFailurePathView.cs (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -0,0 +1,177 @@ +// 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.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Forms.Factories; +using WaveImpactAsphaltCoverDataResources = Riskeer.WaveImpactAsphaltCover.Data.Properties.Resources; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Views +{ + /// + /// This class is a view showing map data for a wave impact asphalt cover failure path. + /// + public class WaveImpactAsphaltCoverFailurePathView : WaveImpactAsphaltCoverFailureMechanismView + { + private MapLineData sectionsMapData; + private MapPointData sectionsStartPointMapData; + private MapPointData sectionsEndPointMapData; + + private MapLineData simpleAssemblyMapData; + private MapLineData detailedAssemblyMapData; + private MapLineData tailorMadeAssemblyMapData; + private MapLineData combinedAssemblyMapData; + + private Observer failureMechanismObserver; + + private RecursiveObserver, WaveImpactAsphaltCoverFailureMechanismSectionResult> sectionResultObserver; + + /// + /// 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 WaveImpactAsphaltCoverFailurePathView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) : base(failureMechanism, assessmentSection) {} + + protected override void Dispose(bool disposing) + { + failureMechanismObserver.Dispose(); + sectionResultObserver.Dispose(); + + base.Dispose(disposing); + } + + protected override void CreateMapData() + { + base.CreateMapData(); + + MapDataCollection sectionsMapDataCollection = RiskeerMapDataFactory.CreateSectionsMapDataCollection(); + sectionsMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsMapData(); + sectionsStartPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); + sectionsEndPointMapData = RiskeerMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); + + MapDataCollection assemblyMapDataCollection = AssemblyMapDataFactory.CreateAssemblyMapDataCollection(); + tailorMadeAssemblyMapData = AssemblyMapDataFactory.CreateTailorMadeAssemblyMapData(); + detailedAssemblyMapData = AssemblyMapDataFactory.CreateDetailedAssemblyMapData(); + simpleAssemblyMapData = AssemblyMapDataFactory.CreateSimpleAssemblyMapData(); + combinedAssemblyMapData = AssemblyMapDataFactory.CreateCombinedAssemblyMapData(); + + sectionsMapDataCollection.Add(sectionsMapData); + sectionsMapDataCollection.Add(sectionsStartPointMapData); + sectionsMapDataCollection.Add(sectionsEndPointMapData); + MapDataCollection.Insert(1, sectionsMapDataCollection); + + assemblyMapDataCollection.Add(tailorMadeAssemblyMapData); + assemblyMapDataCollection.Add(detailedAssemblyMapData); + assemblyMapDataCollection.Add(simpleAssemblyMapData); + assemblyMapDataCollection.Add(combinedAssemblyMapData); + MapDataCollection.Insert(2, assemblyMapDataCollection); + } + + protected override void CreateObservers() + { + base.CreateObservers(); + + failureMechanismObserver = new Observer(UpdateFailureMechanismData) + { + Observable = FailureMechanism + }; + + sectionResultObserver = new RecursiveObserver, + WaveImpactAsphaltCoverFailureMechanismSectionResult>(UpdateAssemblyMapData, sr => sr) + { + Observable = FailureMechanism.SectionResults + }; + } + + protected override void SetAllMapDataFeatures() + { + base.SetAllMapDataFeatures(); + + SetSectionsMapData(); + + SetAssemblyMapData(); + } + + #region Calculations MapData + + protected override void UpdateCalculationsMapData() + { + base.UpdateCalculationsMapData(); + + UpdateAssemblyMapData(); + } + + #endregion + + #region Assembly MapData + + private void UpdateAssemblyMapData() + { + SetAssemblyMapData(); + simpleAssemblyMapData.NotifyObservers(); + detailedAssemblyMapData.NotifyObservers(); + tailorMadeAssemblyMapData.NotifyObservers(); + combinedAssemblyMapData.NotifyObservers(); + } + + private void SetAssemblyMapData() + { + simpleAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(FailureMechanism); + detailedAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(FailureMechanism); + tailorMadeAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(FailureMechanism); + combinedAssemblyMapData.Features = WaveImpactAsphaltCoverAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(FailureMechanism); + } + + #endregion + + #region FailureMechanism MapData + + private void UpdateFailureMechanismData() + { + SetSectionsMapData(); + sectionsMapData.NotifyObservers(); + sectionsStartPointMapData.NotifyObservers(); + sectionsEndPointMapData.NotifyObservers(); + + UpdateAssemblyMapData(); + } + + 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/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs =================================================================== diff -u -r54a48626d01c301e2b30a2ce45125375d64ca5a4 -r7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 54a48626d01c301e2b30a2ce45125375d64ca5a4) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -97,6 +97,13 @@ AdditionalDataCheck = context => context.WrappedData.IsRelevant, CreateInstance = context => new WaveImpactAsphaltCoverFailureMechanismView(context.WrappedData, context.Parent) }; + + yield return new ViewInfo + { + GetViewName = (view, context) => context.WrappedData.Name, + Image = RiskeerCommonFormsResources.FailureMechanismIcon, + CreateInstance = context => new WaveImpactAsphaltCoverFailurePathView(context.WrappedData, context.Parent) + }; yield return new ViewInfo, IObservableEnumerable, Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs =================================================================== diff -u -r4f4daebe59ab925c98cef039101ec70544530bbe -r7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewTest.cs) (revision 4f4daebe59ab925c98cef039101ec70544530bbe) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailureMechanismViewTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewTest.cs) (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -22,6 +22,7 @@ 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; @@ -51,33 +52,30 @@ 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 hydraulicBoundaryLocationsIndex = 1; + private const int foreshoreProfilesIndex = 2; + private const int calculationsIndex = 3; - private const int sectionsIndex = 0; - private const int sectionsStartPointIndex = 1; - private const int sectionsEndPointIndex = 2; - - private const int tailorMadeAssemblyIndex = 0; - private const int detailedAssemblyIndex = 1; - private const int simpleAssemblyIndex = 2; - private const int combinedAssemblyIndex = 3; - private const int hydraulicBoundaryLocationsObserverIndex = 1; private const int foreshoreProfileObserverIndex = 2; private const int calculationObserverIndex = 3; - private const int sectionsObserverIndex = 4; - private const int sectionsStartPointObserverIndex = 5; - private const int sectionsEndPointObserverIndex = 6; - private const int simpleAssemblyObserverIndex = 7; - private const int detailedAssemblyObserverIndex = 8; - private const int tailorMadeAssemblyObserverIndex = 9; - private const int combinedAssemblyObserverIndex = 10; + 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 @@ -86,65 +84,67 @@ mocks.ReplayAll(); // Call - TestDelegate call = () => new WaveImpactAsphaltCoverFailureMechanismView(null, assessmentSection); + void Call() => new WaveImpactAsphaltCoverFailureMechanismView(null, assessmentSection); // Assert - var exception = Assert.Throws(call); + var exception = Assert.Throws(Call); Assert.AreEqual("failureMechanism", exception.ParamName); mocks.VerifyAll(); } [Test] + [Apartment(ApartmentState.STA)] public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Call - TestDelegate call = () => new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), null); + void Call() => new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), null); // Assert - var exception = Assert.Throws(call); + 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 - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsNull(view.Data); - Assert.AreSame(failureMechanism, view.FailureMechanism); - Assert.AreSame(assessmentSection, view.AssessmentSection); + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, 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); - } + // 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 - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection)) - { - // Assert - MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); - } + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); } [Test] + [Apartment(ApartmentState.STA)] public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup @@ -234,38 +234,26 @@ calculator.CombinedAssemblyCategoryOutput = expectedCombinedAssemblyCategory; // Call - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, assessmentSection); - // Assert - MapDataCollection mapData = map.Data; - Assert.IsInstanceOf(mapData); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - List mapDataList = mapData.Collection.ToList(); - Assert.AreEqual(6, mapDataList.Count); - MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + // Assert + MapDataCollection mapData = map.Data; + Assert.IsInstanceOf(mapData); - 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)); + 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]); - - MapDataTestHelper.AssertAssemblyMapDataCollection(expectedSimpleAssembly.Group, - expectedDetailedAssemblyCategory, - expectedTailorMadeAssemblyCategory, - expectedCombinedAssemblyCategory, - (MapDataCollection) mapDataList[assemblyResultsIndex], - failureMechanism); - } + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]); + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), mapDataList[calculationsIndex]); } } [Test] + [Apartment(ApartmentState.STA)] public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationsUpdatedAndNotified_ThenMapDataUpdated() { // Given @@ -275,34 +263,34 @@ new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) }); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); - // When - assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] - { - new HydraulicBoundaryLocation(2, "test2", 3.0, 4.0) - }); - assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); - // Then - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); - mocks.VerifyAll(); - } + // When + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(2, "test2", 3.0, 4.0) + }); + assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.VerifyAll(); } [Test] + [Apartment(ApartmentState.STA)] [TestCaseSource(typeof(MapViewTestHelper), nameof(MapViewTestHelper.GetCalculationFuncs))] public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationCalculationUpdatedAndNotified_ThenMapDataUpdated( Func getCalculationFunc) @@ -315,32 +303,32 @@ hydraulicBoundaryLocation }); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); - // When - HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection); - calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble()); - calculation.NotifyObservers(); + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); - // Then - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); - mocks.ReplayAll(); - } + // When + HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection); + calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble()); + calculation.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.ReplayAll(); } [Test] + [Apartment(ApartmentState.STA)] public void GivenViewWithAssessmentSectionData_WhenAssessmentSectionUpdatedAndNotified_ThenMapDataUpdated() { // Given @@ -355,31 +343,31 @@ ReferenceLine = referenceLine }; - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - var referenceLineMapData = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + var referenceLineMapData = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); - // When - assessmentSection.Name = "New name"; - assessmentSection.NotifyObservers(); + // Precondition + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); - // Then - MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); - mocks.VerifyAll(); - } + // 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 @@ -394,80 +382,35 @@ ReferenceLine = referenceLine }; - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); - // When - referenceLine.SetGeometry(new List - { - new Point2D(2.0, 5.0), - new Point2D(4.0, 3.0) - }); - referenceLine.NotifyObservers(); + // Precondition + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); - // Then - MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); - mocks.VerifyAll(); - } - } - - [Test] - public void GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismSectionsUpdatedAndNotified_ThenMapDataUpdated() - { - // Given - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + // When + referenceLine.SetGeometry(new List { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }); + referenceLine.NotifyObservers(); - 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()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].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(); - } + // Then + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); } [Test] + [Apartment(ApartmentState.STA)] public void GivenViewWithForeshoreProfileData_WhenForeshoreProfileUpdatedAndNotified_ThenMapDataUpdated() { // Given @@ -483,36 +426,36 @@ foreshoreProfile }, "path"); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); - // When - var foreshoreProfileToUpdateFrom = new TestForeshoreProfile("originalProfile ID", new[] - { - new Point2D(2, 2), - new Point2D(3, 3) - }); - foreshoreProfile.CopyProperties(foreshoreProfileToUpdateFrom); - foreshoreProfile.NotifyObservers(); + // Precondition + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); - // Then - MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); - mocks.VerifyAll(); - } + // 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 @@ -526,38 +469,38 @@ }) }, "path"); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[foreshoreProfileObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + MapData foreshoreProfileData = map.Data.Collection.ElementAt(foreshoreProfilesIndex); - // When - failureMechanism.ForeshoreProfiles.AddRange(new[] + // Precondition + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + + // When + failureMechanism.ForeshoreProfiles.AddRange(new[] + { + new TestForeshoreProfile("newProfile ID", new[] { - new TestForeshoreProfile("newProfile ID", new[] - { - new Point2D(2, 2), - new Point2D(3, 3) - }) - }, "path"); - failureMechanism.ForeshoreProfiles.NotifyObservers(); + new Point2D(2, 2), + new Point2D(3, 3) + }) + }, "path"); + failureMechanism.ForeshoreProfiles.NotifyObservers(); - // Then - MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); - mocks.VerifyAll(); - } + // Then + MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, foreshoreProfileData); + mocks.VerifyAll(); } [Test] + [Apartment(ApartmentState.STA)] public void GivenViewWithCalculationGroupData_WhenCalculationGroupUpdatedAndNotified_ThenMapDataUpdated() { // Given @@ -572,44 +515,40 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), - calculationMapData); + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); - // When - var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); + + // When + var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = { - InputParameters = - { - ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)), - HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() - } - }; - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationB); - failureMechanism.WaveConditionsCalculationGroup.NotifyObservers(); + ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation() + } + }; + failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationB); + failureMechanism.WaveConditionsCalculationGroup.NotifyObservers(); - // Then - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); - mocks.VerifyAll(); - } + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); } [Test] + [Apartment(ApartmentState.STA)] public void GivenViewWithCalculationInputData_WhenCalculationInputUpdatedAndNotified_ThenMapDataUpdated() { // Given @@ -624,36 +563,32 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), - calculationMapData); + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); - // When - calculationA.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.5, 1.5)); - calculationA.InputParameters.NotifyObservers(); + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); - // Then - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); - mocks.VerifyAll(); - } + // 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 @@ -668,319 +603,102 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, new AssessmentSectionStub()); - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), - calculationMapData); + var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); - // When - calculationA.Name = "new name"; - calculationA.NotifyObservers(); + // Precondition + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), + calculationMapData); - // Then - AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); - mocks.VerifyAll(); - } - } + // When + calculationA.Name = "new name"; + calculationA.NotifyObservers(); - [Test] - public void GivenViewWithAssemblyData_WhenFailureMechanismNotified_ThenMapDataUpdated() - { - // Given - var random = new Random(39); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); - - var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var originalDetailedAssemblyCategory = random.NextEnumValue(); - var originalTailorMadeAssemblyCategory = random.NextEnumValue(); - var originalCombinedAssemblyCategory = random.NextEnumValue(); - - using (new AssemblyToolCalculatorFactoryConfig()) - { - var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; - FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; - - calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - - 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()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); - - // Precondition - var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); - MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, - originalDetailedAssemblyCategory, - originalTailorMadeAssemblyCategory, - originalCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - - // When - var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var updatedDetailedAssemblyCategory = random.NextEnumValue(); - var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); - var updatedCombinedAssemblyCategory = random.NextEnumValue(); - calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; - failureMechanism.NotifyObservers(); - - // Then - MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, - updatedDetailedAssemblyCategory, - updatedTailorMadeAssemblyCategory, - updatedCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - mocks.VerifyAll(); - } - } + // Then + AssertCalculationsMapData(failureMechanism.Calculations.Cast(), calculationMapData); + mocks.VerifyAll(); } [Test] - public void GivenViewWithAssemblyData_WhenCalculationNotified_ThenMapDataUpdated() - { - // Given - var random = new Random(39); - var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation(); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA); - FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); - - var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var originalDetailedAssemblyCategory = random.NextEnumValue(); - var originalTailorMadeAssemblyCategory = random.NextEnumValue(); - var originalCombinedAssemblyCategory = random.NextEnumValue(); - - using (new AssemblyToolCalculatorFactoryConfig()) - { - var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; - FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; - - calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(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()); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); - - // Precondition - var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); - MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, - originalDetailedAssemblyCategory, - originalTailorMadeAssemblyCategory, - originalCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - - // When - var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var updatedDetailedAssemblyCategory = random.NextEnumValue(); - var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); - var updatedCombinedAssemblyCategory = random.NextEnumValue(); - calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; - calculationA.NotifyObservers(); - - // Then - MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, - updatedDetailedAssemblyCategory, - updatedTailorMadeAssemblyCategory, - updatedCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - mocks.VerifyAll(); - } - } - } - - [Test] - public void GivenViewWithAssemblyData_WhenFailureMechanismSectionResultNotified_ThenMapDataUpdated() - { - // Given - var random = new Random(39); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); - - var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var originalDetailedAssemblyCategory = random.NextEnumValue(); - var originalTailorMadeAssemblyCategory = random.NextEnumValue(); - var originalCombinedAssemblyCategory = random.NextEnumValue(); - - using (new AssemblyToolCalculatorFactoryConfig()) - { - var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; - FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; - - calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, new AssessmentSectionStub())) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); - - // Precondition - var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); - MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, - originalDetailedAssemblyCategory, - originalTailorMadeAssemblyCategory, - originalCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - - // When - var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); - var updatedDetailedAssemblyCategory = random.NextEnumValue(); - var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); - var updatedCombinedAssemblyCategory = random.NextEnumValue(); - calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; - calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; - calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; - calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; - failureMechanism.SectionResults.First().NotifyObservers(); - - // Then - MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, - updatedDetailedAssemblyCategory, - updatedTailorMadeAssemblyCategory, - updatedCombinedAssemblyCategory, - assemblyMapData, - failureMechanism); - mocks.VerifyAll(); - } - } - } - - [Test] + [Apartment(ApartmentState.STA)] public void UpdateObserver_DataUpdated_MapLayersSameOrder() { // Setup - const int updatedReferenceLineLayerIndex = referenceLineIndex + 5; - const int updatedSectionsCollectionLayerIndex = sectionsCollectionIndex - 1; - const int updatedAssemblyResultsCollectionIndex = assemblyResultsIndex - 1; + 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(); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + WaveImpactAsphaltCoverFailureMechanismView view = CreateView(failureMechanism, assessmentSection); - MapDataCollection mapData = map.Data; + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; - var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); - mapData.Remove(dataToMove); - mapData.Add(dataToMove); + MapDataCollection mapData = map.Data; - List mapDataList = mapData.Collection.ToList(); + var dataToMove = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); - // Precondition - var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; - Assert.AreEqual("Referentielijn", referenceLineData.Name); + List mapDataList = mapData.Collection.ToList(); - var sectionsData = (MapDataCollection) mapDataList[updatedSectionsCollectionLayerIndex]; - Assert.AreEqual("Vakindeling", sectionsData.Name); + // Precondition + var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.Name); - var assemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; - Assert.AreEqual("Toetsoordeel", assemblyResultsData.Name); + var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); - var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; - Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); - var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; - Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.Name); + var calculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; + Assert.AreEqual("Berekeningen", calculationsData.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; - 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(); - // Call - assessmentSection.NotifyObservers(); + // Assert + var actualReferenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); - // Assert - var actualReferenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; - Assert.AreEqual("Referentielijn", actualReferenceLineData.Name); + var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); - var actualSectionsData = (MapDataCollection) mapDataList[updatedSectionsCollectionLayerIndex]; - Assert.AreEqual("Vakindeling", actualSectionsData.Name); + var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); - var actualAssemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; - Assert.AreEqual("Toetsoordeel", actualAssemblyResultsData.Name); + var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } - var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; - Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + private WaveImpactAsphaltCoverFailureMechanismView CreateView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection); - var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; - Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + testForm.Controls.Add(view); + testForm.Show(); - var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; - Assert.AreEqual("Berekeningen", actualCalculationsData.Name); - } + return view; } private static void AssertCalculationsMapData(IEnumerable calculations, MapData mapData) @@ -1013,7 +731,7 @@ List mapDataList = mapDataCollection.Collection.ToList(); - Assert.AreEqual(6, mapDataList.Count); + Assert.AreEqual(4, mapDataList.Count); var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; @@ -1029,43 +747,6 @@ 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); - - var assemblyResultsMapDataCollection = (MapDataCollection) mapDataList[assemblyResultsIndex]; - Assert.AreEqual("Toetsoordeel", assemblyResultsMapDataCollection.Name); - List assemblyMapDataList = assemblyResultsMapDataCollection.Collection.ToList(); - Assert.AreEqual(4, assemblyMapDataList.Count); - - var combinedAssemblyMapData = (MapLineData) assemblyMapDataList[combinedAssemblyIndex]; - var simpleAssemblyMapData = (MapLineData) assemblyMapDataList[simpleAssemblyIndex]; - var detailedAssemblyMapData = (MapLineData) assemblyMapDataList[detailedAssemblyIndex]; - var tailorMadeAssemblyMapData = (MapLineData) assemblyMapDataList[tailorMadeAssemblyIndex]; - - CollectionAssert.IsEmpty(combinedAssemblyMapData.Features); - CollectionAssert.IsEmpty(simpleAssemblyMapData.Features); - CollectionAssert.IsEmpty(detailedAssemblyMapData.Features); - CollectionAssert.IsEmpty(tailorMadeAssemblyMapData.Features); - - Assert.AreEqual("Gecombineerd toetsoordeel", combinedAssemblyMapData.Name); - Assert.AreEqual("Toetsoordeel eenvoudige toets", simpleAssemblyMapData.Name); - Assert.AreEqual("Toetsoordeel gedetailleerde toets", detailedAssemblyMapData.Name); - Assert.AreEqual("Toetsoordeel toets op maat", tailorMadeAssemblyMapData.Name); } /// @@ -1091,42 +772,12 @@ var calculationsMapDataObserver = mocks.StrictMock(); mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); - 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); - - MapData[] assemblyResultsCollection = ((MapDataCollection) mapDataArray[assemblyResultsIndex]).Collection.ToArray(); - var simpleAssemblyMapDataObserver = mocks.StrictMock(); - assemblyResultsCollection[simpleAssemblyIndex].Attach(simpleAssemblyMapDataObserver); - - var detailedAssemblyMapDataObserver = mocks.StrictMock(); - assemblyResultsCollection[detailedAssemblyIndex].Attach(detailedAssemblyMapDataObserver); - - var tailorMadeAssemblyMapDataObserver = mocks.StrictMock(); - assemblyResultsCollection[tailorMadeAssemblyIndex].Attach(tailorMadeAssemblyMapDataObserver); - - var combinedAssemblyMapDataObserver = mocks.StrictMock(); - assemblyResultsCollection[combinedAssemblyIndex].Attach(combinedAssemblyMapDataObserver); - return new[] { referenceLineMapDataObserver, hydraulicBoundaryLocationsMapDataObserver, foreshoreProfilesMapDataObserver, - calculationsMapDataObserver, - sectionsMapDataObserver, - sectionsStartPointMapDataObserver, - sectionsEndPointMapDataObserver, - simpleAssemblyMapDataObserver, - detailedAssemblyMapDataObserver, - tailorMadeAssemblyMapDataObserver, - combinedAssemblyMapDataObserver + calculationsMapDataObserver }; } } Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailurePathViewTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailurePathViewTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Forms.Test/Views/WaveImpactAsphaltCoverFailurePathViewTest.cs (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -0,0 +1,1116 @@ +// 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.Common.TestUtil; +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.Data; +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; + +namespace Riskeer.WaveImpactAsphaltCover.Forms.Test.Views +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailurePathViewTest + { + 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 tailorMadeAssemblyIndex = 0; + private const int detailedAssemblyIndex = 1; + private const int simpleAssemblyIndex = 2; + private const int combinedAssemblyIndex = 3; + + private const int hydraulicBoundaryLocationsObserverIndex = 1; + private const int foreshoreProfileObserverIndex = 2; + private const int calculationObserverIndex = 3; + private const int sectionsObserverIndex = 4; + private const int sectionsStartPointObserverIndex = 5; + private const int sectionsEndPointObserverIndex = 6; + private const int simpleAssemblyObserverIndex = 7; + private const int detailedAssemblyObserverIndex = 8; + private const int tailorMadeAssemblyObserverIndex = 9; + private const int combinedAssemblyObserverIndex = 10; + + 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 + WaveImpactAsphaltCoverFailurePathView 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_WithAllData_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var random = new Random(39); + + 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.WaveConditionsCalculationGroup.Children.Add(calculationA); + failureMechanism.WaveConditionsCalculationGroup.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) + }); + + var expectedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedDetailedAssemblyCategory = random.NextEnumValue(); + var expectedTailorMadeAssemblyCategory = random.NextEnumValue(); + var expectedCombinedAssemblyCategory = random.NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = expectedSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = expectedDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = expectedTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = expectedCombinedAssemblyCategory; + + // Call + WaveImpactAsphaltCoverFailurePathView 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]); + + MapDataTestHelper.AssertAssemblyMapDataCollection(expectedSimpleAssembly.Group, + expectedDetailedAssemblyCategory, + expectedTailorMadeAssemblyCategory, + expectedCombinedAssemblyCategory, + (MapDataCollection) mapDataList[assemblyResultsIndex], + failureMechanism); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationsUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var assessmentSection = new AssessmentSectionStub(); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + }); + + WaveImpactAsphaltCoverFailurePathView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + + // When + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(2, "test2", 3.0, 4.0) + }); + assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + [TestCaseSource(typeof(MapViewTestHelper), nameof(MapViewTestHelper.GetCalculationFuncs))] + public void GivenViewWithHydraulicBoundaryLocationsData_WhenHydraulicBoundaryLocationCalculationUpdatedAndNotified_ThenMapDataUpdated( + Func getCalculationFunc) + { + // Given + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); + var assessmentSection = new AssessmentSectionStub(); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation + }); + + WaveImpactAsphaltCoverFailurePathView view = CreateView(new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + MapData hydraulicBoundaryLocationsMapData = map.Data.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + + // Precondition + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + + // When + HydraulicBoundaryLocationCalculation calculation = getCalculationFunc(assessmentSection); + calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(new Random(21).NextDouble()); + calculation.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.ReplayAll(); + } + + [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 + }; + + WaveImpactAsphaltCoverFailurePathView 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 + }; + + WaveImpactAsphaltCoverFailurePathView 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 GivenViewWithFailureMechanismSectionsData_WhenFailureMechanismSectionsUpdatedAndNotified_ThenMapDataUpdated() + { + // Given + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + WaveImpactAsphaltCoverFailurePathView 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].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 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"); + + WaveImpactAsphaltCoverFailurePathView 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"); + + WaveImpactAsphaltCoverFailurePathView 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.WaveConditionsCalculationGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailurePathView 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].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.WaveConditionsCalculationGroup.Children.Add(calculationB); + failureMechanism.WaveConditionsCalculationGroup.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.WaveConditionsCalculationGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailurePathView 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].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.WaveConditionsCalculationGroup.Children.Add(calculationA); + + WaveImpactAsphaltCoverFailurePathView 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].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 GivenViewWithAssemblyData_WhenFailureMechanismNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssemblyCategory = random.NextEnumValue(); + var originalTailorMadeAssemblyCategory = random.NextEnumValue(); + var originalCombinedAssemblyCategory = random.NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; + + WaveImpactAsphaltCoverFailurePathView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, + originalDetailedAssemblyCategory, + originalTailorMadeAssemblyCategory, + originalCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssemblyCategory = random.NextEnumValue(); + var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); + var updatedCombinedAssemblyCategory = random.NextEnumValue(); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; + failureMechanism.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, + updatedDetailedAssemblyCategory, + updatedTailorMadeAssemblyCategory, + updatedCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithAssemblyData_WhenCalculationNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation(); + + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + failureMechanism.WaveConditionsCalculationGroup.Children.Add(calculationA); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssemblyCategory = random.NextEnumValue(); + var originalTailorMadeAssemblyCategory = random.NextEnumValue(); + var originalCombinedAssemblyCategory = random.NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; + + WaveImpactAsphaltCoverFailurePathView 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()); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, + originalDetailedAssemblyCategory, + originalTailorMadeAssemblyCategory, + originalCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssemblyCategory = random.NextEnumValue(); + var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); + var updatedCombinedAssemblyCategory = random.NextEnumValue(); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; + calculationA.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, + updatedDetailedAssemblyCategory, + updatedTailorMadeAssemblyCategory, + updatedCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void GivenViewWithAssemblyData_WhenFailureMechanismSectionResultNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssemblyCategory = random.NextEnumValue(); + var originalTailorMadeAssemblyCategory = random.NextEnumValue(); + var originalCombinedAssemblyCategory = random.NextEnumValue(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = originalDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = originalTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = originalCombinedAssemblyCategory; + + WaveImpactAsphaltCoverFailurePathView view = CreateView(failureMechanism, new AssessmentSectionStub()); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[simpleAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[detailedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[tailorMadeAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + observers[combinedAssemblyObserverIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly.Group, + originalDetailedAssemblyCategory, + originalTailorMadeAssemblyCategory, + originalCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssemblyCategory = random.NextEnumValue(); + var updatedTailorMadeAssemblyCategory = random.NextEnumValue(); + var updatedCombinedAssemblyCategory = random.NextEnumValue(); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyGroupOutput = updatedDetailedAssemblyCategory; + calculator.TailorMadeAssemblyCategoryOutput = updatedTailorMadeAssemblyCategory; + calculator.CombinedAssemblyCategoryOutput = updatedCombinedAssemblyCategory; + failureMechanism.SectionResults.First().NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly.Group, + updatedDetailedAssemblyCategory, + updatedTailorMadeAssemblyCategory, + updatedCombinedAssemblyCategory, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + + [Test] + [Apartment(ApartmentState.STA)] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + const int updatedReferenceLineLayerIndex = referenceLineIndex + 5; + const int updatedSectionsCollectionLayerIndex = sectionsCollectionIndex - 1; + const int updatedAssemblyResultsCollectionIndex = 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(); + + WaveImpactAsphaltCoverFailurePathView 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); + + List mapDataList = mapData.Collection.ToList(); + + // Precondition + var referenceLineData = (MapLineData) mapDataList[updatedReferenceLineLayerIndex]; + Assert.AreEqual("Referentielijn", referenceLineData.Name); + + var sectionsData = (MapDataCollection) mapDataList[updatedSectionsCollectionLayerIndex]; + Assert.AreEqual("Vakindeling", sectionsData.Name); + + var assemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; + Assert.AreEqual("Toetsoordeel", assemblyResultsData.Name); + + var hydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", hydraulicLocationsData.Name); + + var foreshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", foreshoreProfilesData.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[updatedSectionsCollectionLayerIndex]; + Assert.AreEqual("Vakindeling", actualSectionsData.Name); + + var actualAssemblyResultsData = (MapDataCollection) mapDataList[updatedAssemblyResultsCollectionIndex]; + Assert.AreEqual("Toetsoordeel", actualAssemblyResultsData.Name); + + var actualHydraulicLocationsData = (MapPointData) mapDataList[updatedHydraulicLocationsLayerIndex]; + Assert.AreEqual("Hydraulische belastingen", actualHydraulicLocationsData.Name); + + var actualForeshoreProfilesData = (MapLineData) mapDataList[updatedForeshoreProfilesLayerIndex]; + Assert.AreEqual("Voorlandprofielen", actualForeshoreProfilesData.Name); + + var actualCalculationsData = (MapLineData) mapDataList[updatedCalculationsIndex]; + Assert.AreEqual("Berekeningen", actualCalculationsData.Name); + } + + private WaveImpactAsphaltCoverFailurePathView CreateView(WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) + { + var view = new WaveImpactAsphaltCoverFailurePathView(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("Dijken en dammen - Golfklappen op asfaltbekleding", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(6, 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); + + 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); + + var assemblyResultsMapDataCollection = (MapDataCollection) mapDataList[assemblyResultsIndex]; + Assert.AreEqual("Toetsoordeel", assemblyResultsMapDataCollection.Name); + List assemblyMapDataList = assemblyResultsMapDataCollection.Collection.ToList(); + Assert.AreEqual(4, assemblyMapDataList.Count); + + var combinedAssemblyMapData = (MapLineData) assemblyMapDataList[combinedAssemblyIndex]; + var simpleAssemblyMapData = (MapLineData) assemblyMapDataList[simpleAssemblyIndex]; + var detailedAssemblyMapData = (MapLineData) assemblyMapDataList[detailedAssemblyIndex]; + var tailorMadeAssemblyMapData = (MapLineData) assemblyMapDataList[tailorMadeAssemblyIndex]; + + CollectionAssert.IsEmpty(combinedAssemblyMapData.Features); + CollectionAssert.IsEmpty(simpleAssemblyMapData.Features); + CollectionAssert.IsEmpty(detailedAssemblyMapData.Features); + CollectionAssert.IsEmpty(tailorMadeAssemblyMapData.Features); + + Assert.AreEqual("Gecombineerd toetsoordeel", combinedAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel eenvoudige toets", simpleAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel gedetailleerde toets", detailedAssemblyMapData.Name); + Assert.AreEqual("Toetsoordeel toets op maat", tailorMadeAssemblyMapData.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 hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock(); + mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver); + + var foreshoreProfilesMapDataObserver = mocks.StrictMock(); + mapDataArray[foreshoreProfilesIndex].Attach(foreshoreProfilesMapDataObserver); + + var calculationsMapDataObserver = mocks.StrictMock(); + mapDataArray[calculationsIndex].Attach(calculationsMapDataObserver); + + 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); + + MapData[] assemblyResultsCollection = ((MapDataCollection) mapDataArray[assemblyResultsIndex]).Collection.ToArray(); + var simpleAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[simpleAssemblyIndex].Attach(simpleAssemblyMapDataObserver); + + var detailedAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[detailedAssemblyIndex].Attach(detailedAssemblyMapDataObserver); + + var tailorMadeAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[tailorMadeAssemblyIndex].Attach(tailorMadeAssemblyMapDataObserver); + + var combinedAssemblyMapDataObserver = mocks.StrictMock(); + assemblyResultsCollection[combinedAssemblyIndex].Attach(combinedAssemblyMapDataObserver); + + return new[] + { + referenceLineMapDataObserver, + hydraulicBoundaryLocationsMapDataObserver, + foreshoreProfilesMapDataObserver, + calculationsMapDataObserver, + sectionsMapDataObserver, + sectionsStartPointMapDataObserver, + sectionsEndPointMapDataObserver, + simpleAssemblyMapDataObserver, + detailedAssemblyMapDataObserver, + tailorMadeAssemblyMapDataObserver, + combinedAssemblyMapDataObserver + }; + } + } +} \ No newline at end of file Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs =================================================================== diff -u -r38960ec42c1c6f6438d7a04ce0f58e114e6ff180 -r7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs) (revision 38960ec42c1c6f6438d7a04ce0f58e114e6ff180) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs (.../WaveImpactAsphaltCoverFailureMechanismViewInfoTest.cs) (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -21,7 +21,7 @@ using System.Drawing; using System.Linq; -using Core.Common.Controls.Views; +using System.Windows.Forms; using Core.Common.TestUtil; using Core.Gui.Plugin; using NUnit.Framework; @@ -92,123 +92,26 @@ } [Test] - public void CloseForData_ViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse() + public void CreateInstance_WithContext_ReturnWaveImpactAsphaltCoverFailureMechanismView() { // Setup var assessmentSection = new AssessmentSectionStub(); - var otherAssessmentSection = mocks.Stub(); - mocks.ReplayAll(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - // Call - bool closeForData = info.CloseForData(view, otherAssessmentSection); + var context = new WaveImpactAsphaltCoverCalculationsContext(failureMechanism, assessmentSection); - // Assert - Assert.IsFalse(closeForData); - } - - mocks.VerifyAll(); - } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedAssessmentSection_ReturnsTrue() - { - // Setup - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) + using (var testForm = new Form()) { // Call - bool closeForData = info.CloseForData(view, assessmentSection); + var view = info.CreateInstance(context) as WaveImpactAsphaltCoverFailureMechanismView; - // Assert - Assert.IsTrue(closeForData); - } + testForm.Controls.Add(view); + testForm.Show(); - mocks.VerifyAll(); - } - - [Test] - public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanism_ReturnsFalse() - { - // Setup - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - var otherWaveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - // Call - bool closeForData = info.CloseForData(view, otherWaveImpactAsphaltCoverFailureMechanism); - // Assert - Assert.IsFalse(closeForData); + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.AreSame(assessmentSection, view.AssessmentSection); } } - - [Test] - public void CloseForData_ViewCorrespondingToRemovedFailureMechanism_ReturnsTrue() - { - // Setup - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - - using (var view = new WaveImpactAsphaltCoverFailureMechanismView(failureMechanism, assessmentSection)) - { - // Call - bool closeForData = info.CloseForData(view, failureMechanism); - - // Assert - Assert.IsTrue(closeForData); - } - } - - [Test] - [TestCase(true)] - [TestCase(false)] - public void AdditionalDataCheck_Always_ReturnTrueOnlyIfFailureMechanismRelevant(bool isRelevant) - { - // Setup - var assessmentSection = mocks.Stub(); - mocks.ReplayAll(); - - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism - { - IsRelevant = isRelevant - }; - - var context = new WaveImpactAsphaltCoverCalculationsContext(failureMechanism, assessmentSection); - - // Call - bool result = info.AdditionalDataCheck(context); - - // Assert - Assert.AreEqual(isRelevant, result); - mocks.VerifyAll(); - } - - [Test] - public void CreateInstance_WithContext_ReturnWaveImpactAsphaltCoverFailureMechanismView() - { - // Setup - var assessmentSection = new AssessmentSectionStub(); - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - - var context = new WaveImpactAsphaltCoverCalculationsContext(failureMechanism, assessmentSection); - - // Call - IView view = info.CreateInstance(context); - - // Assert - Assert.IsInstanceOf(view); - - var failureMechanismView = (WaveImpactAsphaltCoverFailureMechanismView) view; - Assert.AreSame(failureMechanism, failureMechanismView.FailureMechanism); - Assert.AreSame(assessmentSection, failureMechanismView.AssessmentSection); - } } } \ No newline at end of file Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailurePathViewInfoTest.cs =================================================================== diff -u --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailurePathViewInfoTest.cs (revision 0) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/ViewInfos/WaveImpactAsphaltCoverFailurePathViewInfoTest.cs (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -0,0 +1,119 @@ +// 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.Drawing; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.TestUtil; +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; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.WaveImpactAsphaltCover.Plugin.Test.ViewInfos +{ + [TestFixture] + public class WaveImpactAsphaltCoverFailurePathViewInfoTest + { + 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(WaveImpactAsphaltCoverFailurePathView)); + } + + [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] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.FailureMechanismIcon, image); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void CreateInstance_WithContext_ReturnWaveImpactAsphaltCoverFailurePathView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var context = new WaveImpactAsphaltCoverFailurePathContext(failureMechanism, assessmentSection); + + using (var testForm = new Form()) + { + // Call + var view = info.CreateInstance(context) as WaveImpactAsphaltCoverFailurePathView; + + testForm.Controls.Add(view); + testForm.Show(); + + // 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/WaveImpactAsphaltCoverPluginTest.cs =================================================================== diff -u -r54a48626d01c301e2b30a2ce45125375d64ca5a4 -r7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/WaveImpactAsphaltCoverPluginTest.cs (.../WaveImpactAsphaltCoverPluginTest.cs) (revision 54a48626d01c301e2b30a2ce45125375d64ca5a4) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/WaveImpactAsphaltCoverPluginTest.cs (.../WaveImpactAsphaltCoverPluginTest.cs) (revision 7e8b7562d2dec62c1c5c0a205e1f7f4eca7243fc) @@ -97,12 +97,17 @@ ViewInfo[] viewInfos = plugin.GetViewInfos().ToArray(); // Assert - Assert.AreEqual(3, viewInfos.Length); + Assert.AreEqual(4, viewInfos.Length); PluginTestHelper.AssertViewInfoDefined( viewInfos, typeof(WaveImpactAsphaltCoverCalculationsContext), typeof(WaveImpactAsphaltCoverFailureMechanismView)); + + PluginTestHelper.AssertViewInfoDefined( + viewInfos, + typeof(WaveImpactAsphaltCoverFailurePathContext), + typeof(WaveImpactAsphaltCoverFailurePathView)); PluginTestHelper.AssertViewInfoDefined( viewInfos,