Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.Designer.cs
===================================================================
diff -u -r42bab853d615b667284416929f32f2fe228dd1c0 -r86671bd69fa809d754e4189fb247fb170f2888f4
--- Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.Designer.cs (.../AssessmentSectionAssemblyResultControl.Designer.cs) (revision 42bab853d615b667284416929f32f2fe228dd1c0)
+++ Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.Designer.cs (.../AssessmentSectionAssemblyResultControl.Designer.cs) (revision 86671bd69fa809d754e4189fb247fb170f2888f4)
@@ -57,8 +57,8 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AssessmentSectionAssemblyResultControl));
this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
this.resultLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
- this.assessmentSectionAssemblyCategoryGroupLabel = new System.Windows.Forms.Label();
- this.assessmentSectionFailureProbabilityLabel = new System.Windows.Forms.Label();
+ this.assemblyCategoryGroupDisplayNameLabel = new System.Windows.Forms.Label();
+ this.assemblyProbabilityDisplayNameLabel = new System.Windows.Forms.Label();
this.groupLabel = new Core.Common.Controls.BorderedLabel();
this.probabilityLabel = new Core.Common.Controls.BorderedLabel();
((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
@@ -76,8 +76,8 @@
this.resultLayoutPanel.ColumnCount = 2;
this.resultLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.resultLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
- this.resultLayoutPanel.Controls.Add(this.assessmentSectionAssemblyCategoryGroupLabel, 0, 0);
- this.resultLayoutPanel.Controls.Add(this.assessmentSectionFailureProbabilityLabel, 0, 1);
+ this.resultLayoutPanel.Controls.Add(this.assemblyCategoryGroupDisplayNameLabel, 0, 0);
+ this.resultLayoutPanel.Controls.Add(this.assemblyProbabilityDisplayNameLabel, 0, 1);
this.resultLayoutPanel.Controls.Add(this.groupLabel, 1, 0);
this.resultLayoutPanel.Controls.Add(this.probabilityLabel, 1, 1);
this.resultLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -90,31 +90,31 @@
this.resultLayoutPanel.AutoSize = true;
this.resultLayoutPanel.TabIndex = 0;
//
- // assessmentSectionAssemblyCategoryGroupLabel
+ // assemblyCategoryGroupDisplayNameLabel
//
- this.assessmentSectionAssemblyCategoryGroupLabel.AutoSize = true;
- this.assessmentSectionAssemblyCategoryGroupLabel.TextAlign = ContentAlignment.MiddleLeft;
- this.assessmentSectionAssemblyCategoryGroupLabel.Location = new System.Drawing.Point(3, 0);
- this.assessmentSectionAssemblyCategoryGroupLabel.Name = "assessmentSectionAssemblyCategoryGroupLabel";
- this.assessmentSectionAssemblyCategoryGroupLabel.Size = new System.Drawing.Size(92, 13);
- this.assessmentSectionAssemblyCategoryGroupLabel.Dock = DockStyle.Left;
- this.assessmentSectionAssemblyCategoryGroupLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
- this.assessmentSectionAssemblyCategoryGroupLabel.Margin = new System.Windows.Forms.Padding(3);
- this.assessmentSectionAssemblyCategoryGroupLabel.TabIndex = 0;
- this.assessmentSectionAssemblyCategoryGroupLabel.Text = "Veiligheidsoordeel";
+ this.assemblyCategoryGroupDisplayNameLabel.AutoSize = true;
+ this.assemblyCategoryGroupDisplayNameLabel.TextAlign = ContentAlignment.MiddleLeft;
+ this.assemblyCategoryGroupDisplayNameLabel.Location = new System.Drawing.Point(3, 0);
+ this.assemblyCategoryGroupDisplayNameLabel.Name = "assemblyCategoryGroupDisplayNameLabel";
+ this.assemblyCategoryGroupDisplayNameLabel.Size = new System.Drawing.Size(92, 13);
+ this.assemblyCategoryGroupDisplayNameLabel.Dock = DockStyle.Left;
+ this.assemblyCategoryGroupDisplayNameLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
+ this.assemblyCategoryGroupDisplayNameLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.assemblyCategoryGroupDisplayNameLabel.TabIndex = 0;
+ this.assemblyCategoryGroupDisplayNameLabel.Text = "Veiligheidsoordeel";
//
- // assessmentSectionFailureProbabilityLabel
+ // assemblyProbabilityDisplayNameLabel
//
- this.assessmentSectionFailureProbabilityLabel.AutoSize = true;
- this.assessmentSectionFailureProbabilityLabel.TextAlign = ContentAlignment.MiddleLeft;
- this.assessmentSectionFailureProbabilityLabel.Location = new System.Drawing.Point(3, 398);
- this.assessmentSectionFailureProbabilityLabel.Name = "assessmentSectionFailureProbabilityLabel";
- this.assessmentSectionFailureProbabilityLabel.Size = new System.Drawing.Size(50, 13);
- this.assessmentSectionFailureProbabilityLabel.Dock = DockStyle.Left;
- this.assessmentSectionFailureProbabilityLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
- this.assessmentSectionFailureProbabilityLabel.Margin = new System.Windows.Forms.Padding(3);
- this.assessmentSectionFailureProbabilityLabel.TabIndex = 1;
- this.assessmentSectionFailureProbabilityLabel.Text = "Faalkans";
+ this.assemblyProbabilityDisplayNameLabel.AutoSize = true;
+ this.assemblyProbabilityDisplayNameLabel.TextAlign = ContentAlignment.MiddleLeft;
+ this.assemblyProbabilityDisplayNameLabel.Location = new System.Drawing.Point(3, 398);
+ this.assemblyProbabilityDisplayNameLabel.Name = "assemblyProbabilityDisplayNameLabel";
+ this.assemblyProbabilityDisplayNameLabel.Size = new System.Drawing.Size(50, 13);
+ this.assemblyProbabilityDisplayNameLabel.Dock = DockStyle.Left;
+ this.assemblyProbabilityDisplayNameLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
+ this.assemblyProbabilityDisplayNameLabel.Margin = new System.Windows.Forms.Padding(3);
+ this.assemblyProbabilityDisplayNameLabel.TabIndex = 1;
+ this.assemblyProbabilityDisplayNameLabel.Text = "Faalkans";
//
// groupLabel
//
@@ -163,8 +163,8 @@
private System.Windows.Forms.ErrorProvider errorProvider;
private TableLayoutPanel resultLayoutPanel;
- private Label assessmentSectionAssemblyCategoryGroupLabel;
- private Label assessmentSectionFailureProbabilityLabel;
+ private Label assemblyCategoryGroupDisplayNameLabel;
+ private Label assemblyProbabilityDisplayNameLabel;
private BorderedLabel groupLabel;
private BorderedLabel probabilityLabel;
}
Index: Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.cs
===================================================================
diff -u -r42bab853d615b667284416929f32f2fe228dd1c0 -r86671bd69fa809d754e4189fb247fb170f2888f4
--- Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.cs (.../AssessmentSectionAssemblyResultControl.cs) (revision 42bab853d615b667284416929f32f2fe228dd1c0)
+++ Riskeer/Integration/src/Riskeer.Integration.Forms/Controls/AssessmentSectionAssemblyResultControl.cs (.../AssessmentSectionAssemblyResultControl.cs) (revision 86671bd69fa809d754e4189fb247fb170f2888f4)
@@ -27,7 +27,6 @@
using Riskeer.AssemblyTool.Data;
using Riskeer.Common.Forms.Helpers;
using Riskeer.Common.Forms.Properties;
-using Riskeer.Common.Forms.TypeConverters;
namespace Riskeer.Integration.Forms.Controls
{
@@ -36,8 +35,6 @@
///
public partial class AssessmentSectionAssemblyResultControl : UserControl
{
- private readonly NoProbabilityValueDoubleConverter converter = new NoProbabilityValueDoubleConverter();
-
///
/// Creates a new instance of .
///
@@ -91,7 +88,7 @@
groupLabel.Text = new EnumDisplayWrapper(result.AssemblyCategoryGroup).DisplayName;
groupLabel.BackColor = AssemblyCategoryGroupColorHelper.GetAssessmentSectionAssemblyCategoryGroupColor(result.AssemblyCategoryGroup);
- probabilityLabel.Text = converter.ConvertToString(result.Probability);
+ probabilityLabel.Text = ProbabilityFormattingHelper.FormatWithDiscreteNumbers(result.Probability);
}
///
Fisheye: Tag 86671bd69fa809d754e4189fb247fb170f2888f4 refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Controls/AssessmentSectionAssemblyCategoryGroupControlTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Controls/AssessmentSectionAssemblyResultControlTest.cs
===================================================================
diff -u
--- Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Controls/AssessmentSectionAssemblyResultControlTest.cs (revision 0)
+++ Riskeer/Integration/test/Riskeer.Integration.Forms.Test/Controls/AssessmentSectionAssemblyResultControlTest.cs (revision 86671bd69fa809d754e4189fb247fb170f2888f4)
@@ -0,0 +1,255 @@
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using Core.Common.Controls;
+using Core.Common.TestUtil;
+using Core.Common.Util;
+using Core.Common.Util.Reflection;
+using NUnit.Framework;
+using Riskeer.AssemblyTool.Data;
+using Riskeer.Common.Forms.Helpers;
+using Riskeer.Integration.Forms.Controls;
+using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources;
+
+namespace Riskeer.Integration.Forms.Test.Controls
+{
+ [TestFixture]
+ public class AssessmentSectionAssemblyResultControlTest
+ {
+ [Test]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Call
+ using (var form = new Form())
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ form.Controls.Add(resultControl);
+ form.Show();
+
+ // Assert
+ Assert.IsInstanceOf(resultControl);
+ Assert.IsTrue(resultControl.AutoSize);
+
+ TableLayoutPanel panel = GetResultPanel(resultControl);
+ Assert.AreEqual(2, panel.ColumnCount);
+ Assert.AreEqual(2, panel.RowCount);
+
+ var assemblyCategoryGroupDisplayNameLabel = (Label) panel.GetControlFromPosition(0, 0);
+ Assert.AreEqual("Veiligheidsoordeel", assemblyCategoryGroupDisplayNameLabel.Text);
+ Assert.IsTrue(assemblyCategoryGroupDisplayNameLabel.AutoSize);
+ Assert.AreEqual(DockStyle.Left, assemblyCategoryGroupDisplayNameLabel.Dock);
+ Assert.AreEqual(new Padding(5, 0, 5, 0), assemblyCategoryGroupDisplayNameLabel.Padding);
+ Assert.AreEqual(new Padding(3), assemblyCategoryGroupDisplayNameLabel.Margin);
+
+ var failureProbabilityDisplayNameLabel = (Label) panel.GetControlFromPosition(0, 1);
+ Assert.AreEqual("Faalkans", failureProbabilityDisplayNameLabel.Text);
+ Assert.IsTrue(failureProbabilityDisplayNameLabel.AutoSize);
+ Assert.AreEqual(DockStyle.Left, failureProbabilityDisplayNameLabel.Dock);
+ Assert.AreEqual(new Padding(5, 0, 5, 0), failureProbabilityDisplayNameLabel.Padding);
+ Assert.AreEqual(new Padding(3), failureProbabilityDisplayNameLabel.Margin);
+
+ var groupLabel = (BorderedLabel) panel.GetControlFromPosition(1, 0);
+ Assert.IsTrue(groupLabel.AutoSize);
+ Assert.AreEqual(DockStyle.Left, groupLabel.Dock);
+ Assert.AreEqual(new Padding(5, 0, 5, 0), groupLabel.Padding);
+ Assert.AreEqual(new Padding(3), groupLabel.Margin);
+
+ var probabilityLabel = (BorderedLabel) panel.GetControlFromPosition(1, 1);
+ Assert.IsTrue(probabilityLabel.AutoSize);
+ Assert.AreEqual(DockStyle.Left, probabilityLabel.Dock);
+ Assert.AreEqual(new Padding(5, 0, 5, 0), probabilityLabel.Padding);
+ Assert.AreEqual(new Padding(3), probabilityLabel.Margin);
+
+ ErrorProvider errorProvider = GetErrorProvider(resultControl);
+ TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ErrorIcon.ToBitmap(), errorProvider.Icon.ToBitmap());
+ Assert.AreEqual(ErrorBlinkStyle.NeverBlink, errorProvider.BlinkStyle);
+
+ Assert.IsEmpty(errorProvider.GetError(groupLabel));
+ Assert.IsEmpty(errorProvider.GetError(probabilityLabel));
+ }
+ }
+
+ [Test]
+ public void SetAssemblyResult_ResultNull_ThrowsArgumentNullException()
+ {
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ // Call
+ void Call() => resultControl.SetAssemblyResult(null);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual("result", exception.ParamName);
+ }
+ }
+
+ [Test]
+ public void SetAssemblyResult_WithResult_SetsValues()
+ {
+ // Setup
+ var random = new Random(39);
+ var result = new AssessmentSectionAssemblyResult(random.NextDouble(),
+ random.NextEnumValue());
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ // Call
+ resultControl.SetAssemblyResult(result);
+
+ // Assert
+ BorderedLabel groupLabel = GetGroupLabel(resultControl);
+ AssertGroupLabel(result.AssemblyCategoryGroup, groupLabel);
+
+ BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
+ AssertProbabilityLabel(result.Probability, probabilityLabel);
+ }
+ }
+
+ [Test]
+ public void ClearAssemblyResult_Always_ClearsResultOnControl()
+ {
+ // Setup
+ var random = new Random(39);
+
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ var result = new AssessmentSectionAssemblyResult(random.NextDouble(),
+ random.NextEnumValue());
+ resultControl.SetAssemblyResult(result);
+
+ // Precondition
+ BorderedLabel groupLabel = GetGroupLabel(resultControl);
+ AssertGroupLabel(result.AssemblyCategoryGroup, groupLabel);
+
+ BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
+ AssertProbabilityLabel(result.Probability, probabilityLabel);
+
+ // Call
+ resultControl.ClearAssemblyResult();
+
+ // Assert
+ Assert.IsEmpty(groupLabel.Text);
+ Assert.AreEqual(Color.White, groupLabel.BackColor);
+
+ Assert.AreEqual("-", probabilityLabel.Text);
+ }
+ }
+
+ [Test]
+ public void SetError_ErrorMessageNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ // Call
+ TestDelegate test = () => resultControl.SetError(null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("errorMessage", exception.ParamName);
+ }
+ }
+
+ [Test]
+ [TestCase("random error 123")]
+ [TestCase("")]
+ public void SetError_WithErrorMessage_SetsErrorMessageOnControl(string errorMessage)
+ {
+ // Setup
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ // Call
+ resultControl.SetError(errorMessage);
+
+ // Assert
+ ErrorProvider errorProvider = GetErrorProvider(resultControl);
+
+ BorderedLabel groupLabel = GetGroupLabel(resultControl);
+ Assert.AreEqual(errorMessage, errorProvider.GetError(groupLabel));
+
+ BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
+ Assert.AreEqual(errorMessage, errorProvider.GetError(probabilityLabel));
+ }
+ }
+
+ [Test]
+ public void GivenControlWithMessages_WhenMessagesCleared_ThenMessagesCleared()
+ {
+ // Given
+ using (var resultControl = new AssessmentSectionAssemblyResultControl())
+ {
+ resultControl.SetError("Error");
+
+ // Precondition
+ ErrorProvider errorProvider = GetErrorProvider(resultControl);
+
+ BorderedLabel groupLabel = GetGroupLabel(resultControl);
+ Assert.IsNotEmpty(errorProvider.GetError(groupLabel));
+
+ BorderedLabel probabilityLabel = GetProbabilityLabel(resultControl);
+ Assert.IsNotEmpty(errorProvider.GetError(probabilityLabel));
+
+ // When
+ resultControl.ClearMessages();
+
+ // Then
+ Assert.IsEmpty(errorProvider.GetError(groupLabel));
+ Assert.IsEmpty(errorProvider.GetError(probabilityLabel));
+ }
+ }
+
+ 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 void AssertProbabilityLabel(double probability, BorderedLabel probabilityLabel)
+ {
+ Assert.AreEqual(ProbabilityFormattingHelper.FormatWithDiscreteNumbers(probability),
+ probabilityLabel.Text);
+ }
+
+ private static BorderedLabel GetGroupLabel(AssessmentSectionAssemblyResultControl resultControl)
+ {
+ return (BorderedLabel) (GetResultPanel(resultControl)).GetControlFromPosition(1, 0);
+ }
+
+ private static BorderedLabel GetProbabilityLabel(AssessmentSectionAssemblyResultControl resultControl)
+ {
+ return (BorderedLabel) (GetResultPanel(resultControl)).GetControlFromPosition(1, 1);
+ }
+
+ private static TableLayoutPanel GetResultPanel(AssessmentSectionAssemblyResultControl resultControl)
+ {
+ return (TableLayoutPanel) resultControl.Controls["resultLayoutPanel"];
+ }
+
+ private static ErrorProvider GetErrorProvider(AssessmentSectionAssemblyResultControl resultControl)
+ {
+ return TypeUtils.GetField(resultControl, "errorProvider");
+ }
+ }
+}
\ No newline at end of file