Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultPerSectionMapView.cs =================================================================== diff -u -r5f7ae1dd177727ad2bb1a4bb9605f4264409059c -re5363d0a483288d365fc50dbe070fbbb81bbdb67 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultPerSectionMapView.cs (.../AssemblyResultPerSectionMapView.cs) (revision 5f7ae1dd177727ad2bb1a4bb9605f4264409059c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultPerSectionMapView.cs (.../AssemblyResultPerSectionMapView.cs) (revision e5363d0a483288d365fc50dbe070fbbb81bbdb67) @@ -24,12 +24,12 @@ using Core.Common.Base; using Core.Components.Gis.Data; using Core.Components.Gis.Forms; -using Core.Components.Gis.Style; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Forms.Factories; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.Factories; +using Ringtoets.Integration.Forms.Observers; namespace Ringtoets.Integration.Forms.Views { @@ -44,6 +44,7 @@ private readonly MapPointData hydraulicBoundaryLocationsMapData; private Observer assessmentSectionObserver; + private Observer referenceLineObserver; private Observer hydraulicBoundaryLocationsObserver; private RecursiveObserver, HydraulicBoundaryLocationCalculation> waterLevelCalculationsForFactorizedSignalingNormObserver; private RecursiveObserver, HydraulicBoundaryLocationCalculation> waterLevelCalculationsForSignalingNormObserver; @@ -104,19 +105,20 @@ protected override void Dispose(bool disposing) { - assessmentSectionObserver.Dispose(); - waterLevelCalculationsForFactorizedSignalingNormObserver.Dispose(); - waterLevelCalculationsForSignalingNormObserver.Dispose(); - waterLevelCalculationsForLowerLimitNormObserver.Dispose(); - waterLevelCalculationsForFactorizedLowerLimitNormObserver.Dispose(); - waveHeightCalculationsForFactorizedSignalingNormObserver.Dispose(); - waveHeightCalculationsForSignalingNormObserver.Dispose(); - waveHeightCalculationsForLowerLimitNormObserver.Dispose(); - waveHeightCalculationsForFactorizedLowerLimitNormObserver.Dispose(); - hydraulicBoundaryLocationsObserver.Dispose(); - if (disposing) { + assessmentSectionObserver.Dispose(); + referenceLineObserver.Dispose(); + waterLevelCalculationsForFactorizedSignalingNormObserver.Dispose(); + waterLevelCalculationsForSignalingNormObserver.Dispose(); + waterLevelCalculationsForLowerLimitNormObserver.Dispose(); + waterLevelCalculationsForFactorizedLowerLimitNormObserver.Dispose(); + waveHeightCalculationsForFactorizedSignalingNormObserver.Dispose(); + waveHeightCalculationsForSignalingNormObserver.Dispose(); + waveHeightCalculationsForLowerLimitNormObserver.Dispose(); + waveHeightCalculationsForFactorizedLowerLimitNormObserver.Dispose(); + hydraulicBoundaryLocationsObserver.Dispose(); + components?.Dispose(); } @@ -125,11 +127,16 @@ private void CreateObservers() { - assessmentSectionObserver = new Observer(UpdateReferenceLineMapData) + referenceLineObserver = new Observer(UpdateReferenceLineMapData) { Observable = AssessmentSection }; + assessmentSectionObserver = new Observer(UpdateAssemblyResultsMapData) + { + Observable = new AssessmentSectionResultObserver(AssessmentSection) + }; + waterLevelCalculationsForFactorizedSignalingNormObserver = ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver( AssessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, UpdateHydraulicBoundaryLocationsMapData); waterLevelCalculationsForSignalingNormObserver = ObserverHelper.CreateHydraulicBoundaryLocationCalculationsObserver( @@ -160,6 +167,17 @@ SetAssemblyResultsMapData(); } + private void UpdateAssemblyResultsMapData() + { + SetAssemblyResultsMapData(); + assemblyResultsMapData.NotifyObservers(); + } + + private void SetAssemblyResultsMapData() + { + assemblyResultsMapData.Features = AssessmentSectionAssemblyMapDataFeaturesFactory.CreateCombinedFailureMechanismSectionAssemblyFeatures(AssessmentSection); + } + #region ReferenceLine MapData private void UpdateReferenceLineMapData() @@ -191,10 +209,5 @@ } #endregion - - private void SetAssemblyResultsMapData() - { - assemblyResultsMapData.Features = AssessmentSectionAssemblyMapDataFeaturesFactory.CreateCombinedFailureMechanismSectionAssemblyFeatures(AssessmentSection); - } } } \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionMapViewTest.cs =================================================================== diff -u -r5f7ae1dd177727ad2bb1a4bb9605f4264409059c -re5363d0a483288d365fc50dbe070fbbb81bbdb67 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionMapViewTest.cs (.../AssemblyResultPerSectionMapViewTest.cs) (revision 5f7ae1dd177727ad2bb1a4bb9605f4264409059c) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionMapViewTest.cs (.../AssemblyResultPerSectionMapViewTest.cs) (revision e5363d0a483288d365fc50dbe070fbbb81bbdb67) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2018. All rights reserved. +// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of Ringtoets. // @@ -39,6 +39,7 @@ using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.TestUtil; @@ -73,6 +74,7 @@ { // Setup AssessmentSection assessmentSection = CreateAssessmentSection(); + assessmentSection.ReferenceLine = new ReferenceLine(); // Call using (var view = new AssemblyResultPerSectionMapView(assessmentSection)) @@ -88,15 +90,32 @@ Assert.AreEqual(DockStyle.Fill, ((Control) view.Map).Dock); Assert.AreSame(assessmentSection, view.AssessmentSection); - AssertEmptyMapData(view.Map.Data); + MapDataCollection mapDataCollection = view.Map.Data; + Assert.AreEqual("Assemblagekaart", mapDataCollection.Name); + + List mapDataList = mapDataCollection.Collection.ToList(); + + Assert.AreEqual(3, mapDataList.Count); + + var assemblyResultsLineMapData = (MapLineData) mapDataList[assemblyResultsIndex]; + var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; + var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; + + CollectionAssert.IsEmpty(assemblyResultsLineMapData.Features); + CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); + Assert.AreEqual(1, referenceLineMapData.Features.Count()); + + Assert.AreEqual("Gecombineerd vakoordeel", assemblyResultsLineMapData.Name); + Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name); + Assert.AreEqual("Referentielijn", referenceLineMapData.Name); } } [Test] public void Constructor_AssessmentSectionWithBackgroundData_BackgroundDataSet() { // Setup - AssessmentSection assessmentSection = CreateAssessmentSection(); + AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine(); // Call using (var view = new AssemblyResultPerSectionMapView(assessmentSection)) @@ -110,6 +129,7 @@ public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup + var random = new Random(21); var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(new[] { @@ -131,7 +151,8 @@ AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator; CombinedFailureMechanismSectionAssembly[] failureMechanismSectionAssembly = { - CreateCombinedFailureMechanismSectionAssembly(assessmentSection) + CreateCombinedFailureMechanismSectionAssembly(assessmentSection, + random.NextEnumValue()) }; calculator.CombinedFailureMechanismSectionAssemblyOutput = failureMechanismSectionAssembly; @@ -155,7 +176,7 @@ MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); MapData referenceLineMapData = mapData.Collection.ElementAt(referenceLineIndex); - AssertReferenceLineMapData(referenceLine, referenceLineMapData); + AssertReferenceLineMapData(assessmentSection.ReferenceLine, referenceLineMapData); } } } @@ -167,7 +188,7 @@ { // Given var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0); - AssessmentSection assessmentSection = CreateAssessmentSection(); + AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation @@ -202,7 +223,7 @@ public void GivenViewWithHydraulicBoundaryLocationsDatabase_WhenChangingHydraulicBoundaryLocationsDataAndObserversNotified_ThenMapDataUpdated() { // Given - AssessmentSection assessmentSection = CreateAssessmentSection(); + AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { new HydraulicBoundaryLocation(1, "test1", 1.0, 2.0) @@ -240,13 +261,13 @@ { // Setup var referenceLine = new ReferenceLine(); - referenceLine.SetGeometry(new List + referenceLine.SetGeometry(new[] { new Point2D(1.0, 2.0), new Point2D(2.0, 1.0) }); - AssessmentSection assessmentSection = CreateAssessmentSection(); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); assessmentSection.ReferenceLine = referenceLine; using (var view = new AssemblyResultPerSectionMapView(assessmentSection)) @@ -255,6 +276,7 @@ var mocks = new MockRepository(); IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); + observers[assemblyResultsIndex].Expect(obs => obs.UpdateObserver()); observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); mocks.ReplayAll(); @@ -277,45 +299,142 @@ } } + [Test] + public void GivenViewWithAssemblyResults_WhenFailureMechanismNotifiesObserver_ThenAssemblyResultsRefreshed() + { + // Given + var random = new Random(21); + AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator; + calculator.CombinedFailureMechanismSectionAssemblyOutput = new[] + { + CreateCombinedFailureMechanismSectionAssembly(assessmentSection, + FailureMechanismSectionAssemblyCategoryGroup.IIIv) + }; + + using (var view = new AssemblyResultPerSectionMapView(assessmentSection)) + { + // Precondition + MapDataCollection mapData = view.Map.Data; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, mapData.Collection); + observers[assemblyResultsIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + IEnumerable expectedResults = + AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection, true); + + AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults, + assessmentSection.ReferenceLine, + mapData.Collection.ElementAt(assemblyResultsIndex)); + + // When + calculator.CombinedFailureMechanismSectionAssemblyOutput = new[] + { + CreateCombinedFailureMechanismSectionAssembly(assessmentSection, FailureMechanismSectionAssemblyCategoryGroup.Iv) + }; + IEnumerable failureMechanisms = assessmentSection.GetFailureMechanisms(); + failureMechanisms.ElementAt(random.Next(failureMechanisms.Count())).NotifyObservers(); + + // Then + expectedResults = AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection, true); + AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults, + assessmentSection.ReferenceLine, + mapData.Collection.ElementAt(assemblyResultsIndex)); + mocks.VerifyAll(); + } + } + } + + [Test] + public void GivenViewWithAssemblyResults_WhenAssessmentSectionNotifiesObserver_ThenAssemblyResultsRefreshed() + { + // Given + AssessmentSection assessmentSection = CreateAssessmentSectionWithReferenceLine(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssessmentSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyCalculator; + calculator.CombinedFailureMechanismSectionAssemblyOutput = new[] + { + CreateCombinedFailureMechanismSectionAssembly(assessmentSection, + FailureMechanismSectionAssemblyCategoryGroup.IIIv) + }; + + using (var view = new AssemblyResultPerSectionMapView(assessmentSection)) + { + // Precondition + MapDataCollection mapData = view.Map.Data; + + var mocks = new MockRepository(); + IObserver[] observers = AttachMapDataObservers(mocks, mapData.Collection); + observers[assemblyResultsIndex].Expect(obs => obs.UpdateObserver()); + observers[referenceLineIndex].Expect(obs => obs.UpdateObserver()); + mocks.ReplayAll(); + + IEnumerable expectedResults = + AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection, true); + + AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults, + assessmentSection.ReferenceLine, + mapData.Collection.ElementAt(assemblyResultsIndex)); + + // When + calculator.CombinedFailureMechanismSectionAssemblyOutput = new[] + { + CreateCombinedFailureMechanismSectionAssembly(assessmentSection, FailureMechanismSectionAssemblyCategoryGroup.Iv) + }; + assessmentSection.NotifyObservers(); + + // Then + expectedResults = AssessmentSectionAssemblyFactory.AssembleCombinedPerFailureMechanismSection(assessmentSection, true); + AssertCombinedFailureMechanismSectionAssemblyResultMapData(expectedResults, + assessmentSection.ReferenceLine, + mapData.Collection.ElementAt(assemblyResultsIndex)); + mocks.VerifyAll(); + } + } + } + private static AssessmentSection CreateAssessmentSection() { var random = new Random(21); - var assessmentSection = new AssessmentSection(random.NextEnumValue()); + return new AssessmentSection(random.NextEnumValue()); + } + + private static AssessmentSection CreateAssessmentSectionWithReferenceLine() + { + var referenceLine = new ReferenceLine(); + referenceLine.SetGeometry(new[] + { + new Point2D(1.0, 2.0), + new Point2D(2.0, 1.0) + }); + + AssessmentSection assessmentSection = CreateAssessmentSection(); + assessmentSection.ReferenceLine = referenceLine; + return assessmentSection; } - private static CombinedFailureMechanismSectionAssembly CreateCombinedFailureMechanismSectionAssembly(AssessmentSection assessmentSection) + private static CombinedFailureMechanismSectionAssembly CreateCombinedFailureMechanismSectionAssembly(AssessmentSection assessmentSection, + FailureMechanismSectionAssemblyCategoryGroup totalResult) { var random = new Random(37); return new CombinedFailureMechanismSectionAssembly(new CombinedAssemblyFailureMechanismSection(random.NextDouble(), random.NextDouble(), - random.NextEnumValue()), + totalResult), assessmentSection.GetFailureMechanisms() .Where(fm => fm.IsRelevant) .Select(fm => random.NextEnumValue()).ToArray()); } - private static void AssertEmptyMapData(MapDataCollection mapDataCollection) - { - Assert.AreEqual("Assemblagekaart", mapDataCollection.Name); - - List mapDataList = mapDataCollection.Collection.ToList(); - - Assert.AreEqual(3, mapDataList.Count); - - var assemblyResultsLineMapData = (MapLineData) mapDataList[assemblyResultsIndex]; - var hydraulicBoundaryLocationsMapData = (MapPointData) mapDataList[hydraulicBoundaryLocationsIndex]; - var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; - - CollectionAssert.IsEmpty(assemblyResultsLineMapData.Features); - CollectionAssert.IsEmpty(hydraulicBoundaryLocationsMapData.Features); - CollectionAssert.IsEmpty(referenceLineMapData.Features); - - Assert.AreEqual("Gecombineerd vakoordeel", assemblyResultsLineMapData.Name); - Assert.AreEqual("Hydraulische belastingen", hydraulicBoundaryLocationsMapData.Name); - Assert.AreEqual("Referentielijn", referenceLineMapData.Name); - } - private static void AssertReferenceLineMapData(ReferenceLine referenceLine, MapData referenceLineMapData) { MapDataTestHelper.AssertReferenceLineMapData(referenceLine, referenceLineMapData); @@ -378,12 +497,12 @@ var assemblyResultsObserver = mocks.StrictMock(); mapDataArray[assemblyResultsIndex].Attach(assemblyResultsObserver); - var referenceLineMapDataObserver = mocks.StrictMock(); - mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); - var hydraulicBoundaryLocationsMapDataObserver = mocks.StrictMock(); mapDataArray[hydraulicBoundaryLocationsIndex].Attach(hydraulicBoundaryLocationsMapDataObserver); + var referenceLineMapDataObserver = mocks.StrictMock(); + mapDataArray[referenceLineIndex].Attach(referenceLineMapDataObserver); + return new[] { assemblyResultsObserver,