Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismResultWithProbabilityTester.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismResultWithProbabilityTester.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/FailureMechanismResultWithProbabilityTester.cs (revision 967ba9221cb505caf8d8f5afd3a0e0aee9664e30)
@@ -0,0 +1,251 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets 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.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using NUnit.Extensions.Forms;
+using NUnit.Framework;
+using Ringtoets.AssemblyTool.Data;
+using Ringtoets.AssemblyTool.KernelWrapper.Calculators;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators;
+using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly;
+using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.FailureMechanism;
+using Ringtoets.Common.Data.TestUtil;
+using Ringtoets.Common.Forms.Controls;
+using Ringtoets.Common.Forms.Views;
+
+namespace Ringtoets.Common.Forms.TestUtil
+{
+ ///
+ /// Class for testing data and styling in a view with a .
+ ///
+ /// The type of the view to test.
+ /// The type of the failure mechanism the view belongs to.
+ /// The type of the section results shown in the view.
+ /// The type of the presentation objects used in the view.
+ /// The type of calculations to get the input from.
+ /// The type of the input of a calculation.
+ public abstract class FailureMechanismResultWithProbabilityTester
+ where TView : FailureMechanismResultView
+ where TFailureMechanism : IFailureMechanism, IHasSectionResults, ICalculatableFailureMechanism, new()
+ where TSectionResult : FailureMechanismSectionResult
+ where TResultRow : FailureMechanismSectionResultRow
+ where TCalculation : ICalculation
+ where TCalculationInput : ICalculationInput
+ {
+ private Form testForm;
+
+ [SetUp]
+ public void Setup()
+ {
+ testForm = new Form();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ testForm.Dispose();
+ }
+
+ [Test]
+ public void FailureMechanismResultsView_Always_FailureMechanismResultControlCorrectlyInitialized()
+ {
+ // Setup
+ var failureMechanism = new TFailureMechanism();
+ failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());
+
+ // Call
+ using (new AssemblyToolCalculatorFactoryConfig())
+ using (ShowFailureMechanismResultsView(failureMechanism))
+ {
+ // Assert
+ var assemblyResultPanel = (TableLayoutPanel) new ControlTester("TableLayoutPanel").TheObject;
+ var assemblyResultControl = (FailureMechanismAssemblyResultWithProbabilityControl) assemblyResultPanel.GetControlFromPosition(0, 0);
+
+ Assert.IsInstanceOf(assemblyResultControl);
+ Assert.AreEqual(DockStyle.Left, assemblyResultControl.Dock);
+ }
+ }
+
+ [Test]
+ public void GivenFailureMechanismResultsView_WhenCalculatorThrowsException_FailureMechanismAssemblyResultCleared()
+ {
+ // Given
+ var failureMechanism = new TFailureMechanism();
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ using (ShowFailureMechanismResultsView(failureMechanism))
+ {
+ // Precondition
+ BoxedLabel assemblyGroupLabel = GetGroupLabel();
+ BoxedLabel assemblyProbabilityLabel = GetProbabilityLabelControl();
+ Assert.AreEqual("1/1", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("IIIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 255, 0), assemblyGroupLabel.BackColor);
+
+ // When
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.ThrowExceptionOnCalculate = true;
+ failureMechanism.NotifyObservers();
+
+ // Assert
+ Assert.AreEqual("-", assemblyProbabilityLabel.Text);
+ Assert.IsEmpty(assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.White, assemblyGroupLabel.BackColor);
+ }
+ }
+
+ [Test]
+ public void GivenFailureMechanismResultsView_WhenResultChangedAndSectionResultNotified_FailureMechanismAssemblyResultUpdated()
+ {
+ // Given
+ var failureMechanism = new TFailureMechanism();
+ failureMechanism.AddSection(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ using (ShowFailureMechanismResultsView(failureMechanism))
+ {
+ // Precondition
+ BoxedLabel assemblyGroupLabel = GetGroupLabel();
+ BoxedLabel assemblyProbabilityLabel = GetProbabilityLabelControl();
+ Assert.AreEqual("1/1", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("IIIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 255, 0), assemblyGroupLabel.BackColor);
+
+ // When
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.FailureMechanismAssemblyOutput = new FailureMechanismAssembly(0.5, FailureMechanismAssemblyCategoryGroup.VIt);
+ failureMechanism.SectionResults.Single().NotifyObservers();
+
+ // Assert
+ Assert.AreEqual("1/2", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("VIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 0, 0), assemblyGroupLabel.BackColor);
+ }
+ }
+
+ [Test]
+ public void GivenFailureMechanismResultsView_WhenResultChangedAndCalculationNotified_FailureMechanismAssemblyResultUpdated()
+ {
+ // Given
+ var failureMechanism = new TFailureMechanism();
+ TCalculation calculation = CreateCalculationScenario();
+ failureMechanism.CalculationsGroup.Children.Add(calculation);
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ using (ShowFailureMechanismResultsView(failureMechanism))
+ {
+ // Precondition
+ BoxedLabel assemblyGroupLabel = GetGroupLabel();
+ BoxedLabel assemblyProbabilityLabel = GetProbabilityLabelControl();
+ Assert.AreEqual("1/1", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("IIIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 255, 0), assemblyGroupLabel.BackColor);
+
+ // When
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.FailureMechanismAssemblyOutput = new FailureMechanismAssembly(0.5, FailureMechanismAssemblyCategoryGroup.VIt);
+ calculation.NotifyObservers();
+
+ // Assert
+ Assert.AreEqual("1/2", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("VIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 0, 0), assemblyGroupLabel.BackColor);
+ }
+ }
+
+ [Test]
+ public void GivenFailureMechanismResultsView_WhenResultChangedAndCalculationInputNotified_FailureMechanismAssemblyResultUpdated()
+ {
+ // Given
+ var failureMechanism = new TFailureMechanism();
+ TCalculation calculation = CreateCalculationScenario();
+ failureMechanism.CalculationsGroup.Children.Add(calculation);
+
+ using (new AssemblyToolCalculatorFactoryConfig())
+ using (ShowFailureMechanismResultsView(failureMechanism))
+ {
+ // Precondition
+ BoxedLabel assemblyGroupLabel = GetGroupLabel();
+ BoxedLabel assemblyProbabilityLabel = GetProbabilityLabelControl();
+ Assert.AreEqual("1/1", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("IIIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 255, 0), assemblyGroupLabel.BackColor);
+
+ // When
+ var calculatorfactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance;
+ FailureMechanismAssemblyCalculatorStub calculator = calculatorfactory.LastCreatedFailureMechanismAssemblyCalculator;
+ calculator.FailureMechanismAssemblyOutput = new FailureMechanismAssembly(0.5, FailureMechanismAssemblyCategoryGroup.VIt);
+ GetInput(failureMechanism.CalculationsGroup.Children.Cast().Single()).NotifyObservers();
+
+ // Assert
+ Assert.AreEqual("1/2", assemblyProbabilityLabel.Text);
+ Assert.AreEqual("VIt", assemblyGroupLabel.Text);
+ Assert.AreEqual(Color.FromArgb(255, 0, 0), assemblyGroupLabel.BackColor);
+ }
+ }
+
+ ///
+ /// Method for creating an instance of .
+ ///
+ /// The failure mechanism to create the view for.
+ /// A new .
+ protected abstract TView CreateResultView(TFailureMechanism failureMechanism);
+
+ ///
+ /// Method for creating an instance of .
+ ///
+ /// A new .
+ protected abstract TCalculation CreateCalculationScenario();
+
+ ///
+ /// Method to get the from a
+ /// .
+ ///
+ /// The calculation to get the input from.
+ /// A new .
+ protected abstract TCalculationInput GetInput(TCalculation calculation);
+
+ private static BoxedLabel GetGroupLabel()
+ {
+ return (BoxedLabel) new ControlTester("GroupLabel").TheObject;
+ }
+
+ private static BoxedLabel GetProbabilityLabelControl()
+ {
+ return (BoxedLabel) new ControlTester("probabilityLabel").TheObject;
+ }
+
+ private TView ShowFailureMechanismResultsView(TFailureMechanism failureMechanism)
+ {
+ TView failureMechanismResultView = CreateResultView(failureMechanism);
+ testForm.Controls.Add(failureMechanismResultView);
+ testForm.Show();
+
+ return failureMechanismResultView;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj
===================================================================
diff -u -rcbd59f2213a5cfac87c5af5039ff452ac9f39251 -r967ba9221cb505caf8d8f5afd3a0e0aee9664e30
--- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision cbd59f2213a5cfac87c5af5039ff452ac9f39251)
+++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision 967ba9221cb505caf8d8f5afd3a0e0aee9664e30)
@@ -11,13 +11,19 @@
..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll
True
+
+ False
+ ..\..\..\..\lib\NUnitForms.dll
+
+
+
@@ -62,6 +68,14 @@
{420ED9C3-0C33-47EA-B893-121A9C0DB4F1}
Ringtoets.AssemblyTool.Data
+
+ {358B6DA2-A1DF-477F-B6AC-C30204265CB0}
+ Ringtoets.AssemblyTool.KernelWrapper
+
+
+ {0AB432BB-E2CC-42EA-A72C-7AFEF7536B38}
+ Ringtoets.AssemblyTool.KernelWrapper.TestUtil
+
{D4200F43-3F72-4F42-AF0A-8CED416A38EC}
Ringtoets.Common.Data