Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs =================================================================== diff -u -r60f07b55583942fd5e83e9f3dc36f71810eaf16e -re98a0f7266a2f152b8411c0b2c876ab2fe0464d1 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs (.../GrassCoverErosionInwardsCalculationsView.cs) (revision 60f07b55583942fd5e83e9f3dc36f71810eaf16e) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsCalculationsView.cs (.../GrassCoverErosionInwardsCalculationsView.cs) (revision e98a0f7266a2f152b8411c0b2c876ab2fe0464d1) @@ -50,14 +50,14 @@ { private const int selectableHydraulicBoundaryLocationColumnIndex = 1; private const int selectableDikeProfileColumnIndex = 2; + private readonly IAssessmentSection assessmentSection; + private readonly GrassCoverErosionInwardsFailureMechanism failureMechanism; private Observer failureMechanismObserver; private Observer hydraulicBoundaryLocationsObserver; private Observer dikeProfilesObserver; private RecursiveObserver inputObserver; private RecursiveObserver calculationScenarioObserver; private RecursiveObserver calculationGroupObserver; - private readonly IAssessmentSection assessmentSection; - private readonly GrassCoverErosionInwardsFailureMechanism failureMechanism; private CalculationGroup calculationGroup; @@ -253,8 +253,12 @@ { Observable = assessmentSection.HydraulicBoundaryDatabase.Locations }; - dikeProfilesObserver = new Observer(UpdateDikeProfilesColumn) + dikeProfilesObserver = new Observer(() => { + UpdateDikeProfilesColumn(); + UpdateGenerateCalculationsButtonState(); + }) + { Observable = failureMechanism.DikeProfiles }; @@ -481,7 +485,6 @@ private void OnFailureMechanismUpdate() { UpdateSectionsListBox(); - UpdateGenerateCalculationsButtonState(); } private void UpdateSectionsListBox() Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs =================================================================== diff -u -r1f9e425e9d128b1356093d14fa2839b492dc12a4 -re98a0f7266a2f152b8411c0b2c876ab2fe0464d1 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs (.../GrassCoverErosionInwardsCalculationRowTest.cs) (revision 1f9e425e9d128b1356093d14fa2839b492dc12a4) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationRowTest.cs (.../GrassCoverErosionInwardsCalculationRowTest.cs) (revision e98a0f7266a2f152b8411c0b2c876ab2fe0464d1) @@ -256,18 +256,18 @@ } [Test] - [TestCase(BreakWaterType.Wall)] - [TestCase(BreakWaterType.Caisson)] - [TestCase(BreakWaterType.Dam)] - public void BreakWaterType_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged(BreakWaterType breakWaterType) + [TestCase(BreakWaterType.Wall, BreakWaterType.Dam)] + [TestCase(BreakWaterType.Caisson, BreakWaterType.Wall)] + [TestCase(BreakWaterType.Dam, BreakWaterType.Caisson)] + public void BreakWaterType_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged(BreakWaterType breakWaterType, BreakWaterType oldBreakWaterType) { // Setup BreakWaterType newValue = breakWaterType; var calculation = new GrassCoverErosionInwardsCalculationScenario(); // This step is necessary because setting the same value would not change the row state. - calculation.InputParameters.BreakWater.Type = (BreakWaterType) 4; + calculation.InputParameters.BreakWater.Type = oldBreakWaterType; // Call & Assert SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.BreakWaterType = newValue, calculation); @@ -280,7 +280,7 @@ public void BreakWaterType_ChangeToEqualValue_NoNotificationsOutputNotCleared(BreakWaterType breakWaterType) { // Setup - var oldValue = breakWaterType; + BreakWaterType oldValue = breakWaterType; // Call AssertPropertyNotChanged( Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs =================================================================== diff -u -r60f07b55583942fd5e83e9f3dc36f71810eaf16e -re98a0f7266a2f152b8411c0b2c876ab2fe0464d1 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs (.../GrassCoverErosionInwardsCalculationsViewTest.cs) (revision 60f07b55583942fd5e83e9f3dc36f71810eaf16e) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsCalculationsViewTest.cs (.../GrassCoverErosionInwardsCalculationsViewTest.cs) (revision e98a0f7266a2f152b8411c0b2c876ab2fe0464d1) @@ -232,7 +232,51 @@ mocks.VerifyAll(); } + [Test] + public void CalculationsView_ChangingDikeProfiles_ButtonCorrectState() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + + mocks.ReplayAll(); + + ConfigureHydraulicBoundaryDatabase(assessmentSection); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var calculationsView = ShowCalculationsView(ConfigureCalculationGroup(failureMechanism, assessmentSection), failureMechanism, assessmentSection); + + // Precondition + var button = (Button) calculationsView.Controls.Find("buttonGenerateCalculations", true)[0]; + Assert.IsFalse(button.Enabled); + + var failureMechanismSection1 = new FailureMechanismSection("Section 1", new[] + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }); + + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + failureMechanismSection1 + }); + + failureMechanism.DikeProfiles.AddRange(new List + { + DikeProfileTestFactory.CreateDikeProfile(new Point2D(0.0, 0.0), "profiel 1") + }, string.Empty); + + // Call + failureMechanism.DikeProfiles.NotifyObservers(); + + // Assert + Assert.IsTrue(button.Enabled); + + mocks.VerifyAll(); + } + + [Test] public void FailureMechanism_FailureMechanismWithSections_SectionsListBoxCorrectlyInitialized() { // Setup @@ -820,7 +864,7 @@ }, InputParameters = { - DikeProfile = failureMechanism.DikeProfiles.First(), + DikeProfile = failureMechanism.DikeProfiles.FirstOrDefault(), HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(), DikeHeight = (RoundedDouble) 1.1, Orientation = (RoundedDouble) 2.2, @@ -853,7 +897,7 @@ }, InputParameters = { - DikeProfile = failureMechanism.DikeProfiles.Last(), + DikeProfile = failureMechanism.DikeProfiles.LastOrDefault(), HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.Last(), DikeHeight = (RoundedDouble) 1.1, Orientation = (RoundedDouble) 2.2,