Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionViewTest.cs =================================================================== diff -u -r3a6b8683163bfa83f5c62c1942d8e2e39316c888 -r9bf0fc986826a6ad2e2a812e0f502c567c544c59 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionViewTest.cs (.../AssemblyResultPerSectionViewTest.cs) (revision 3a6b8683163bfa83f5c62c1942d8e2e39316c888) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultPerSectionViewTest.cs (.../AssemblyResultPerSectionViewTest.cs) (revision 9bf0fc986826a6ad2e2a812e0f502c567c544c59) @@ -29,6 +29,7 @@ using NUnit.Extensions.Forms; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.HeightStructures.Data.TestUtil; using Ringtoets.Integration.Data; using Ringtoets.Integration.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -60,6 +61,7 @@ private const int duneErosionColumnIndex = 19; private const int technicalInnovationColumnIndex = 20; private const int expectedColumnCount = 21; + private const string assemblyResultOutdatedWarning = "Assemblageresultaat is verouderd. Druk op de \"Assemblageresultaat verversen\" knop om opnieuw te berekenen."; private Form testForm; @@ -113,13 +115,18 @@ var button = (Button) new ControlTester("RefreshAssemblyResultsButton").TheObject; Assert.AreEqual("Assemblageresultaat verversen", button.Text); - Assert.IsTrue(button.Enabled); + Assert.IsFalse(button.Enabled); ErrorProvider errorProvider = GetErrorProvider(view); TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.ErrorIcon.ToBitmap(), errorProvider.Icon.ToBitmap()); Assert.AreEqual(ErrorBlinkStyle.NeverBlink, errorProvider.BlinkStyle); - Assert.IsEmpty(errorProvider.GetError(view)); + Assert.IsEmpty(errorProvider.GetError(button)); + ErrorProvider warningProvider = GetWarningProvider(view); + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.warning.ToBitmap(), warningProvider.Icon.ToBitmap()); + Assert.AreEqual(ErrorBlinkStyle.NeverBlink, warningProvider.BlinkStyle); + Assert.IsEmpty(warningProvider.GetError(button)); + Assert.IsInstanceOf(view); Assert.IsInstanceOf(view); Assert.IsNull(view.Data); @@ -171,18 +178,19 @@ // Given using (ShowAssemblyResultPerSectionView()) { + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + buttonTester.Properties.Enabled = true; DataGridView dataGridView = GetDataGridView(); dataGridView.CellFormatting += (sender, args) => { - var row = (IHasColumnStateDefinitions)dataGridView.Rows[0].DataBoundItem; + var row = (IHasColumnStateDefinitions) dataGridView.Rows[0].DataBoundItem; DataGridViewColumnStateDefinition definition = row.ColumnStateDefinitions[sectionTotalAssemblyResultColumnIndex]; definition.ReadOnly = readOnly; definition.ErrorText = errorText; definition.Style = style; }; // When - ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); buttonTester.Click(); // Then @@ -194,14 +202,114 @@ } } + [Test] + public void GivenFormWithAssemblyResultPerSectionViewWithOutdatedContent_WhenRefreshingAssemblyResults_ThenRefreshButtonDisabledAndWarningCleared() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection)) + { + assessmentSection.NotifyObservers(); + + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Button button = buttonTester.Properties; + Assert.IsTrue(button.Enabled); + ErrorProvider warningProvider = GetWarningProvider(view); + Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button)); + + // When + buttonTester.Click(); + + // Then + Assert.IsFalse(button.Enabled); + Assert.IsEmpty(warningProvider.GetError(button)); + } + } + + [Test] + public void GivenFormWithAssemblyResultPerSectionView_WhenAssessmentSectionNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Button button = buttonTester.Properties; + Assert.IsFalse(button.Enabled); + ErrorProvider warningProvider = GetWarningProvider(view); + Assert.IsEmpty(warningProvider.GetError(button)); + + // When + assessmentSection.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button)); + } + } + + [Test] + public void GivenFormWithAssemblyResultPerSectionView_WhenFailureMechanismNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + + using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Button button = buttonTester.Properties; + Assert.IsFalse(button.Enabled); + ErrorProvider warningProvider = GetWarningProvider(view); + Assert.IsEmpty(warningProvider.GetError(button)); + + // When + assessmentSection.StabilityStoneCover.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button)); + } + } + + [Test] + public void GivenFormWithAssemblyResultPerSectionView_WhenCalculationNotifiesObservers_ThenRefreshButtonEnabledAndWarningSet() + { + // Given + var assessmentSection = new AssessmentSection(new Random(21).NextEnumValue()); + var calculation = new TestHeightStructuresCalculation(); + assessmentSection.HeightStructures.CalculationsGroup.Children.Add(calculation); + + using (AssemblyResultPerSectionView view = ShowAssemblyResultPerSectionView(assessmentSection)) + { + // Precondition + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + Button button = buttonTester.Properties; + Assert.IsFalse(button.Enabled); + ErrorProvider warningProvider = GetWarningProvider(view); + Assert.IsEmpty(warningProvider.GetError(button)); + + // When + calculation.NotifyObservers(); + + // Then + Assert.IsTrue(buttonTester.Properties.Enabled); + Assert.AreEqual(assemblyResultOutdatedWarning, warningProvider.GetError(button)); + } + } + private ButtonTester GetRefreshAssemblyResultButtonTester() { return new ButtonTester("RefreshAssemblyResultsButton", testForm); } private static DataGridView GetDataGridView() { - return (DataGridView)new ControlTester("dataGridView").TheObject; + return (DataGridView) new ControlTester("dataGridView").TheObject; } private static void AssertColumn(DataGridViewColumn column, string headerText) @@ -216,11 +324,18 @@ return TypeUtils.GetField(resultView, "errorProvider"); } + private static ErrorProvider GetWarningProvider(AssemblyResultPerSectionView resultControl) + { + return TypeUtils.GetField(resultControl, "warningProvider"); + } + private AssemblyResultPerSectionView ShowAssemblyResultPerSectionView() { - var random = new Random(21); - var assessmentSection = new AssessmentSection(random.NextEnumValue()); + return ShowAssemblyResultPerSectionView(new AssessmentSection(new Random(21).NextEnumValue())); + } + private AssemblyResultPerSectionView ShowAssemblyResultPerSectionView(AssessmentSection assessmentSection) + { var view = new AssemblyResultPerSectionView(assessmentSection); testForm.Controls.Add(view); testForm.Show();