Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs =================================================================== diff -u -rf9ef294839f02236f8d813b2220ceccc4c2bfc73 -rd02c462c07c2c5ca910feb8ad822968a7697423e --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision f9ef294839f02236f8d813b2220ceccc4c2bfc73) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismViewTest.cs (.../GrassCoverErosionInwardsFailureMechanismViewTest.cs) (revision d02c462c07c2c5ca910feb8ad822968a7697423e) @@ -140,7 +140,7 @@ IAssessmentSection assessmentSection = new AssessmentSectionStub(); // Call - using (var view = new GrassCoverErosionInwardsFailureMechanismView(new GrassCoverErosionInwardsFailureMechanism(), new AssessmentSectionStub())) + using (var view = new GrassCoverErosionInwardsFailureMechanismView(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection)) { // Assert MapDataTestHelper.AssertImageBasedMapData(assessmentSection.BackgroundData, view.Map.BackgroundMapData); Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.cs =================================================================== diff -u -rf4f91db0ee54785dd8dfea6309ddfe824cadda9b -rd02c462c07c2c5ca910feb8ad822968a7697423e --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.cs (.../HeightStructuresFailureMechanismView.cs) (revision f4f91db0ee54785dd8dfea6309ddfe824cadda9b) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismView.cs (.../HeightStructuresFailureMechanismView.cs) (revision d02c462c07c2c5ca910feb8ad822968a7697423e) @@ -36,6 +36,7 @@ using Ringtoets.Common.Forms.Factories; using Ringtoets.Common.Forms.Helpers; using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Forms.Factories; using HeightStructuresDataResources = Ringtoets.HeightStructures.Data.Properties.Resources; namespace Ringtoets.HeightStructures.Forms.Views @@ -45,16 +46,22 @@ /// public partial class HeightStructuresFailureMechanismView : UserControl, IMapView { - private readonly MapLineData referenceLineMapData; - private readonly MapPointData hydraulicBoundaryLocationsMapData; - private readonly MapLineData foreshoreProfilesMapData; - private readonly MapPointData structuresMapData; - private readonly MapLineData calculationsMapData; + private MapDataCollection mapDataCollection; + private MapLineData referenceLineMapData; + private MapPointData hydraulicBoundaryLocationsMapData; + private MapLineData foreshoreProfilesMapData; + private MapPointData structuresMapData; + private MapLineData calculationsMapData; - private readonly MapLineData sectionsMapData; - private readonly MapPointData sectionsStartPointMapData; - private readonly MapPointData sectionsEndPointMapData; + 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 hydraulicBoundaryLocationsObserver; @@ -74,6 +81,7 @@ private RecursiveObserver> calculationObserver; private RecursiveObserver foreshoreProfileObserver; private RecursiveObserver, HeightStructure> structureObserver; + private RecursiveObserver, HeightStructuresFailureMechanismSectionResult> sectionResultObserver; /// /// Creates a new instance of . @@ -101,31 +109,8 @@ CreateObservers(); - var mapDataCollection = new MapDataCollection(HeightStructuresDataResources.HeightStructuresFailureMechanism_DisplayName); - referenceLineMapData = RingtoetsMapDataFactory.CreateReferenceLineMapData(); - hydraulicBoundaryLocationsMapData = RingtoetsMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); - foreshoreProfilesMapData = RingtoetsMapDataFactory.CreateForeshoreProfileMapData(); - calculationsMapData = RingtoetsMapDataFactory.CreateCalculationsMapData(); - structuresMapData = RingtoetsMapDataFactory.CreateStructuresMapData(); - - MapDataCollection sectionsMapDataCollection = RingtoetsMapDataFactory.CreateSectionsMapDataCollection(); - sectionsMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsMapData(); - sectionsStartPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); - sectionsEndPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); - - mapDataCollection.Add(referenceLineMapData); - - sectionsMapDataCollection.Add(sectionsMapData); - sectionsMapDataCollection.Add(sectionsStartPointMapData); - sectionsMapDataCollection.Add(sectionsEndPointMapData); - mapDataCollection.Add(sectionsMapDataCollection); - - mapDataCollection.Add(hydraulicBoundaryLocationsMapData); - mapDataCollection.Add(foreshoreProfilesMapData); - mapDataCollection.Add(structuresMapData); - mapDataCollection.Add(calculationsMapData); - - SetMapDataFeatures(); + CreateMapData(); + SetAllMapDataFeatures(); ringtoetsMapControl.SetAllData(mapDataCollection, AssessmentSection.BackgroundData); } @@ -169,6 +154,7 @@ calculationObserver.Dispose(); structuresObserver.Dispose(); structureObserver.Dispose(); + sectionResultObserver.Dispose(); if (disposing) { @@ -178,13 +164,52 @@ base.Dispose(disposing); } + private void CreateMapData() + { + mapDataCollection = new MapDataCollection(HeightStructuresDataResources.HeightStructuresFailureMechanism_DisplayName); + referenceLineMapData = RingtoetsMapDataFactory.CreateReferenceLineMapData(); + hydraulicBoundaryLocationsMapData = RingtoetsMapDataFactory.CreateHydraulicBoundaryLocationsMapData(); + foreshoreProfilesMapData = RingtoetsMapDataFactory.CreateForeshoreProfileMapData(); + calculationsMapData = RingtoetsMapDataFactory.CreateCalculationsMapData(); + structuresMapData = RingtoetsMapDataFactory.CreateStructuresMapData(); + + MapDataCollection sectionsMapDataCollection = RingtoetsMapDataFactory.CreateSectionsMapDataCollection(); + sectionsMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsMapData(); + sectionsStartPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsStartPointMapData(); + sectionsEndPointMapData = RingtoetsMapDataFactory.CreateFailureMechanismSectionsEndPointMapData(); + + 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(structuresMapData); + mapDataCollection.Add(calculationsMapData); + } + private void CreateObservers() { - failureMechanismObserver = new Observer(UpdateSectionsMapData) + failureMechanismObserver = new Observer(UpdateFailureMechanismMapData) { Observable = FailureMechanism }; - assessmentSectionObserver = new Observer(UpdateReferenceLineMapData) + assessmentSectionObserver = new Observer(UpdateAssessmentSectionMapData) { Observable = AssessmentSection }; @@ -240,24 +265,54 @@ { Observable = FailureMechanism.HeightStructures }; + + sectionResultObserver = new RecursiveObserver, + HeightStructuresFailureMechanismSectionResult>(UpdateAssemblyMapData, sr => sr) + { + Observable = FailureMechanism.SectionResults + }; } - private void SetMapDataFeatures() + private void SetAllMapDataFeatures() { SetReferenceLineMapData(); SetSectionsMapData(); SetHydraulicBoundaryLocationsMapData(); SetForeshoreProfilesMapData(); SetStructuresMapData(); SetCalculationsMapData(); + SetAssemblyMapData(); } + #region Assembly MapData + + private void UpdateAssemblyMapData() + { + SetAssemblyMapData(); + simpleAssemblyMapData.NotifyObservers(); + detailedAssemblyMapData.NotifyObservers(); + tailorMadeAssemblyMapData.NotifyObservers(); + combinedAssemblyMapData.NotifyObservers(); + } + + private void SetAssemblyMapData() + { + simpleAssemblyMapData.Features = HeightStructuresAssemblyMapDataFeaturesFactory.CreateSimpleAssemblyFeatures(FailureMechanism); + detailedAssemblyMapData.Features = HeightStructuresAssemblyMapDataFeaturesFactory.CreateDetailedAssemblyFeatures(FailureMechanism, AssessmentSection); + tailorMadeAssemblyMapData.Features = HeightStructuresAssemblyMapDataFeaturesFactory.CreateTailorMadeAssemblyFeatures(FailureMechanism, AssessmentSection); + combinedAssemblyMapData.Features = HeightStructuresAssemblyMapDataFeaturesFactory.CreateCombinedAssemblyFeatures(FailureMechanism, AssessmentSection); + } + + #endregion + #region Calculations MapData private void UpdateCalculationsMapData() { SetCalculationsMapData(); calculationsMapData.NotifyObservers(); + + UpdateAssemblyMapData(); } private void SetCalculationsMapData() @@ -284,9 +339,9 @@ #endregion - #region ReferenceLine MapData + #region AssessmentSection MapData - private void UpdateReferenceLineMapData() + private void UpdateAssessmentSectionMapData() { SetReferenceLineMapData(); referenceLineMapData.NotifyObservers(); @@ -300,20 +355,21 @@ #endregion - #region Sections MapData + #region FailureMechanism MapData - private void UpdateSectionsMapData() + private void UpdateFailureMechanismMapData() { SetSectionsMapData(); sectionsMapData.NotifyObservers(); sectionsStartPointMapData.NotifyObservers(); sectionsEndPointMapData.NotifyObservers(); + + UpdateAssemblyMapData(); } private void SetSectionsMapData() { IEnumerable failureMechanismSections = FailureMechanism.Sections; - sectionsMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(failureMechanismSections); sectionsStartPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionStartPointFeatures(failureMechanismSections); sectionsEndPointMapData.Features = RingtoetsMapDataFeaturesFactory.CreateFailureMechanismSectionEndPointFeatures(failureMechanismSections); Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs =================================================================== diff -u -rf4f91db0ee54785dd8dfea6309ddfe824cadda9b -rd02c462c07c2c5ca910feb8ad822968a7697423e --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs (.../HeightStructuresFailureMechanismViewTest.cs) (revision f4f91db0ee54785dd8dfea6309ddfe824cadda9b) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/Views/HeightStructuresFailureMechanismViewTest.cs (.../HeightStructuresFailureMechanismViewTest.cs) (revision d02c462c07c2c5ca910feb8ad822968a7697423e) @@ -25,12 +25,17 @@ 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 Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +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; @@ -49,22 +54,32 @@ { private const int referenceLineIndex = 0; private const int sectionsCollectionIndex = 1; - private const int hydraulicBoundaryLocationsIndex = 2; - private const int foreshoreProfilesIndex = 3; - private const int structuresIndex = 4; - private const int calculationsIndex = 5; + private const int assemblyResultsIndex = 2; + private const int hydraulicBoundaryLocationsIndex = 3; + private const int foreshoreProfilesIndex = 4; + private const int structuresIndex = 5; + private const int calculationsIndex = 6; private const int sectionsIndex = 0; private const int sectionsStartPointIndex = 1; private const int sectionsEndPointIndex = 2; + private const int 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 foreshoreProfilesObserverIndex = 2; private const int structuresObserverIndex = 3; private const int calculationObserverIndex = 4; private const int sectionsObserverIndex = 5; private const int sectionsStartPointObserverIndex = 6; private const int sectionsEndPointObserverIndex = 7; + private const int simpleAssemblyObserverIndex = 8; + private const int detailedAssemblyObserverIndex = 9; + private const int tailorMadeAssemblyObserverIndex = 10; + private const int combinedAssemblyObserverIndex = 11; [Test] public void Constructor_FailureMechanismNull_ThrowsArgumentNullException() @@ -137,6 +152,8 @@ public void Constructor_WithAllData_DataUpdatedToCollectionOfFilledMapData() { // Setup + var random = new Random(39); + var calculationA = new StructuresCalculation { InputParameters = @@ -205,30 +222,52 @@ new HydraulicBoundaryLocation(1, "test", 1.0, 2.0) }); - // Call - using (var view = new HeightStructuresFailureMechanismView(failureMechanism, assessmentSection)) + var expectedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var expectedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) { - IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; - // Assert - MapDataCollection mapData = map.Data; - Assert.IsInstanceOf(mapData); + calculator.SimpleAssessmentAssemblyOutput = expectedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = expectedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = expectedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = expectedCombinedAssembly; - List mapDataList = mapData.Collection.ToList(); - Assert.AreEqual(6, mapDataList.Count); - MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); + // Call + using (var view = new HeightStructuresFailureMechanismView(failureMechanism, assessmentSection)) + { + IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; - 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)); + // Assert + MapDataCollection mapData = map.Data; + Assert.IsInstanceOf(mapData); - MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, mapDataList[hydraulicBoundaryLocationsIndex]); - MapDataTestHelper.AssertForeshoreProfilesMapData(failureMechanism.ForeshoreProfiles, mapDataList[foreshoreProfilesIndex]); + List mapDataList = mapData.Collection.ToList(); + Assert.AreEqual(7, mapDataList.Count); + MapDataTestHelper.AssertReferenceLineMapData(assessmentSection.ReferenceLine, mapDataList[referenceLineIndex]); - AssertCalculationsMapData( - failureMechanism.Calculations.Cast>(), - mapDataList[calculationsIndex]); + 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, + expectedDetailedAssembly, + expectedTailorMadeAssembly, + expectedCombinedAssembly, + (MapDataCollection) mapDataList[assemblyResultsIndex], + failureMechanism); + } } } @@ -263,7 +302,7 @@ }); assessmentSection.HydraulicBoundaryDatabase.Locations.NotifyObservers(); - // Then + // Then MapDataTestHelper.AssertHydraulicBoundaryLocationsMapData(assessmentSection, hydraulicBoundaryLocationsMapData); mocks.VerifyAll(); } @@ -369,6 +408,10 @@ 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 @@ -578,6 +621,10 @@ 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); @@ -627,6 +674,10 @@ 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); @@ -646,52 +697,220 @@ } [Test] - public void GivenViewWithCalculationData_WhenCalculationUpdatedAndNotified_ThenMapDataUpdated() + public void GivenViewWithAssemblyData_WhenFailureMechanismNotified_ThenMapDataUpdated() { // Given - var calculationA = new StructuresCalculation + var random = new Random(39); + var failureMechanism = new HeightStructuresFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) { - InputParameters = + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; + + using (var view = new HeightStructuresFailureMechanismView(failureMechanism, new AssessmentSectionStub())) { - HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 1.3, 2.3), - Structure = new TestHeightStructure(new Point2D(1.2, 2.3)) + IMapControl map = ((RingtoetsMapControl) 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, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + failureMechanism.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); } - }; + } + } + [Test] + public void GivenViewWithAssemblyData_WhenCalculationNotified_ThenMapDataUpdated() + { + // Given + var random = new Random(39); + var calculationA = new StructuresCalculation(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(calculationA); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); - using (var view = new HeightStructuresFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) { - IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; - var mocks = new MockRepository(); - IObserver[] observers = AttachMapDataObservers(mocks, map.Data.Collection); - observers[calculationObserverIndex].Expect(obs => obs.UpdateObserver()); - mocks.ReplayAll(); + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; - var calculationMapData = (MapLineData) map.Data.Collection.ElementAt(calculationsIndex); + using (var view = new HeightStructuresFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RingtoetsMapControl) view.Controls[0]).MapControl; - // Precondition - AssertCalculationsMapData(failureMechanism.Calculations.Cast>(), - calculationMapData); + 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(); - // When - calculationA.Name = "new name"; - calculationA.NotifyObservers(); + // Precondition + var assemblyMapData = (MapDataCollection) map.Data.Collection.ElementAt(assemblyResultsIndex); + MapDataTestHelper.AssertAssemblyMapDataCollection(originalSimpleAssembly, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); - // Then - AssertCalculationsMapData(failureMechanism.Calculations.Cast>(), calculationMapData); - mocks.VerifyAll(); + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + calculationA.NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } } } [Test] - public void UpdateObserver_DataUpdated_MapLayersSameOrder() + public void GivenViewWithAssemblyData_WhenFailureMechanismSectionResultNotified_ThenMapDataUpdated() { + // Given + var random = new Random(39); + var failureMechanism = new HeightStructuresFailureMechanism(); + FailureMechanismTestHelper.AddSections(failureMechanism, random.Next(1, 10)); + + var originalSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var originalCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + calculator.SimpleAssessmentAssemblyOutput = originalSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = originalDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = originalTailorMadeAssembly; + calculator.CombinedAssemblyOutput = originalCombinedAssembly; + + using (var view = new HeightStructuresFailureMechanismView(failureMechanism, new AssessmentSectionStub())) + { + IMapControl map = ((RingtoetsMapControl) 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, + originalDetailedAssembly, + originalTailorMadeAssembly, + originalCombinedAssembly, + assemblyMapData, + failureMechanism); + + // When + var updatedSimpleAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedDetailedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedTailorMadeAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + var updatedCombinedAssembly = new FailureMechanismSectionAssembly(random.NextDouble(), random.NextEnumValue()); + calculator.SimpleAssessmentAssemblyOutput = updatedSimpleAssembly; + calculator.DetailedAssessmentAssemblyOutput = updatedDetailedAssembly; + calculator.TailorMadeAssessmentAssemblyOutput = updatedTailorMadeAssembly; + calculator.CombinedAssemblyOutput = updatedCombinedAssembly; + failureMechanism.SectionResults.First().NotifyObservers(); + + // Then + MapDataTestHelper.AssertAssemblyMapDataCollection(updatedSimpleAssembly, + updatedDetailedAssembly, + updatedTailorMadeAssembly, + updatedCombinedAssembly, + assemblyMapData, + failureMechanism); + mocks.VerifyAll(); + } + } + } + + [Test] + public void NotifyObservers_DataUpdated_MapLayersSameOrder() + { // Setup - const int updatedReferenceLineLayerIndex = referenceLineIndex + 5; + const int updatedReferenceLineLayerIndex = referenceLineIndex + 6; const int updatedSectionCollectionIndex = sectionsCollectionIndex - 1; + const int updatedAssemblyResultsCollectionIndex = assemblyResultsIndex - 1; const int updatedHydraulicLocationsLayerIndex = hydraulicBoundaryLocationsIndex - 1; const int updatedForeshoreProfilesLayerIndex = foreshoreProfilesIndex - 1; const int updatedStructuresLayerIndex = structuresIndex - 1; @@ -718,6 +937,9 @@ var sectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; 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); @@ -749,6 +971,9 @@ var actualSectionsData = (MapDataCollection) mapDataList[updatedSectionCollectionIndex]; 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); @@ -793,7 +1018,7 @@ List mapDataList = mapDataCollection.Collection.ToList(); - Assert.AreEqual(6, mapDataList.Count); + Assert.AreEqual(7, mapDataList.Count); var referenceLineMapData = (MapLineData) mapDataList[referenceLineIndex]; var foreshoreProfilesMapData = (MapLineData) mapDataList[foreshoreProfilesIndex]; @@ -829,6 +1054,26 @@ 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); } /// @@ -867,6 +1112,19 @@ 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, @@ -876,7 +1134,11 @@ calculationsMapDataObserver, sectionsMapDataObserver, sectionsStartPointMapDataObserver, - sectionsEndPointMapDataObserver + sectionsEndPointMapDataObserver, + simpleAssemblyMapDataObserver, + detailedAssemblyMapDataObserver, + tailorMadeAssemblyMapDataObserver, + combinedAssemblyMapDataObserver }; } }