Index: Riskeer/Common/src/Riskeer.Common.Forms/Views/FailureMechanismResultView.cs =================================================================== diff -u -r6634485dd2d55fb2be1b9e3fa001cd2ece3c61c6 -r0e9aacae86bb756ea45a965b7eab7fb735491062 --- Riskeer/Common/src/Riskeer.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 6634485dd2d55fb2be1b9e3fa001cd2ece3c61c6) +++ Riskeer/Common/src/Riskeer.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 0e9aacae86bb756ea45a965b7eab7fb735491062) @@ -182,15 +182,9 @@ { UpdateDataGridViewDataSource(); UpdateAssemblyData(); - UpdateProbabilityResultTypeCombobox(); - UpdateFailureMechanismAssemblyControls(); + UpdateFailureMechanismAssemblyResultControls(); } - - private void UpdateProbabilityResultTypeCombobox() - { - probabilityResultTypeComboBox.Enabled = HasSections(); - } - + private void RefreshDataGrid() { DataGridViewControl.RefreshDataGridView(false); @@ -216,10 +210,13 @@ probabilityResultTypeComboBox.EndUpdate(); } - private void UpdateFailureMechanismAssemblyControls() + private void UpdateFailureMechanismAssemblyResultControls() { - failureMechanismAssemblyProbabilityTextBox.Enabled = IsManualAssembly() && HasSections(); - failureMechanismAssemblyProbabilityTextBox.ReadOnly = !IsManualAssembly() && !HasSections(); + probabilityResultTypeComboBox.Enabled = HasSections(); + + bool isManualAssembly = FailureMechanism.AssemblyResult.IsManualProbability(); + failureMechanismAssemblyProbabilityTextBox.Enabled = isManualAssembly && HasSections(); + failureMechanismAssemblyProbabilityTextBox.ReadOnly = !isManualAssembly || !HasSections(); failureMechanismAssemblyProbabilityTextBox.Refresh(); } @@ -325,7 +322,7 @@ assemblyResult.NotifyObservers(); UpdateAssemblyData(); - UpdateFailureMechanismAssemblyControls(); + UpdateFailureMechanismAssemblyResultControls(); } private void FailureMechanismAssemblyProbabilityTextBoxKeyDown(object sender, KeyEventArgs e) @@ -352,19 +349,18 @@ private void ProcessFailureMechanismAssemblyProbabilityTextBox() { - if (!IsManualAssembly()) + FailureMechanismAssemblyResult assemblyResult = FailureMechanism.AssemblyResult; + if (!assemblyResult.IsManualProbability()) { return; } try { double probability = ProbabilityParsingHelper.Parse(failureMechanismAssemblyProbabilityTextBox.Text); + assemblyResult.ManualFailureMechanismAssemblyProbability = probability; + assemblyResult.NotifyObservers(); - FailureMechanismAssemblyResult failureMechanismAssemblyResult = FailureMechanism.AssemblyResult; - failureMechanismAssemblyResult.ManualFailureMechanismAssemblyProbability = probability; - failureMechanismAssemblyResult.NotifyObservers(); - SetTextBoxValue(probability); } catch (Exception exception) when (exception is ArgumentOutOfRangeException @@ -391,11 +387,6 @@ } } - private bool IsManualAssembly() - { - return FailureMechanism.AssemblyResult.ProbabilityResultType == FailureMechanismAssemblyProbabilityResultType.Manual; - } - private void SetErrorMessage(string errorMessage) { errorProvider.SetIconPadding(failureMechanismAssemblyProbabilityTextBox, 5); Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs =================================================================== diff -u -r2de2df8b0bb65ec9f57492e08df40c5c27bc24fe -r0e9aacae86bb756ea45a965b7eab7fb735491062 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs (.../FailureMechanismResultViewTest.cs) (revision 2de2df8b0bb65ec9f57492e08df40c5c27bc24fe) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Views/FailureMechanismResultViewTest.cs (.../FailureMechanismResultViewTest.cs) (revision 0e9aacae86bb756ea45a965b7eab7fb735491062) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Windows.Forms; using Core.Common.Base; using Core.Common.Controls.DataGrid; @@ -221,48 +222,6 @@ } [Test] - public void FailureMechanismResultView_WithoutSections_ProbabilityResultTypeComboBoxDisabled() - { - // Setup - var failureMechanism = new TestFailureMechanism(); - - // Call - using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) - { - // Assert - ComboBox comboBox = GetProbabilityResultTypeComboBox(); - CollectionAssert.IsEmpty(failureMechanism.Sections); - Assert.IsFalse(comboBox.Enabled); - } - } - - [Test] - public void FailureMechanismResultView_WithSections_ProbabilityResultTypeComboBoxEnabled() - { - // Setup - var failureMechanism = new TestFailureMechanism(); - - using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) - { - // Precondition - ComboBox comboBox = GetProbabilityResultTypeComboBox(); - Assert.IsFalse(comboBox.Enabled); - - // Call - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - section - }); - - failureMechanism.NotifyObservers(); - - // Assert - Assert.IsTrue(comboBox.Enabled); - } - } - - [Test] public void GivenFailureMechanismResultView_WhenFailureMechanismObserversNotified_ThenDataGridViewUpdatedAndPerformsAssemblyCalculation() { // Given @@ -855,36 +814,9 @@ mocks.VerifyAll(); } - - [Test] - public void FailureMechanismResultViewWithoutSectionsAndProbabilityTypeManual_ReturnsCorrectError() - { - // Setup - const string expectedErrorMessage = "Om een oordeel te kunnen invoeren moet voor het faalmechanisme een vakindeling zijn geïmporteerd."; - var failureMechanism = new TestFailureMechanism - { - AssemblyResult = - { - ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Manual - } - }; - // Call - using (TestFailureMechanismResultView view = ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) - { - ErrorProvider errorProvider = GetErrorProvider(view); - TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); - string errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); - - // Assert - Assert.AreEqual(expectedErrorMessage, errorMessage); - } - } - [Test] - [TestCase(true)] - [TestCase(false)] - public void GivenFailureMechanismResultViewAndProbabilityResultTypeAutomatic_WhenProbabilityResultTypeSetToManual_ThenFailureMechanismAssemblyProbabilityTextBoxSetWithCorrectStateAndObserversNotified(bool hasSections) + public void GivenFailureMechanismResultViewAndProbabilityResultTypeAutomatic_WhenProbabilityResultTypeSetToManual_ThenFailureMechanismAssemblyProbabilityTextBoxSetWithCorrectStateAndObserversNotified() { // Given var mocks = new MockRepository(); @@ -899,14 +831,12 @@ ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic } }; - if (hasSections) + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] { - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - section - }); - } + section + }); failureMechanism.AssemblyResult.Attach(observer); @@ -916,6 +846,7 @@ // Precondition Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); // When const FailureMechanismAssemblyProbabilityResultType newResultType = FailureMechanismAssemblyProbabilityResultType.Manual; @@ -924,64 +855,14 @@ // Then Assert.AreEqual(newResultType, failureMechanism.AssemblyResult.ProbabilityResultType); - Assert.AreEqual(hasSections, failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.Enabled); Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.ReadOnly); } mocks.VerifyAll(); } [Test] - public void FailureMechanismResultView_WithoutSections_FailureMechanismAssemblyProbabilityTextBoxCorrectState() - { - // Setup - var failureMechanism = new TestFailureMechanism(); - - // Call - using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) - { - // Assert - TextBox textBox = GetFailureMechanismAssemblyProbabilityTextBox(); - CollectionAssert.IsEmpty(failureMechanism.Sections); - Assert.IsFalse(textBox.Enabled); - Assert.IsTrue(textBox.ReadOnly); - } - } - - [Test] - public void FailureMechanismResultView_WithSections_FailureMechanismAssemblyProbabilityTextBoxCorrectState() - { - // Setup - var failureMechanism = new TestFailureMechanism - { - AssemblyResult = - { - ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Manual - } - }; - - using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) - { - // Precondition - TextBox textBox = GetFailureMechanismAssemblyProbabilityTextBox(); - Assert.IsFalse(textBox.Enabled); - - // Call - FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); - FailureMechanismTestHelper.SetSections(failureMechanism, new[] - { - section - }); - - failureMechanism.NotifyObservers(); - - // Assert - Assert.IsTrue(textBox.Enabled); - Assert.IsFalse(textBox.ReadOnly); - } - } - - [Test] [SetCulture("nl-NL")] [TestCase(FailureMechanismAssemblyProbabilityResultType.Automatic, FailureMechanismAssemblyProbabilityResultType.Manual)] [TestCase(FailureMechanismAssemblyProbabilityResultType.Manual, FailureMechanismAssemblyProbabilityResultType.Automatic)] @@ -1274,5 +1155,266 @@ } #endregion + + #region FailureMechanismAssemblyResultControls + + [Test] + [TestCase(FailureMechanismAssemblyProbabilityResultType.Automatic)] + [TestCase(FailureMechanismAssemblyProbabilityResultType.Manual)] + public void FailureMechanismResultView_WithoutSections_FailureMechanismAssemblyResultsCorrectState( + FailureMechanismAssemblyProbabilityResultType resultType) + { + // Setup + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = resultType + } + }; + + // Call + using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Precondition + CollectionAssert.IsEmpty(failureMechanism.Sections); + + // Assert + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsFalse(comboBox.Enabled); + + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + [Test] + [TestCase(FailureMechanismAssemblyProbabilityResultType.Automatic)] + [TestCase(FailureMechanismAssemblyProbabilityResultType.Manual)] + public void FailureMechanismResultView_WithSections_FailureMechanismAssemblyResultsCorrectState( + FailureMechanismAssemblyProbabilityResultType resultType) + { + // Setup + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = resultType + } + }; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + section + }); + + // Call + using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Assert + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsTrue(comboBox.Enabled); + + FailureMechanismAssemblyResult assemblyResult = failureMechanism.AssemblyResult; + bool isManualAssemblyProbability = assemblyResult.IsManualProbability(); + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.AreEqual(isManualAssemblyProbability, failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.AreEqual(!isManualAssemblyProbability, failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + [Test] + public void FailureMechanismResultView_WithoutSectionsAndProbabilityTypeManual_ReturnsCorrectError() + { + // Setup + const string expectedErrorMessage = "Om een oordeel te kunnen invoeren moet voor het faalmechanisme een vakindeling zijn geïmporteerd."; + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Manual + } + }; + + // Call + using (TestFailureMechanismResultView view = ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + ErrorProvider errorProvider = GetErrorProvider(view); + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + string errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); + + // Assert + Assert.AreEqual(expectedErrorMessage, errorMessage); + } + } + + [Test] + public void GivenFailureMechanismResultViewWithoutSectionsAndProbabilityTypeManual_WhenSectionsAddedAndObserversNotified_ThenErrorUpdatedAndSetsFailureMechanismAssemblyResultsCorrectState() + { + // Given + const string initialErrorMessage = "Om een oordeel te kunnen invoeren moet voor het faalmechanisme een vakindeling zijn geïmporteerd."; + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Manual + } + }; + + using (TestFailureMechanismResultView view = ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Precondition + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + + ErrorProvider errorProvider = GetErrorProvider(view); + string errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); + Assert.AreEqual(initialErrorMessage, errorMessage); + + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsFalse(comboBox.Enabled); + + // When + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + section + }); + failureMechanism.NotifyObservers(); + + // Assert + errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); + Assert.AreNotEqual(initialErrorMessage, errorMessage); + + Assert.IsTrue(comboBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + [Test] + public void GivenFailureMechanismResultViewWithSectionsAndProbabilityTypeManual_WhenSectionsClearedAndObserversNotified_ThenErrorUpdatedAndSetsFailureMechanismAssemblyResultsCorrectState() + { + // Given + const string expectedErrorMessage = "Om een oordeel te kunnen invoeren moet voor het faalmechanisme een vakindeling zijn geïmporteerd."; + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Manual + } + }; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + section + }); + + using (TestFailureMechanismResultView view = ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Precondition + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + + ErrorProvider errorProvider = GetErrorProvider(view); + string errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); + Assert.AreNotEqual(expectedErrorMessage, errorMessage); + + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsTrue(comboBox.Enabled); + + // When + FailureMechanismTestHelper.SetSections(failureMechanism, Enumerable.Empty()); + failureMechanism.NotifyObservers(); + + // Assert + errorMessage = errorProvider.GetError(failureMechanismAssemblyProbabilityTextBox); + Assert.AreEqual(expectedErrorMessage, errorMessage); + + Assert.IsFalse(comboBox.Enabled); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + [Test] + public void GivenFailureMechanismResultViewWithoutSectionsAndProbabilityTypeAutomatic_WhenSectionsAddedAndObserversNotified_ThenFailureMechanismAssemblyResultsCorrectStateSet() + { + // Given + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic + } + }; + + using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Precondition + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsFalse(comboBox.Enabled); + + // When + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + section + }); + failureMechanism.NotifyObservers(); + + // Assert + Assert.IsTrue(comboBox.Enabled); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + [Test] + public void GivenFailureMechanismResultViewWithSectionsAndProbabilityTypeAutomatic_WhenSectionsClearedAndObserversNotified_ThenFailureMechanismAssemblyResultsCorrectStateSet() + { + // Given + var failureMechanism = new TestFailureMechanism + { + AssemblyResult = + { + ProbabilityResultType = FailureMechanismAssemblyProbabilityResultType.Automatic + } + }; + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1"); + FailureMechanismTestHelper.SetSections(failureMechanism, new[] + { + section + }); + + using (ShowFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism)) + { + // Precondition + TextBox failureMechanismAssemblyProbabilityTextBox = GetFailureMechanismAssemblyProbabilityTextBox(); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + + ComboBox comboBox = GetProbabilityResultTypeComboBox(); + Assert.IsTrue(comboBox.Enabled); + + // When + FailureMechanismTestHelper.SetSections(failureMechanism, Enumerable.Empty()); + failureMechanism.NotifyObservers(); + + // Assert + Assert.IsFalse(comboBox.Enabled); + Assert.IsFalse(failureMechanismAssemblyProbabilityTextBox.Enabled); + Assert.IsTrue(failureMechanismAssemblyProbabilityTextBox.ReadOnly); + } + } + + #endregion } } \ No newline at end of file