Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionExtendedViewTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionExtendedViewTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionExtendedViewTest.cs (revision 24dadd7f736e8b0c9cd420a1def367e5c51e4ad2) @@ -0,0 +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. + +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 AssessmentSectionExtendedViewTest : 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 + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + + // Assert + Assert.IsInstanceOf(extendedView); + Assert.IsInstanceOf(extendedView); + Assert.IsNull(extendedView.Data); + + Assert.AreEqual(2, extendedView.Controls.Count); + Assert.IsInstanceOf(extendedView.Controls[0]); + Assert.AreSame(extendedView.Map, ((RiskeerMapControl) extendedView.Controls[0]).MapControl); + Assert.AreEqual(DockStyle.Fill, ((Control) extendedView.Map).Dock); + AssertEmptyMapData(extendedView.Map.Data); + } + + [Test] + public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + void Call() => new AssessmentSectionExtendedView(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + + // Call + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + + // Assert + MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, extendedView.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 + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + + // Assert + Assert.IsInstanceOf(extendedView.Map.Data); + MapDataCollection mapData = extendedView.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 + }); + + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + + IMapControl map = ((RiskeerMapControl) extendedView.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) + }); + + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + IMapControl map = ((RiskeerMapControl) extendedView.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 + }; + + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + IMapControl map = ((RiskeerMapControl) extendedView.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 + }; + + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + IMapControl map = ((RiskeerMapControl) extendedView.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) + }); + + AssessmentSectionExtendedView extendedView = ShowCalculationsView(assessmentSection); + MapDataCollection mapData = extendedView.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 AssessmentSectionExtendedView ShowCalculationsView(IAssessmentSection assessmentSection) + { + var assessmentSectionView = new AssessmentSectionExtendedView(assessmentSection); + testForm.Controls.Add(assessmentSectionView); + testForm.Show(); + + return assessmentSectionView; + } + } +} \ No newline at end of file Fisheye: Tag 24dadd7f736e8b0c9cd420a1def367e5c51e4ad2 refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Views/AssessmentSectionViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/AssessmentSectionExtendedViewInfoTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/AssessmentSectionExtendedViewInfoTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/AssessmentSectionExtendedViewInfoTest.cs (revision 24dadd7f736e8b0c9cd420a1def367e5c51e4ad2) @@ -0,0 +1,94 @@ +// 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 Core.Common.Controls.Views; +using Core.Common.TestUtil; +using Core.Gui.Plugin; +using NUnit.Framework; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Integration.Forms.Views; +using RiskeerFormsResources = Riskeer.Integration.Forms.Properties.Resources; + +namespace Riskeer.Integration.Plugin.Test.ViewInfos +{ + [TestFixture] + public class AssessmentSectionExtendedViewInfoTest + { + private RiskeerPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + plugin = new RiskeerPlugin(); + info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(AssessmentSectionExtendedView)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(IAssessmentSection), info.DataType); + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Call + string viewName = info.GetViewName(null, null); + + // Assert + Assert.AreEqual("Trajectkaart", viewName); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RiskeerFormsResources.Map, image); + } + + [Test] + public void CreateInstance_WithAssessmentSection_ReturnsAssessmentSectionView() + { + // Setup + var assessmentSection = new AssessmentSectionStub(); + + // Call + IView view = info.CreateInstance(assessmentSection); + + // Assert + Assert.IsInstanceOf(view); + } + } +} \ No newline at end of file Fisheye: Tag 24dadd7f736e8b0c9cd420a1def367e5c51e4ad2 refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/ViewInfos/AssessmentSectionViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?