Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultControl.cs =================================================================== diff -u -r1ed4c3d0bf61e04b9a3069977c76c183b2cc072a -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultControl.cs (.../AssemblyResultControl.cs) (revision 1ed4c3d0bf61e04b9a3069977c76c183b2cc072a) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultControl.cs (.../AssemblyResultControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -26,7 +26,7 @@ namespace Ringtoets.Common.Forms.Controls { /// - /// Custom base control to display an assembly result. + /// Base control to display an assembly result. /// public abstract partial class AssemblyResultControl : UserControl { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultWithProbabilityControl.cs =================================================================== diff -u -r1ed4c3d0bf61e04b9a3069977c76c183b2cc072a -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultWithProbabilityControl.cs (.../AssemblyResultWithProbabilityControl.cs) (revision 1ed4c3d0bf61e04b9a3069977c76c183b2cc072a) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/AssemblyResultWithProbabilityControl.cs (.../AssemblyResultWithProbabilityControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -24,7 +24,7 @@ namespace Ringtoets.Common.Forms.Controls { /// - /// Custom control to display an assembly result with probability. + /// Control to display an assembly result with probability. /// public abstract partial class AssemblyResultWithProbabilityControl : AssemblyResultControl { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyCategoryGroupControl.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyCategoryGroupControl.cs (.../FailureMechanismAssemblyCategoryGroupControl.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyCategoryGroupControl.cs (.../FailureMechanismAssemblyCategoryGroupControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -19,21 +19,27 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.ComponentModel; using Core.Common.Util; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Forms.Helpers; namespace Ringtoets.Common.Forms.Controls { /// - /// Custom control to display a . + /// Control to display a . /// public class FailureMechanismAssemblyCategoryGroupControl : AssemblyResultControl { /// /// Set the value of on the control. /// /// The to set on the control. + /// Thrown when + /// has an invalid value for . + /// Thrown when + /// is not supported. public void SetAssemblyResult(FailureMechanismAssemblyCategoryGroup result) { GroupLabel.Text = new EnumDisplayWrapper(result).DisplayName; Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyControl.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyControl.cs (.../FailureMechanismAssemblyControl.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Controls/FailureMechanismAssemblyControl.cs (.../FailureMechanismAssemblyControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.ComponentModel; using Core.Common.Util; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Forms.Helpers; @@ -28,7 +29,7 @@ namespace Ringtoets.Common.Forms.Controls { /// - /// Custom control to display a . + /// Control to display a . /// public class FailureMechanismAssemblyControl : AssemblyResultWithProbabilityControl { @@ -37,6 +38,10 @@ /// /// The to set on the control. /// Thrown when is null. + /// Thrown when + /// has an invalid value for . + /// Thrown when + /// has a category that is not supported. public void SetAssemblyResult(FailureMechanismAssembly result) { if (result == null) Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/AssemblyCategoryGroupColorHelper.cs =================================================================== diff -u -r9ce0ef2c7cbc8036c659b0a5f7aee3d6b2b44576 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/AssemblyCategoryGroupColorHelper.cs (.../AssemblyCategoryGroupColorHelper.cs) (revision 9ce0ef2c7cbc8036c659b0a5f7aee3d6b2b44576) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Helpers/AssemblyCategoryGroupColorHelper.cs (.../AssemblyCategoryGroupColorHelper.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -117,7 +117,7 @@ /// The category group to get the color for. /// The corresponding to the given category group. /// Thrown when - /// has an invalid value for . + /// has an invalid value for . /// Thrown when /// is not supported. public static Color GetFailureMechanismAssemblyCategoryGroupColor(FailureMechanismAssemblyCategoryGroup assemblyCategoryGroup) Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs =================================================================== diff -u -r1ed4c3d0bf61e04b9a3069977c76c183b2cc072a -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 1ed4c3d0bf61e04b9a3069977c76c183b2cc072a) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -21,12 +21,14 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.Util.Extensions; +using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Controls; @@ -155,6 +157,10 @@ /// /// Thrown when the assembly result /// could not be created. + /// Thrown when the result + /// has an invalid value for . + /// Thrown when the result has a value for + /// that is not supported. protected abstract void UpdateAssemblyResultControl(); /// Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultControlTest.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultControlTest.cs (.../AssemblyResultControlTest.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultControlTest.cs (.../AssemblyResultControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -59,7 +59,7 @@ Assert.AreEqual(DockStyle.Fill, groupLabel.Dock); Assert.AreEqual(new Padding(5, 0, 5, 0), groupLabel.Padding); - var errorProvider = TypeUtils.GetField(resultControl, "errorProvider"); + ErrorProvider errorProvider = GetErrorProvider(resultControl); TestHelper.AssertImagesAreEqual(Resources.ErrorIcon.ToBitmap(), errorProvider.Icon.ToBitmap()); Assert.AreEqual(ErrorBlinkStyle.NeverBlink, errorProvider.BlinkStyle); Assert.IsEmpty(errorProvider.GetError(resultControl)); @@ -133,11 +133,14 @@ // Setup using (var resultControl = new TestAssemblyResultControl()) { + Control groupLabel = GetGroupPanel(resultControl).GetControlFromPosition(0, 0); + groupLabel.Text = "abcd"; + groupLabel.BackColor = Color.Yellow; + // Call resultControl.ClearData(); // Assert - Control groupLabel = GetGroupPanel(resultControl).GetControlFromPosition(0, 0); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultWithProbabilityControlTest.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultWithProbabilityControlTest.cs (.../AssemblyResultWithProbabilityControlTest.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/AssemblyResultWithProbabilityControlTest.cs (.../AssemblyResultWithProbabilityControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -33,8 +33,9 @@ [Test] public void DefaultConstructor_ExpectedValues() { - // Setup & Call + // Setup using (var form = new Form()) + // Call using (var resultControl = new TestAssemblyResultWithProbabilityControl()) { form.Controls.Add(resultControl); @@ -73,12 +74,16 @@ // Setup using (var resultControl = new TestAssemblyResultWithProbabilityControl()) { + Control groupLabel = GetGroupPanel(resultControl).GetControlFromPosition(0, 0); + Control probabilityLabel = GetProbabilityPanel(resultControl).GetControlFromPosition(0, 0); + groupLabel.Text = "abcd"; + groupLabel.BackColor = Color.Yellow; + probabilityLabel.Text = "1/245"; + // Call resultControl.ClearData(); // Assert - Control groupLabel = GetGroupPanel(resultControl).GetControlFromPosition(0, 0); - Control probabilityLabel = GetProbabilityPanel(resultControl).GetControlFromPosition(0, 0); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); Assert.AreEqual("-", probabilityLabel.Text); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyCategoryGroupControlTest.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyCategoryGroupControlTest.cs (.../FailureMechanismAssemblyCategoryGroupControlTest.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyCategoryGroupControlTest.cs (.../FailureMechanismAssemblyCategoryGroupControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -60,29 +60,42 @@ // Assert BorderedLabel groupLabel = GetGroupLabel(resultControl); - Assert.AreEqual(new EnumDisplayWrapper(result).DisplayName, - groupLabel.Text); - Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetFailureMechanismAssemblyCategoryGroupColor(result), - groupLabel.BackColor); + AssertGroupLabel(result, groupLabel); } } [Test] public void ClearData_Always_ClearsDataOnControl() { // Setup + var random = new Random(39); + using (var resultControl = new FailureMechanismAssemblyCategoryGroupControl()) { + var result = random.NextEnumValue(); + resultControl.SetAssemblyResult(result); + + // Precondition + BorderedLabel groupLabel = GetGroupLabel(resultControl); + AssertGroupLabel(result, groupLabel); + // Call resultControl.ClearData(); // Assert - BorderedLabel groupLabel = GetGroupLabel(resultControl); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); } } + private static void AssertGroupLabel(FailureMechanismAssemblyCategoryGroup result, BorderedLabel groupLabel) + { + Assert.AreEqual(new EnumDisplayWrapper(result).DisplayName, + groupLabel.Text); + Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetFailureMechanismAssemblyCategoryGroupColor(result), + groupLabel.BackColor); + } + private static BorderedLabel GetGroupLabel(FailureMechanismAssemblyCategoryGroupControl resultControl) { return (BorderedLabel) ((TableLayoutPanel) resultControl.Controls["GroupPanel"]).GetControlFromPosition(0, 0); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyControlTest.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyControlTest.cs (.../FailureMechanismAssemblyControlTest.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Controls/FailureMechanismAssemblyControlTest.cs (.../FailureMechanismAssemblyControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -76,37 +76,56 @@ resultControl.SetAssemblyResult(result); // Assert - Control groupLabel = GetGroupLabel(resultControl); - Control probabilityLabel = GetProbabilityLabel(resultControl); + BorderedLabel groupLabel = GetGroupLabel(resultControl); + BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); - Assert.AreEqual(new EnumDisplayWrapper(result.Group).DisplayName, - groupLabel.Text); - Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetFailureMechanismAssemblyCategoryGroupColor(result.Group), - groupLabel.BackColor); - - Assert.AreEqual(new NoProbabilityValueDoubleConverter().ConvertToString(result.Probability), - probabilityLabel.Text); + AssertGroupLabel(result, groupLabel); + AssertProbabilityLabel(result, probabilityLabel); } } [Test] public void ClearData_Always_ClearsDataOnControl() { // Setup + var random = new Random(39); + using (var resultControl = new FailureMechanismAssemblyControl()) { + var result = new FailureMechanismAssembly(random.NextDouble(), + random.NextEnumValue()); + resultControl.SetAssemblyResult(result); + + // Precondition + BorderedLabel groupLabel = GetGroupLabel(resultControl); + BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); + + AssertGroupLabel(result, groupLabel); + AssertProbabilityLabel(result, probabilityLabel); + // Call resultControl.ClearData(); // Assert - BorderedLabel groupLabel = GetGroupLabel(resultControl); - BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); Assert.AreEqual("-", probabilityLabel.Text); } } + private static void AssertProbabilityLabel(FailureMechanismAssembly result, BorderedLabel probabilityLabel) + { + Assert.AreEqual(new NoProbabilityValueDoubleConverter().ConvertToString(result.Probability), + probabilityLabel.Text); + } + + private static void AssertGroupLabel(FailureMechanismAssembly result, BorderedLabel groupLabel) + { + Assert.AreEqual(new EnumDisplayWrapper(result.Group).DisplayName, groupLabel.Text); + Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetFailureMechanismAssemblyCategoryGroupColor(result.Group), + groupLabel.BackColor); + } + private static BorderedLabel GetGroupLabel(FailureMechanismAssemblyControl resultControl) { return (BorderedLabel) ((TableLayoutPanel) resultControl.Controls["GroupPanel"]).GetControlFromPosition(0, 0); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs (.../FailureMechanismResultViewTest.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs (.../FailureMechanismResultViewTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -24,6 +24,7 @@ using System.Drawing; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Controls; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.TestUtil; @@ -173,7 +174,7 @@ } [Test] - public void GivenFailureMechanismResultView_WhenFailureMechanismNotifiesObservers_ThenDataGridViewInvalidatedAndAssemblyResultUpdated() + public void GivenFailureMechanismResultView_WhenFailureMechanismNotifiesObservers_ThenDataGridViewInvalidatedAndAssemblyResultControlUpdated() { // Given TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); @@ -188,18 +189,18 @@ var invalidated = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Invalidated += (sender, args) => invalidated = true; - view.AssemblyResultUpdated = false; + view.AssemblyResultControlUpdated = false; // Precondition Assert.IsFalse(invalidated); - Assert.IsFalse(view.AssemblyResultUpdated); + Assert.IsFalse(view.AssemblyResultControlUpdated); // When view.FailureMechanism.NotifyObservers(); // Then Assert.IsTrue(invalidated); - Assert.IsTrue(view.AssemblyResultUpdated); + Assert.IsTrue(view.AssemblyResultControlUpdated); } } @@ -225,7 +226,7 @@ } [Test] - public void GivenFailureMechanismResultView_WhenSingleFailureMechanismSectionResultNotifiesObservers_ThenDataGridViewInvalidatedAndAssemblyResultUpdated() + public void GivenFailureMechanismResultView_WhenSingleFailureMechanismSectionResultNotifiesObservers_ThenDataGridViewInvalidatedAndAssemblyResultControlUpdated() { // Given TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); @@ -240,18 +241,18 @@ var invalidated = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Invalidated += (sender, args) => invalidated = true; - view.AssemblyResultUpdated = false; + view.AssemblyResultControlUpdated = false; // Precondition Assert.IsFalse(invalidated); - Assert.IsFalse(view.AssemblyResultUpdated); + Assert.IsFalse(view.AssemblyResultControlUpdated); // When sectionResult.NotifyObservers(); // Then Assert.IsTrue(invalidated); - Assert.IsTrue(view.AssemblyResultUpdated); + Assert.IsTrue(view.AssemblyResultControlUpdated); } } @@ -290,7 +291,7 @@ } [Test] - public void GivenFailureMechanismResultView_WhenRowUpdatedEventFiredAndSectionResultNotified_ThenRowNotUpdatedAndViewInvalidatedAndAssemblyResultUpdated() + public void GivenFailureMechanismResultView_WhenRowUpdatedEventFiredAndSectionResultNotified_ThenRowNotUpdatedAndViewInvalidatedAndAssemblyResultControlUpdated() { // Given TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); @@ -306,7 +307,7 @@ var row = (TestRow) dataGridView.Rows[0].DataBoundItem; var invalidated = false; dataGridView.Invalidated += (sender, args) => invalidated = true; - view.AssemblyResultUpdated = false; + view.AssemblyResultControlUpdated = false; // Precondition Assert.IsFalse(invalidated); @@ -320,12 +321,12 @@ // Then Assert.IsTrue(invalidated); Assert.IsFalse(row.Updated); - Assert.IsTrue(view.AssemblyResultUpdated); + Assert.IsTrue(view.AssemblyResultControlUpdated); } } [Test] - public void GivenFailureMechanismResultsView_WhenExceptionThrownDuringUpdate_FailureMechanismAssemblyResultClearedAndErrorSet() + public void GivenFailureMechanismResultsView_WhenExceptionThrownDuringUpdate_ThenErrorSet() { // Given TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); @@ -338,12 +339,12 @@ using (TestFailureMechanismResultView view = ShowFailureMechanismResultsView(sectionResults)) { // Precondition - FailureMechanismAssemblyCategoryGroupControl resultControl = GetFailureMechanismAssemblyCategoryGroupControl(); + TestAssemblyResultControl resultControl = GetFailureMechanismAssemblyCategoryGroupControl(); ErrorProvider errorProvider = GetErrorProvider(resultControl); Assert.IsEmpty(errorProvider.GetError(resultControl)); // When - view.ThrowExceptionOnCalculate = true; + view.ThrowExceptionOnUpdate = true; sectionResult.NotifyObservers(); // Then @@ -352,7 +353,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithFailureMechanismAssemblyError_WhenNoExceptionThrownDuringUpdate_ResultSetAndErrorCleared() + public void GivenFailureMechanismResultsView_WhenFailureMechanismAssemblyControlUpdated_ThenDataCleared() { // Given TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); @@ -362,18 +363,42 @@ sectionResult }; + using (ShowFailureMechanismResultsView(sectionResults)) + { + var groupLabel = (BorderedLabel) new ControlTester("GroupLabel").TheObject; + groupLabel.Text = "aaa"; + + // When + sectionResult.NotifyObservers(); + + // Then + Assert.IsEmpty(groupLabel.Text); + } + } + + [Test] + public void GivenFailureMechanismResultsViewWithFailureMechanismAssemblyError_WhenNoExceptionThrownDuringUpdate_ThenErrorCleared() + { + // Given + TestFailureMechanismSectionResult sectionResult = FailureMechanismSectionResultTestFactory.CreateFailureMechanismSectionResult(); + + var sectionResults = new ObservableList + { + sectionResult + }; + using (TestFailureMechanismResultView view = ShowFailureMechanismResultsView(sectionResults)) { - view.ThrowExceptionOnCalculate = true; + view.ThrowExceptionOnUpdate = true; sectionResult.NotifyObservers(); // Precondition - FailureMechanismAssemblyCategoryGroupControl resultControl = GetFailureMechanismAssemblyCategoryGroupControl(); + TestAssemblyResultControl resultControl = GetFailureMechanismAssemblyCategoryGroupControl(); ErrorProvider errorProvider = GetErrorProvider(resultControl); Assert.AreEqual("Message", errorProvider.GetError(resultControl)); // When - view.ThrowExceptionOnCalculate = false; + view.ThrowExceptionOnUpdate = false; sectionResult.NotifyObservers(); // Then @@ -452,14 +477,14 @@ return (DataGridView) new ControlTester("dataGridView").TheObject; } - private static ErrorProvider GetErrorProvider(FailureMechanismAssemblyCategoryGroupControl resultControl) + private static ErrorProvider GetErrorProvider(TestAssemblyResultControl resultControl) { return TypeUtils.GetField(resultControl, "errorProvider"); } - private static FailureMechanismAssemblyCategoryGroupControl GetFailureMechanismAssemblyCategoryGroupControl() + private static TestAssemblyResultControl GetFailureMechanismAssemblyCategoryGroupControl() { - return (FailureMechanismAssemblyCategoryGroupControl) new ControlTester("AssemblyResultControl").TheObject; + return (TestAssemblyResultControl) new ControlTester("AssemblyResultControl").TheObject; } private TestFailureMechanismResultView ShowFailureMechanismResultsView(IObservableEnumerable sectionResults) @@ -471,16 +496,21 @@ return failureMechanismResultView; } - private class TestFailureMechanismResultView : FailureMechanismResultView, TestFailureMechanism, FailureMechanismAssemblyCategoryGroupControl> + private class TestFailureMechanismResultView : FailureMechanismResultView, + TestFailureMechanism, + TestAssemblyResultControl> { - public TestFailureMechanismResultView(IObservableEnumerable failureMechanismSectionResults, TestFailureMechanism failureMechanism) + public TestFailureMechanismResultView(IObservableEnumerable failureMechanismSectionResults, + TestFailureMechanism failureMechanism) : base(failureMechanismSectionResults, failureMechanism) {} - public bool ThrowExceptionOnCalculate { private get; set; } + public bool ThrowExceptionOnUpdate { private get; set; } - public bool AssemblyResultUpdated { get; set; } + public bool AssemblyResultControlUpdated { get; set; } - protected override FailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow(FailureMechanismSectionResult sectionResult) + protected override FailureMechanismSectionResultRow CreateFailureMechanismSectionResultRow( + FailureMechanismSectionResult sectionResult) { return new TestRow(sectionResult); } @@ -492,15 +522,17 @@ protected override void UpdateAssemblyResultControl() { - if (ThrowExceptionOnCalculate) + if (ThrowExceptionOnUpdate) { throw new AssemblyException("Message"); } - AssemblyResultUpdated = true; + AssemblyResultControlUpdated = true; } } + private class TestAssemblyResultControl : AssemblyResultControl {} + private class TestRow : FailureMechanismSectionResultRow { public TestRow(FailureMechanismSectionResult sectionResult) : base(sectionResult) Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyCategoryGroupControlTestFixture.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyCategoryGroupControlTestFixture.cs (.../FailureMechanismAssemblyCategoryGroupControlTestFixture.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyCategoryGroupControlTestFixture.cs (.../FailureMechanismAssemblyCategoryGroupControlTestFixture.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -85,7 +85,7 @@ } [Test] - public void GivenFailureMechanismResultsView_WhenCalculatorThrowsException_ErrorSetToControl() + public void GivenFailureMechanismResultsView_WhenCalculatorThrowsException_ThenErrorSetToControl() { // Given var failureMechanism = new TFailureMechanism(); @@ -110,7 +110,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenCalculatorThrowsException_FailureMechanismAssemblyResultCleared() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenCalculatorThrowsException_ThenFailureMechanismAssemblyResultCleared() { // Given var failureMechanism = new TFailureMechanism(); @@ -134,7 +134,7 @@ } [Test] - public void GivenFailureMechanismResultsView_WhenNoExceptionThrownByCalculator_ErrorCleared() + public void GivenFailureMechanismResultsViewWithError_WhenNoExceptionThrownByCalculator_ThenErrorCleared() { // Given var failureMechanism = new TFailureMechanism(); @@ -163,7 +163,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_FailureMechanismAssemblyResultChangedAndSectionResultNotified_FailureMechanismAssemblyResultUpdated() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndSectionResultNotified_ThenFailureMechanismAssemblyResultUpdated() { // Given var failureMechanism = new TFailureMechanism(); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyResultWithProbabilityControlTestFixture.cs =================================================================== diff -u -r84223425c4ab8eec2440f512b5b06bea8937f8f9 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyResultWithProbabilityControlTestFixture.cs (.../FailureMechanismAssemblyResultWithProbabilityControlTestFixture.cs) (revision 84223425c4ab8eec2440f512b5b06bea8937f8f9) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismAssemblyResultWithProbabilityControlTestFixture.cs (.../FailureMechanismAssemblyResultWithProbabilityControlTestFixture.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -90,7 +90,7 @@ } [Test] - public void GivenFailureMechanismResultsView_WhenNoExceptionThrownByCalculator_ErrorSetToControl() + public void GivenFailureMechanismResultsView_WhenNoExceptionThrownByCalculator_ThenErrorSetToControl() { // Given var failureMechanism = new TFailureMechanism(); @@ -115,7 +115,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenCalculatorThrowsException_FailureMechanismAssemblyResultCleared() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenCalculatorThrowsException_ThenFailureMechanismAssemblyResultCleared() { // Given var failureMechanism = new TFailureMechanism(); @@ -142,7 +142,7 @@ } [Test] - public void GivenFailureMechanismResultsView_WhenNoExceptionThrownByCalculator_ErrorCleared() + public void GivenFailureMechanismResultsViewWithError_WhenNoExceptionThrownByCalculator_ThenErrorCleared() { // Given var failureMechanism = new TFailureMechanism(); @@ -171,7 +171,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndSectionResultNotified_FailureMechanismAssemblyResultUpdated() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndSectionResultNotified_ThenFailureMechanismAssemblyResultUpdated() { // Given var failureMechanism = new TFailureMechanism(); @@ -199,7 +199,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndCalculationNotified_FailureMechanismAssemblyResultUpdated() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndCalculationNotified_ThenFailureMechanismAssemblyResultUpdated() { // Given var failureMechanism = new TFailureMechanism(); @@ -228,7 +228,7 @@ } [Test] - public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndCalculationInputNotified_FailureMechanismAssemblyResultUpdated() + public void GivenFailureMechanismResultsViewWithAssemblyResult_WhenFailureMechanismAssemblyResultChangedAndCalculationInputNotified_ThenFailureMechanismAssemblyResultUpdated() { // Given var failureMechanism = new TFailureMechanism(); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyCategoryGroupControl.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyCategoryGroupControl.cs (.../AssessmentSectionAssemblyCategoryGroupControl.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyCategoryGroupControl.cs (.../AssessmentSectionAssemblyCategoryGroupControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -19,6 +19,8 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.ComponentModel; using Core.Common.Util; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Forms.Controls; @@ -27,14 +29,18 @@ namespace Ringtoets.Integration.Forms.Controls { /// - /// Custom control to display a . + /// Control to display a . /// public class AssessmentSectionAssemblyCategoryGroupControl : AssemblyResultControl { /// /// Set the value of on the control. /// /// The to set on the control. + /// Thrown when + /// has an invalid value for . + /// Thrown when + /// is not supported. public void SetAssemblyResult(AssessmentSectionAssemblyCategoryGroup result) { GroupLabel.Text = new EnumDisplayWrapper(result).DisplayName; Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyControl.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyControl.cs (.../AssessmentSectionAssemblyControl.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Controls/AssessmentSectionAssemblyControl.cs (.../AssessmentSectionAssemblyControl.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.ComponentModel; using Core.Common.Util; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Forms.Controls; @@ -29,7 +30,7 @@ namespace Ringtoets.Integration.Forms.Controls { /// - /// Custom control to display a . + /// Control to display a . /// public class AssessmentSectionAssemblyControl : AssemblyResultWithProbabilityControl { @@ -38,6 +39,10 @@ /// /// The to set on the control. /// Thrown when is null. + /// Thrown when + /// has an invalid value for . + /// Thrown when + /// has a category that is not supported. public void SetAssemblyResult(AssessmentSectionAssembly result) { if (result == null) Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs =================================================================== diff -u -r2d3464046e5856581b5b9c2027572ac03b5a9be3 -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 2d3464046e5856581b5b9c2027572ac03b5a9be3) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -21,10 +21,12 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Windows.Forms; using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Core.Common.Util.Extensions; +using Ringtoets.AssemblyTool.Data; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.Exceptions; using Ringtoets.DuneErosion.Data; @@ -151,13 +153,29 @@ dataGridViewControl.SetDataSource(assemblyResultRows); } + /// + /// Event handler for a click event on the . + /// + /// The sender of the event. + /// The event arguments. + /// Thrown when the result + /// has an invalid value for . + /// Thrown when the result has a value for + /// that is not supported. private void RefreshAssemblyResults_Click(object sender, EventArgs e) { assemblyResultRows.ForEachElementDo(row => row.Update()); dataGridViewControl.RefreshDataGridView(); UpdateAssemblyResultControls(); } + /// + /// Updates the assembly result controls. + /// + /// Thrown when the result + /// has an invalid value for . + /// Thrown when the result has a value for + /// that is not supported. private void UpdateAssemblyResultControls() { totalAssemblyCategoryGroupControl.ClearData(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyCategoryGroupControlTest.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyCategoryGroupControlTest.cs (.../AssessmentSectionAssemblyCategoryGroupControlTest.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyCategoryGroupControlTest.cs (.../AssessmentSectionAssemblyCategoryGroupControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -60,29 +60,42 @@ // Assert BorderedLabel groupLabel = GetGroupLabel(resultControl); - Assert.AreEqual(new EnumDisplayWrapper(result).DisplayName, - groupLabel.Text); - Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetAssessmentSectionAssemblyCategoryGroupColor(result), - groupLabel.BackColor); + AssertGroupLabel(result, groupLabel); } } [Test] public void ClearData_Always_ClearsDataOnControl() { // Setup + var random = new Random(39); + using (var resultControl = new AssessmentSectionAssemblyCategoryGroupControl()) { + var result = random.NextEnumValue(); + resultControl.SetAssemblyResult(result); + + // Precondition + BorderedLabel groupLabel = GetGroupLabel(resultControl); + AssertGroupLabel(result, groupLabel); + // Call resultControl.ClearData(); // Assert - BorderedLabel groupLabel = GetGroupLabel(resultControl); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); } } + private static void AssertGroupLabel(AssessmentSectionAssemblyCategoryGroup result, BorderedLabel groupLabel) + { + Assert.AreEqual(new EnumDisplayWrapper(result).DisplayName, + groupLabel.Text); + Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetAssessmentSectionAssemblyCategoryGroupColor(result), + groupLabel.BackColor); + } + private static BorderedLabel GetGroupLabel(AssessmentSectionAssemblyCategoryGroupControl resultControl) { return (BorderedLabel) ((TableLayoutPanel) resultControl.Controls["GroupPanel"]).GetControlFromPosition(0, 0); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyControlTest.cs =================================================================== diff -u -r5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f -ree93ac5bb6cb37107dfbef6ea72287cf67f83cc0 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyControlTest.cs (.../AssessmentSectionAssemblyControlTest.cs) (revision 5f24b9f44bf75f735f6b9171ec6ce482fa0dcc7f) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Controls/AssessmentSectionAssemblyControlTest.cs (.../AssessmentSectionAssemblyControlTest.cs) (revision ee93ac5bb6cb37107dfbef6ea72287cf67f83cc0) @@ -76,37 +76,55 @@ resultControl.SetAssemblyResult(result); // Assert - Control groupLabel = GetGroupLabel(resultControl); - Control probabilityLabel = GetProbabilityLabel(resultControl); + BorderedLabel groupLabel = GetGroupLabel(resultControl); + BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); - Assert.AreEqual(new EnumDisplayWrapper(result.Group).DisplayName, - groupLabel.Text); - Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetAssessmentSectionAssemblyCategoryGroupColor(result.Group), - groupLabel.BackColor); - - Assert.AreEqual(new NoProbabilityValueDoubleConverter().ConvertToString(result.Probability), - probabilityLabel.Text); + AssertGroupLabel(result, groupLabel); + AssertProbabilityLabel(result, probabilityLabel); } } [Test] public void ClearData_Always_ClearsDataOnControl() { // Setup + var random = new Random(39); + using (var resultControl = new AssessmentSectionAssemblyControl()) { + var result = new AssessmentSectionAssembly(random.NextDouble(), + random.NextEnumValue()); + resultControl.SetAssemblyResult(result); + + // Precondition + BorderedLabel groupLabel = GetGroupLabel(resultControl); + BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); + AssertGroupLabel(result, groupLabel); + AssertProbabilityLabel(result, probabilityLabel); // Call resultControl.ClearData(); // Assert - BorderedLabel groupLabel = GetGroupLabel(resultControl); - BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl); Assert.IsEmpty(groupLabel.Text); Assert.AreEqual(Color.White, groupLabel.BackColor); Assert.AreEqual("-", probabilityLabel.Text); } } + private static void AssertProbabilityLabel(AssessmentSectionAssembly result, BorderedLabel probabilityLabel) + { + Assert.AreEqual(new NoProbabilityValueDoubleConverter().ConvertToString(result.Probability), + probabilityLabel.Text); + } + + private static void AssertGroupLabel(AssessmentSectionAssembly result, BorderedLabel groupLabel) + { + Assert.AreEqual(new EnumDisplayWrapper(result.Group).DisplayName, + groupLabel.Text); + Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetAssessmentSectionAssemblyCategoryGroupColor(result.Group), + groupLabel.BackColor); + } + private static BorderedLabel GetGroupLabel(AssessmentSectionAssemblyControl resultControl) { return (BorderedLabel) ((TableLayoutPanel) resultControl.Controls["GroupPanel"]).GetControlFromPosition(0, 0);