Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs =================================================================== diff -u -r29fa3a5e54e1ba71a95a4405088a8a5b87c7b3c8 -r5562ec9835fa2ad44ede7aa031e80c3e9a368445 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 29fa3a5e54e1ba71a95a4405088a8a5b87c7b3c8) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 5562ec9835fa2ad44ede7aa031e80c3e9a368445) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Controls.Views; @@ -177,7 +178,7 @@ [Test] [SetCulture("nl-NL")] - public void GivenFormWithAssemblyResultTotalView_WhenUpdateCalledAndNoExceptionThrown_ThenRowsUpdatedToNewValues() + public void GivenFormWithAssemblyResultTotalView_WhenRefreshingAssemblyResultsAndNoExceptionThrown_ThenRowsUpdatedToNewValues() { // Given var random = new Random(21); @@ -214,12 +215,45 @@ } [Test] - public void GivenAssemblyResultTotalView_WhenUpdateCalled_ThenDataGridViewInvalidated() + [SetCulture("nl-NL")] + public void GivenFormWithAssemblyResultTotalViewWithoutErrors_WhenRefreshingAssemblyResultsAndExceptionThrown_ThenErrorTextSet() { // Given var random = new Random(21); var assessmentSection = new AssessmentSection(random.NextEnumValue()); + using (new AssemblyToolCalculatorFactoryConfig()) + using (var view = new AssemblyResultTotalView(assessmentSection)) + { + testForm.Controls.Add(view); + testForm.Show(); + + var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator; + + // Precondition + var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; + DataGridViewRowCollection rows = dataGridView.Rows; + AssertFailureMechanismRowsWithoutErrorText(assessmentSection, rows); + + // When + calculator.ThrowExceptionOnCalculate = true; + const string exceptionMessage = "Message"; + var buttonTester = new ButtonTester("RefreshAssemblyResultsButton", testForm); + buttonTester.Click(); + + // Then + AssertFailureMechanismRowsWithErrorText(assessmentSection, exceptionMessage, rows); + } + } + + [Test] + public void GivenAssemblyResultTotalView_WhenRefreshingAssemblyResults_ThenDataGridViewInvalidated() + { + // Given + var random = new Random(21); + var assessmentSection = new AssessmentSection(random.NextEnumValue()); + // Then using (var view = new AssemblyResultTotalView(assessmentSection)) { @@ -305,6 +339,31 @@ AssertAssemblyRow(technicalInnovation, assemblyCategoryGroup, rows[17].Cells); } + private static void AssertFailureMechanismRowsWithoutErrorText(AssessmentSection assessmentSection, + DataGridViewRowCollection rows) + { + Assert.AreEqual(assessmentSection.GetFailureMechanisms().Count(), rows.Count); + + for (var i = 0; i < rows.Count; i++) + { + DataGridViewCell categoryGroupCell = GetCategoryGroupCellFromRow(rows[i].Cells); + Assert.IsEmpty(categoryGroupCell.ErrorText); + } + } + + private static void AssertFailureMechanismRowsWithErrorText(AssessmentSection assessmentSection, + string errorText, + DataGridViewRowCollection rows) + { + Assert.AreEqual(assessmentSection.GetFailureMechanisms().Count(), rows.Count); + + for (var i = 0; i < rows.Count; i++) + { + DataGridViewCell categoryGroupCell = GetCategoryGroupCellFromRow(rows[i].Cells); + Assert.AreEqual(errorText, categoryGroupCell.ErrorText); + } + } + private static void AssertAssemblyRow(IFailureMechanism failureMechanism, DataGridViewCellCollection row) { Assert.AreEqual(expectedColumnCount, row.Count); @@ -320,7 +379,7 @@ { AssertAssemblyRow(failureMechanism, row); - Assert.AreEqual(assemblyOutput.Group, row[failureMechanismAssemblyCategoryColumnIndex].Value); + AssertCategoryGroupCell(assemblyOutput.Group, row); Assert.AreEqual(ProbabilityFormattingHelper.Format(assemblyOutput.Probability), row[failureMechanisProbabilityColumnIndex].FormattedValue); } @@ -331,8 +390,27 @@ { AssertAssemblyRow(failureMechanism, row); - Assert.AreEqual(categoryGroup, row[failureMechanismAssemblyCategoryColumnIndex].Value); + AssertCategoryGroupCell(categoryGroup, row); Assert.AreEqual("-", row[failureMechanisProbabilityColumnIndex].FormattedValue); } + + private static void AssertCategoryGroupCell(FailureMechanismAssemblyCategoryGroup categoryGroup, DataGridViewCellCollection row) + { + DataGridViewCell categoryColumnCell = GetCategoryGroupCellFromRow(row); + + Assert.AreEqual(categoryGroup, categoryColumnCell.Value); + Assert.IsTrue(categoryColumnCell.ReadOnly); + Assert.IsEmpty(categoryColumnCell.ErrorText); + + DataGridViewCellStyle categoryColumnCellStyle = categoryColumnCell.Style; + Assert.AreEqual(AssemblyCategoryGroupColorHelper.GetFailureMechanismAssemblyCategoryGroupColor(categoryGroup), + categoryColumnCellStyle.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), categoryColumnCellStyle.ForeColor); + } + + private static DataGridViewCell GetCategoryGroupCellFromRow(DataGridViewCellCollection rowCells) + { + return rowCells[failureMechanismAssemblyCategoryColumnIndex]; + } } } \ No newline at end of file