Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.Designer.cs =================================================================== diff -u -r90c590080ff1a02036f608ea498f696625e11f6b -r0a1e00c14da142df178d43f87af86906f170842b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.Designer.cs (.../AssemblyResultTotalView.Designer.cs) (revision 90c590080ff1a02036f608ea498f696625e11f6b) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.Designer.cs (.../AssemblyResultTotalView.Designer.cs) (revision 0a1e00c14da142df178d43f87af86906f170842b) @@ -68,6 +68,7 @@ // this.RefreshAssemblyResultsButton.AutoSize = true; this.RefreshAssemblyResultsButton.Dock = System.Windows.Forms.DockStyle.Left; + this.RefreshAssemblyResultsButton.Enabled = false; this.RefreshAssemblyResultsButton.Location = new System.Drawing.Point(5, 5); this.RefreshAssemblyResultsButton.Name = "RefreshAssemblyResultsButton"; this.RefreshAssemblyResultsButton.Size = new System.Drawing.Size(164, 25); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs =================================================================== diff -u -re6dce9f10ba6b2e89fa58977a50fb7e4c9ceb647 -r0a1e00c14da142df178d43f87af86906f170842b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision e6dce9f10ba6b2e89fa58977a50fb7e4c9ceb647) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 0a1e00c14da142df178d43f87af86906f170842b) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; +using Core.Common.Base; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.Util.Extensions; @@ -35,6 +36,7 @@ using Ringtoets.Integration.Data.Assembly; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.AssemblyFactories; +using Ringtoets.Integration.Forms.Observers; using Ringtoets.Integration.Forms.Properties; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.Piping.Data; @@ -52,6 +54,7 @@ public partial class AssemblyResultTotalView : UserControl, IView { private IEnumerable assemblyResultRows; + private readonly Observer assessmentSectionResultObserver; /// /// Creates a new instance of . @@ -69,8 +72,21 @@ AssessmentSection = assessmentSection; InitializeComponent(); + + assessmentSectionResultObserver = new Observer(EnableRefreshButton) + { + Observable = new AssessmentSectionResultObserver(assessmentSection) + }; } + private void EnableRefreshButton() + { + if (!RefreshAssemblyResultsButton.Enabled) + { + RefreshAssemblyResultsButton.Enabled = true; + } + } + /// /// Gets the the view belongs to. /// @@ -95,6 +111,7 @@ if (disposing) { components?.Dispose(); + assessmentSectionResultObserver.Dispose(); } base.Dispose(disposing); @@ -154,6 +171,7 @@ private void RefreshAssemblyResults_Click(object sender, EventArgs e) { + RefreshAssemblyResultsButton.Enabled = false; assemblyResultRows.ForEachElementDo(row => row.Update()); dataGridViewControl.RefreshDataGridView(); UpdateAssemblyResultControls(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Observers/AssessmentSectionResultObserverTest.cs =================================================================== diff -u -r0d878b05e84da0ad81affc99619fd4a0722d0629 -r0a1e00c14da142df178d43f87af86906f170842b --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Observers/AssessmentSectionResultObserverTest.cs (.../AssessmentSectionResultObserverTest.cs) (revision 0d878b05e84da0ad81affc99619fd4a0722d0629) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Observers/AssessmentSectionResultObserverTest.cs (.../AssessmentSectionResultObserverTest.cs) (revision 0a1e00c14da142df178d43f87af86906f170842b) @@ -21,6 +21,7 @@ using System; using Core.Common.Base; +using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.ClosingStructures.Data.TestUtil; @@ -55,7 +56,7 @@ public void Constructor_WithAssessmentSection_ExpectedProperties() { // Call - using (var resultObserver = new AssessmentSectionResultObserver(new AssessmentSection(AssessmentSectionComposition.Dike))) + using (var resultObserver = new AssessmentSectionResultObserver(new AssessmentSection(new Random(21).NextEnumValue()))) { // Assert Assert.IsInstanceOf(resultObserver); @@ -67,7 +68,7 @@ public void GivenAssessmentSectionResultObserver_WhenAssessmentSectionNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.DikeAndDune); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -90,7 +91,7 @@ public void GivenAssessmentSectionResultObserver_WhenClosingStructuresCalculationNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); var calculation = new TestClosingStructuresCalculation(); assessmentSection.ClosingStructures.CalculationsGroup.Children.Add(calculation); @@ -115,7 +116,7 @@ public void GivenAssessmentSectionResultObserver_WhenDuneErosionFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -138,7 +139,7 @@ public void GivenAssessmentSectionResultObserver_WhenGrassCoverErosionInwardsCalculationNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); var calculation = new GrassCoverErosionInwardsCalculation(); assessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(calculation); @@ -163,7 +164,7 @@ public void GivenAssessmentSectionResultObserver_WhenGrassCoverErosionOutwardsFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -186,7 +187,7 @@ public void GivenAssessmentSectionResultObserver_WhenHeightStructuresCalculationNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); var calculation = new TestHeightStructuresCalculation(); assessmentSection.HeightStructures.CalculationsGroup.Children.Add(calculation); @@ -211,7 +212,7 @@ public void GivenAssessmentSectionResultObserver_WhenMacroStabilityInwardsCalculationScenarioNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput(); assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation); @@ -237,7 +238,7 @@ public void GivenAssessmentSectionResultObserver_WhenPipingCalculationScenarioNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); PipingCalculationScenario calculation = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenarioWithInvalidInput(); assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation); @@ -262,7 +263,7 @@ public void GivenAssessmentSectionResultObserver_WhenStabilityPointStructuresCalculationNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); var calculation = new TestStabilityPointStructuresCalculation(); assessmentSection.StabilityPointStructures.CalculationsGroup.Children.Add(calculation); @@ -287,7 +288,7 @@ public void GivenAssessmentSectionResultObserver_WhenStabilityStoneCoverFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -310,7 +311,7 @@ public void GivenAssessmentSectionResultObserver_WhenWaveImpactAsphaltCoverFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -333,7 +334,7 @@ public void GivenAssessmentSectionResultObserver_WhenGrassCoverSlipOffInwardsFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -356,7 +357,7 @@ public void GivenAssessmentSectionResultObserver_WhenGrassCoverSlipOffOutwardsFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -379,7 +380,7 @@ public void GivenAssessmentSectionResultObserver_WhenMacroStabilityOutwardsFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -402,7 +403,7 @@ public void GivenAssessmentSectionResultObserver_WhenMicrostabilityFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -425,7 +426,7 @@ public void GivenAssessmentSectionResultObserver_WhenPipingStructureFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -448,7 +449,7 @@ public void GivenAssessmentSectionResultObserver_WhenStrengthStabilityLengthwiseConstructionFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -471,7 +472,7 @@ public void GivenAssessmentSectionResultObserver_WhenTechnicalInnovationFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { @@ -494,7 +495,7 @@ public void GivenAssessmentSectionResultObserver_WhenWaterPressureAsphaltCoverFailureMechanismNotified_ThenAssessmentSectionResultObserverObserversNotified() { // Given - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection)) { Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs =================================================================== diff -u -r9ad47a5528cc7345846eb091d5f374ffc7c9ff0a -r0a1e00c14da142df178d43f87af86906f170842b --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 9ad47a5528cc7345846eb091d5f374ffc7c9ff0a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 0a1e00c14da142df178d43f87af86906f170842b) @@ -43,6 +43,7 @@ using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.HeightStructures.Data; +using Ringtoets.HeightStructures.Data.TestUtil; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Forms.Controls; @@ -117,9 +118,9 @@ // Assert Assert.AreEqual(3, view.Controls.Count); - var button = (Button) new ControlTester("RefreshAssemblyResultsButton").TheObject; + Button button = GetRefreshAssemblyResultButtonTester().Properties; Assert.AreEqual("Assemblageresultaat verversen", button.Text); - Assert.IsTrue(button.Enabled); + Assert.IsFalse(button.Enabled); var groupBox = (GroupBox) new ControlTester("assemblyResultGroupBox").TheObject; Assert.AreEqual(1, groupBox.Controls.Count); @@ -133,9 +134,9 @@ var totalResultLabel = (Label) tableLayOutPanel.GetControlFromPosition(0, 0); Assert.AreEqual("Totaal", totalResultLabel.Text); - var failureMechanismsWithProbabilityLabel = (Label)tableLayOutPanel.GetControlFromPosition(0, 1); + var failureMechanismsWithProbabilityLabel = (Label) tableLayOutPanel.GetControlFromPosition(0, 1); Assert.AreEqual("Groepen 1 en 2", failureMechanismsWithProbabilityLabel.Text); - var failureMechanismsWithoutProbablityLabel = (Label)tableLayOutPanel.GetControlFromPosition(0, 2); + var failureMechanismsWithoutProbablityLabel = (Label) tableLayOutPanel.GetControlFromPosition(0, 2); Assert.AreEqual("Groepen 3 en 4", failureMechanismsWithoutProbablityLabel.Text); Assert.IsInstanceOf(tableLayOutPanel.GetControlFromPosition(1, 0)); Assert.IsInstanceOf(tableLayOutPanel.GetControlFromPosition(1, 1)); @@ -224,6 +225,8 @@ using (new AssemblyToolCalculatorFactoryConfig()) using (ShowAssemblyResultTotalView()) { + GetRefreshAssemblyResultButtonTester().Properties.Enabled = true; + // Precondition AssertAssessmentSectionAssemblyCategoryGroupControl(totalControlName, "C"); AssertAssessmentSectionAssemblyControl(failureMechanismsWithProbabilityControlName, "D", "1/1"); @@ -252,6 +255,8 @@ using (new AssemblyToolCalculatorFactoryConfig()) using (ShowAssemblyResultTotalView()) { + GetRefreshAssemblyResultButtonTester().Properties.Enabled = true; + // Precondition AssertAssessmentSectionAssemblyCategoryGroupControl(totalControlName, "C"); AssertAssessmentSectionAssemblyControl(failureMechanismsWithProbabilityControlName, "D", "1/1"); @@ -283,6 +288,8 @@ using (ShowAssemblyResultTotalView()) { + GetRefreshAssemblyResultButtonTester().Properties.Enabled = true; + // Precondition AssertAssessmentSectionAssemblyWithoutProbabilityControlWithError(totalControlName); AssertAssessmentSectionAssemblyWithProbabilityControlWithError(failureMechanismsWithProbabilityControlName); @@ -318,6 +325,8 @@ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator; + GetRefreshAssemblyResultButtonTester().Properties.Enabled = true; + var invalidated = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Invalidated += (sender, args) => invalidated = true; @@ -353,6 +362,7 @@ // Given using (ShowAssemblyResultTotalView()) { + GetRefreshAssemblyResultButtonTester().Properties.Enabled = true; DataGridView dataGridView = GetDataGridView(); dataGridView.CellFormatting += (sender, args) => { @@ -376,13 +386,99 @@ } } + [Test] + public void GivenFormWithAssemblyResultTotalViewWithOutdatedContent_WhenRefreshingAssemblyResults_ThenRefreshButtonDisabled() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (ShowAssemblyResultTotalView(assessmentSection)) + { + assessmentSection.NotifyObservers(); + + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Assert.IsTrue(buttonTester.Properties.Enabled); + + // When + buttonTester.Click(); + + // Then + Assert.IsFalse(buttonTester.Properties.Enabled); + } + } + + [Test] + public void GivenFormWithAssemblyResultTotalView_WhenAssessmentSectionNotifiesObservers_ThenRefreshButtonEnabled() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (ShowAssemblyResultTotalView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Assert.IsFalse(buttonTester.Properties.Enabled); + + // When + assessmentSection.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + } + } + + [Test] + public void GivenFormWithAssemblyResultTotalView_WhenFailureMechanismNotifiesObservers_ThenRefreshButtonEnabled() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (ShowAssemblyResultTotalView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Assert.IsFalse(buttonTester.Properties.Enabled); + + // When + assessmentSection.StabilityStoneCover.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + } + } + + [Test] + public void GivenFormWithAssemblyResultTotalView_WhenCalculationNotifiesObservers_ThenRefreshButtonEnabled() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + var calculation = new TestHeightStructuresCalculation(); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(calculation); + + using (ShowAssemblyResultTotalView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Assert.IsFalse(buttonTester.Properties.Enabled); + + // When + calculation.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + } + } + #region View test helpers private AssemblyResultTotalView ShowAssemblyResultTotalView() { - var random = new Random(21); - var assessmentSection = new AssessmentSection(random.NextEnumValue()); + return ShowAssemblyResultTotalView(new AssessmentSection(new Random(21).NextEnumValue())); + } + private AssemblyResultTotalView ShowAssemblyResultTotalView(AssessmentSection assessmentSection) + { var view = new AssemblyResultTotalView(assessmentSection); testForm.Controls.Add(view); testForm.Show();