Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionReferenceLineView.cs =================================================================== diff -u -r389bbd8afb76c14374cf23b2802e532ea6059a4e -r60b0b93589099f5f331ebf12aa2d5e646d325963 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionReferenceLineView.cs (.../AssessmentSectionReferenceLineView.cs) (revision 389bbd8afb76c14374cf23b2802e532ea6059a4e) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionReferenceLineView.cs (.../AssessmentSectionReferenceLineView.cs) (revision 60b0b93589099f5f331ebf12aa2d5e646d325963) @@ -67,7 +67,6 @@ MapDataCollection.Add(referenceLineMapData); SetAllMapDataFeatures(); - riskeerMapControl.SetAllData(MapDataCollection, assessmentSection.BackgroundData); } public object Data { get; set; } @@ -82,6 +81,13 @@ protected MapDataCollection MapDataCollection { get; } + protected override void OnLoad(EventArgs e) + { + riskeerMapControl.SetAllData(MapDataCollection, assessmentSection.BackgroundData); + + base.OnLoad(e); + } + protected override void Dispose(bool disposing) { assessmentSectionObserver.Dispose(); Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionView.cs =================================================================== diff -u -r62f69365c3ca1c417bf5b03318fda99ed6f6e778 -r60b0b93589099f5f331ebf12aa2d5e646d325963 --- Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionView.cs (.../AssessmentSectionView.cs) (revision 62f69365c3ca1c417bf5b03318fda99ed6f6e778) +++ Riskeer/Integration/src/Riskeer.Integration.Forms/Views/AssessmentSectionView.cs (.../AssessmentSectionView.cs) (revision 60b0b93589099f5f331ebf12aa2d5e646d325963) @@ -64,10 +64,9 @@ hydraulicBoundaryLocationsMapData = RiskeerMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); - //MapDataCollection.Add(hydraulicBoundaryLocationsMapData); + MapDataCollection.Add(hydraulicBoundaryLocationsMapData); - //SetAllMapDataFeatures(); - //riskeerMapControl.SetAllData(MapDataCollection, assessmentSection.BackgroundData); + SetAllMapDataFeatures(); } protected override void Dispose(bool disposing) Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionReferenceLineViewTest.cs =================================================================== diff -u -rf12484d4debb221524bf92ec7c470088243c99d8 -r60b0b93589099f5f331ebf12aa2d5e646d325963 --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionReferenceLineViewTest.cs (.../AssessmentSectionReferenceLineViewTest.cs) (revision f12484d4debb221524bf92ec7c470088243c99d8) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionReferenceLineViewTest.cs (.../AssessmentSectionReferenceLineViewTest.cs) (revision 60b0b93589099f5f331ebf12aa2d5e646d325963) @@ -22,11 +22,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Geometry; using Core.Components.Gis.Data; using Core.Components.Gis.Forms; +using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Riskeer.Common.Data.AssessmentSection; @@ -38,30 +40,32 @@ namespace Riskeer.Integration.Forms.Test.Views { [TestFixture] - public class AssessmentSectionReferenceLineViewTest + [Apartment(ApartmentState.STA)] + public class AssessmentSectionReferenceLineViewTest : NUnitFormTest { private const int referenceLineIndex = 0; + private Form testForm; + [Test] public void Constructor_ExpectedValues() { // Setup var assessmentSection = new AssessmentSectionStub(); // Call - using (var view = new AssessmentSectionReferenceLineView(assessmentSection)) - { - // Assert - Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); - Assert.IsNull(view.Data); + AssessmentSectionReferenceLineView view = ShowCalculationsView(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.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] @@ -82,11 +86,10 @@ var assessmentSection = new AssessmentSectionStub(); // Call - using (var view = new AssessmentSectionReferenceLineView(assessmentSection)) - { - // Assert - MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); - } + AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); } [Test] @@ -106,16 +109,15 @@ }; // Call - using (var view = new AssessmentSectionReferenceLineView(assessmentSection)) - { - // Assert - Assert.IsInstanceOf(view.Map.Data); - MapDataCollection mapData = view.Map.Data; - Assert.IsNotNull(mapData); + AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection); - MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); - AssertReferenceLineMapData(referenceLine, referenceLineMapData); - } + // Assert + Assert.IsInstanceOf(view.Map.Data); + MapDataCollection mapData = view.Map.Data; + Assert.IsNotNull(mapData); + + MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); + AssertReferenceLineMapData(referenceLine, referenceLineMapData); } [Test] @@ -134,29 +136,28 @@ ReferenceLine = referenceLine }; - using (var view = new AssessmentSectionReferenceLineView(assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection); - var mocks = new MockRepository(); - IObserver observer = AttachReferenceLineMapDataObserver(mocks, map.Data.Collection); - observer.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 observer = AttachReferenceLineMapDataObserver(mocks, map.Data.Collection); + observer.Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); - AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + var referenceLineMapData = (MapLineData) map.Data.Collection.ElementAt(referenceLineIndex); - // Call - assessmentSection.Name = "New name"; - assessmentSection.NotifyObservers(); + // Precondition + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); - // Assert - MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); - mocks.VerifyAll(); - } + // Call + assessmentSection.Name = "New name"; + assessmentSection.NotifyObservers(); + + // Assert + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + mocks.VerifyAll(); } [Test] @@ -175,32 +176,31 @@ ReferenceLine = referenceLine }; - using (var view = new AssessmentSectionReferenceLineView(assessmentSection)) - { - IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + AssessmentSectionReferenceLineView view = ShowCalculationsView(assessmentSection); - var mocks = new MockRepository(); - IObserver observer = AttachReferenceLineMapDataObserver(mocks, map.Data.Collection); - observer.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 observer = AttachReferenceLineMapDataObserver(mocks, map.Data.Collection); + observer.Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); - // Precondition - AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + MapData referenceLineMapData = map.Data.Collection.ElementAt(referenceLineIndex); - // Call - referenceLine.SetGeometry(new List - { - new Point2D(2.0, 5.0), - new Point2D(4.0, 3.0) - }); - referenceLine.NotifyObservers(); + // Precondition + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); - // Assert - AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); - mocks.VerifyAll(); - } + // Call + referenceLine.SetGeometry(new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }); + referenceLine.NotifyObservers(); + + // Assert + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); } private static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData referenceLineMapData) @@ -224,6 +224,20 @@ Assert.AreEqual("Referentielijn", referenceLineMapData.Name); } + public override void Setup() + { + base.Setup(); + + testForm = new Form(); + } + + public override void TearDown() + { + base.TearDown(); + + testForm.Dispose(); + } + /// /// Attaches a mocked observer to the map data components. /// @@ -239,5 +253,14 @@ mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); return referenceLineMapDataObserver; } + + private AssessmentSectionReferenceLineView ShowCalculationsView(IAssessmentSection assessmentSection) + { + var assessmentSectionView = new AssessmentSectionReferenceLineView(assessmentSection); + testForm.Controls.Add(assessmentSectionView); + testForm.Show(); + + return assessmentSectionView; + } } } \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionViewTest.cs =================================================================== diff -u -r752431b2be66148c64e3168d2c2b8a149f58d8d2 -r60b0b93589099f5f331ebf12aa2d5e646d325963 --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionViewTest.cs (.../AssessmentSectionViewTest.cs) (revision 752431b2be66148c64e3168d2c2b8a149f58d8d2) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionViewTest.cs (.../AssessmentSectionViewTest.cs) (revision 60b0b93589099f5f331ebf12aa2d5e646d325963) @@ -1,389 +1,405 @@ -// // 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. +// Copyright (C) Stichting Deltares 2021. All rights reserved. // -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Windows.Forms; -// using Core.Common.Base; -// using Core.Common.Base.Geometry; -// using Core.Components.Gis.Data; -// using Core.Components.Gis.Forms; -// using NUnit.Framework; -// using Rhino.Mocks; -// using Riskeer.Common.Data.AssessmentSection; -// using Riskeer.Common.Data.Hydraulics; -// using Riskeer.Common.Data.TestUtil; -// using Riskeer.Common.Forms.TestUtil; -// using Riskeer.Common.Forms.Views; -// using Riskeer.Integration.Forms.Views; +// This file is part of Riskeer. // -// namespace Riskeer.Integration.Forms.Test.Views -// { -// [TestFixture] -// public class AssessmentSectionViewTest -// { -// private const int referenceLineIndex = 0; -// private const int hydraulicBoundaryLocationsIndex = 1; +// 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. // -// [Test] -// public void Constructor_ExpectedValues() -// { -// // Setup -// var assessmentSection = new AssessmentSectionStub(); +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . // -// // Call -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// // Assert -// Assert.IsInstanceOf(view); -// Assert.IsInstanceOf(view); -// Assert.IsNull(view.Data); -// -// 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] -// public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() -// { -// // Call -// void Call() => new AssessmentSectionView(null); -// -// // Assert -// var exception = Assert.Throws(Call); -// Assert.AreEqual("assessmentSection", exception.ParamName); -// } -// -// [Test] -// public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() -// { -// // Setup -// var assessmentSection = new AssessmentSectionStub(); -// -// // Call -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// // Assert -// MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); -// } -// } -// -// [Test] -// public void Constructor_WithReferenceLineAndHydraulicBoundaryDatabase_DataUpdatedToCollectionOfFilledMapData() -// { -// // Setup -// var referenceLine = new ReferenceLine(); -// referenceLine.SetGeometry(new[] -// { -// new Point2D(1.0, 2.0), -// new Point2D(2.0, 1.0) -// }); -// -// var assessmentSection = new AssessmentSectionStub -// { -// ReferenceLine = referenceLine -// }; -// assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] -// { -// new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) -// }); -// -// // Call -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// // Assert -// Assert.IsInstanceOf(view.Map.Data); -// MapDataCollection mapData = view.Map.Data; -// Assert.IsNotNull(mapData); -// -// MapData hydraulicBoundaryLocationsMapData = mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex); -// MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); -// -// MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); -// AssertReferenceLineMapData(referenceLine, referenceLineMapData); -// } -// } -// -// [Test] -// [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 -// }); -// -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; -// -// var mocks = new MockRepository(); -// IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); -// observers[hydraulicBoundaryLocationsIndex].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.VerifyAll(); -// } -// } -// -// [Test] -// public void GivenViewWithHydraulicBoundaryLocationsDatabase_WhenChangingHydraulicBoundaryLocationsDataAndObserversNotified_ThenMapDataUpdated() -// { -// // Given -// var assessmentSection = new AssessmentSectionStub(); -// assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] -// { -// new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) -// }); -// -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; -// -// var mocks = new MockRepository(); -// IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); -// observers[hydraulicBoundaryLocationsIndex].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", 2.0, 3.0) -// }); -// assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); -// -// // Then -// MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); -// mocks.VerifyAll(); -// } -// } -// -// [Test] -// public void UpdateObserver_AssessmentSectionUpdated_MapDataUpdated() -// { -// // Setup -// 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 -// }; -// -// using (var view = new AssessmentSectionView(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); -// AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); -// -// // Call -// assessmentSection.Name = "New name"; -// assessmentSection.NotifyObservers(); -// -// // Assert -// MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); -// mocks.VerifyAll(); -// } -// } -// -// [Test] -// public void UpdateObserver_ReferenceLineUpdated_MapDataUpdated() -// { -// // Setup -// 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 -// }; -// -// using (var view = new AssessmentSectionView(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 -// AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); -// -// // Call -// referenceLine.SetGeometry(new List -// { -// new Point2D(2.0, 5.0), -// new Point2D(4.0, 3.0) -// }); -// referenceLine.NotifyObservers(); -// -// // Assert -// AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); -// mocks.VerifyAll(); -// } -// } -// -// [Test] -// public void UpdateObserver_DataUpdated_MapLayersSameOrder() -// { -// // Setup -// var referenceLine = new ReferenceLine(); -// referenceLine.SetGeometry(new[] -// { -// new Point2D(1.0, 2.0), -// new Point2D(2.0, 1.0) -// }); -// -// var assessmentSection = new AssessmentSectionStub -// { -// ReferenceLine = referenceLine -// }; -// assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] -// { -// new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) -// }); -// -// using (var view = new AssessmentSectionView(assessmentSection)) -// { -// MapDataCollection mapData = view.Map.Data; -// -// MapData dataToMove = mapData.Collection.ElementAt(0); -// mapData.Remove(dataToMove); -// mapData.Add(dataToMove); -// -// // Precondition -// var referenceLineMapData = (MapLineData) mapData.Collection.ElementAt(referenceLineIndex + 1); -// Assert.AreEqual("Referentielijn", referenceLineMapData.Name); -// -// var hrLocationsMapData = (MapPointData) mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); -// Assert.AreEqual("Hydraulische belastingen", hrLocationsMapData.Name); -// -// // Call -// assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] -// { -// new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) -// }); -// assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); -// -// // Assert -// var actualReferenceLineMapData = (MapLineData) mapData.Collection.ElementAt(referenceLineIndex + 1); -// Assert.AreEqual("Referentielijn", actualReferenceLineMapData.Name); -// -// var actualHrLocationsMapData = (MapPointData) mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); -// Assert.AreEqual("Hydraulische belastingen", actualHrLocationsMapData.Name); -// } -// } -// -// private static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData referenceLineMapData) -// { -// MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData); -// Assert.IsTrue(referenceLineMapData.IsVisible); -// } -// -// private static void AssertEmptyMapData(MapDataCollection mapDataCollection) -// { -// Assert.AreEqual("Trajectkaart", mapDataCollection.Name); -// -// List mapDataList = mapDataCollection.Collection.ToList(); -// -// Assert.AreEqual(2, mapDataList.Count); -// -// var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; -// var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; -// -// CollectionAssert.IsEmpty(referenceLineMapData.Features); -// CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); -// -// Assert.AreEqual("Referentielijn", referenceLineMapData.Name); -// Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.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); -// -// return new[] -// { -// referenceLineMapDataObserver, -// hydraulicBoundaryLocationsMapDataObserver -// }; -// } -// } -// } \ No newline at end of file +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Data; +using Core.Components.Gis.Forms; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.TestUtil; +using Riskeer.Common.Forms.Views; +using Riskeer.Integration.Forms.Views; + +namespace Riskeer.Integration.Forms.Test.Views +{ + [TestFixture] + [Apartment(ApartmentState.STA)] + public class AssessmentSectionViewTest : NUnitFormTest + { + private const int referenceLineIndex = 0; + private const int hydraulicBoundaryLocationsIndex = 1; + + private Form testForm; + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + + // Call + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + + // Assert + Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); + Assert.IsNull(view.Data); + + Assert.AreEqual(2, 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] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new AssessmentSectionView(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + + // Call + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); + } + + [Test] + public void Constructor_WithReferenceLineAndHydraulicBoundaryDatabase_DataUpdatedToCollectionOfFilledMapData() + { + // Setup + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) + }); + + // Call + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + + // Assert + Assert.IsInstanceOf(view.Map.Data); + MapDataCollection mapData = view.Map.Data; + Assert.IsNotNull(mapData); + + MapData hydraulicBoundaryLocationsMapData = mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex); + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + + MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); + AssertReferenceLineMapData(referenceLine, referenceLineMapData); + } + + [Test] + [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 + }); + + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsIndex].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.VerifyAll(); + } + + [Test] + public void GivenViewWithHydraulicBoundaryLocationsDatabase_WhenChangingHydraulicBoundaryLocationsDataAndObserversNotified_ThenMapDataUpdated() + { + // Given + var assessmentSection = new AssessmentSectionStub(); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + }); + + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + IMapControl map = ((RiskeerMapControl) view.Controls[0]).MapControl; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[hydraulicBoundaryLocationsIndex].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", 2.0, 3.0) + }); + assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + + // Then + MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); + mocks.VerifyAll(); + } + + [Test] + public void UpdateObserver_AssessmentSectionUpdated_MapDataUpdated() + { + // Setup + 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 + }; + + AssessmentSectionView view = ShowCalculationsView(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); + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + + // Call + assessmentSection.Name = "New name"; + assessmentSection.NotifyObservers(); + + // Assert + MapFeaturesTestHelper.AssertReferenceLineMetaData(assessmentSection.ReferenceLine, assessmentSection, referenceLineMapData.Features); + mocks.VerifyAll(); + } + + [Test] + public void UpdateObserver_ReferenceLineUpdated_MapDataUpdated() + { + // Setup + 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 + }; + + AssessmentSectionView view = ShowCalculationsView(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 + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + + // Call + referenceLine.SetGeometry(new List + { + new Point2D(2.0, 5.0), + new Point2D(4.0, 3.0) + }); + referenceLine.NotifyObservers(); + + // Assert + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); + mocks.VerifyAll(); + } + + [Test] + public void UpdateObserver_DataUpdated_MapLayersSameOrder() + { + // Setup + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + var assessmentSection = new AssessmentSectionStub + { + ReferenceLine = referenceLine + }; + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) + }); + + AssessmentSectionView view = ShowCalculationsView(assessmentSection); + MapDataCollection mapData = view.Map.Data; + + MapData dataToMove = mapData.Collection.ElementAt(0); + mapData.Remove(dataToMove); + mapData.Add(dataToMove); + + // Precondition + var referenceLineMapData = (MapLineData) mapData.Collection.ElementAt(referenceLineIndex + 1); + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + + var hrLocationsMapData = (MapPointData) mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); + Assert.AreEqual("Hydraulische belastingen", hrLocationsMapData.Name); + + // Call + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + new HydraulicBoundaryLocation(2, "test2", 2.0, 3.0) + }); + assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); + + // Assert + var actualReferenceLineMapData = (MapLineData) mapData.Collection.ElementAt(referenceLineIndex + 1); + Assert.AreEqual("Referentielijn", actualReferenceLineMapData.Name); + + var actualHrLocationsMapData = (MapPointData) mapData.Collection.ElementAt(hydraulicBoundaryLocationsIndex - 1); + Assert.AreEqual("Hydraulische belastingen", actualHrLocationsMapData.Name); + } + + public override void Setup() + { + base.Setup(); + + testForm = new Form(); + } + + public override void TearDown() + { + base.TearDown(); + + testForm.Dispose(); + } + + private static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData referenceLineMapData) + { + MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData); + Assert.IsTrue(referenceLineMapData.IsVisible); + } + + private static void AssertEmptyMapData(MapDataCollection mapDataCollection) + { + Assert.AreEqual("Trajectkaart", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(2, mapDataList.Count); + + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + + CollectionAssert.IsEmpty(referenceLineMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); + Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.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); + + return new[] + { + referenceLineMapDataObserver, + hydraulicBoundaryLocationsMapDataObserver + }; + } + + private AssessmentSectionView ShowCalculationsView(IAssessmentSection assessmentSection) + { + var assessmentSectionView = new AssessmentSectionView(assessmentSection); + testForm.Controls.Add(assessmentSectionView); + testForm.Show(); + + return assessmentSectionView; + } + } +} \ No newline at end of file