Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs =================================================================== diff -u -r70c6d25383da91912edb6e26dfcb748b1fe361ae -rf93e79beccdd031927870b2db114c8a140e1e3fd --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision 70c6d25383da91912edb6e26dfcb748b1fe361ae) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelLocationsViewTest.cs) (revision f93e79beccdd031927870b2db114c8a140e1e3fd) @@ -170,7 +170,7 @@ public void DesignWaterLevelLocationsView_WithNonIObservableList_ThrowsInvalidCastException() { // Setup - var view = ShowDesignWaterLevelLocationsView(); + GrassCoverErosionOutwardsDesignWaterLevelLocationsView view = ShowDesignWaterLevelLocationsView(); var locations = new List { Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs =================================================================== diff -u -r1b9d535d0b4f21bd0adb64184e5273d8bf691c4e -rf93e79beccdd031927870b2db114c8a140e1e3fd --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision 1b9d535d0b4f21bd0adb64184e5273d8bf691c4e) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightLocationsViewTest.cs) (revision f93e79beccdd031927870b2db114c8a140e1e3fd) @@ -26,6 +26,7 @@ using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Geometry; +using Core.Common.Utils.Reflection; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; @@ -97,7 +98,7 @@ public void Selection_WithLocations_ReturnsSelectedLocationWrappedInContext() { // Call - using (var view = ShowFullyConfiguredWaveHeightLocationsView()) + using (GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView()) { var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; var selectedLocationRow = dataGridView.Rows[0]; @@ -145,10 +146,27 @@ } [Test] + public void WaveHeightLocationsView_AssessmentSection_CorrectlyAttachedAndDetached() + { + // Setup + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(); + var assessmentSection = mockRepository.StrictMock(); + assessmentSection.Expect(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Expect(a => a.Detach(null)).IgnoreArguments(); + mockRepository.ReplayAll(); + + // Call + view.AssessmentSection = assessmentSection; + + // Assert + // Assertions based on mock expectancies + } + + [Test] public void WaveHeightLocationsView_WithNonIObservableList_ThrowsInvalidCastException() { // Setup - var view = ShowWaveHeightLocationsView(); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowWaveHeightLocationsView(); var locations = new List { @@ -352,6 +370,37 @@ Assert.DoesNotThrow(test); } + [Test] + [TestCase(false, false, "De bijdrage van dit toetsspoor is nul.")] + [TestCase(true, false, "De bijdrage van dit toetsspoor is nul.")] + [TestCase(false, true, "Er zijn geen berekeningen geselecteerd.")] + [TestCase(true, true, "")] + public void CalculateForSelectedButton_SpecificCombinationOfRowSelectionAndFailureMechanismContributionSet_ButtonAndErrorMessageSyncedAccordingly(bool rowSelected, bool contributionNotZero, string expectedErrorMessage) + { + // Setup & Call + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(); + + if (rowSelected) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; + } + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + if (contributionNotZero) + { + failureMechanism.Contribution = 5; + } + view.FailureMechanism = failureMechanism; + + // Assert + var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; + Assert.AreEqual(rowSelected && contributionNotZero, button.Enabled); + var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); + Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); + } + private GrassCoverErosionOutwardsWaveHeightLocationsView ShowWaveHeightLocationsView() { var view = new GrassCoverErosionOutwardsWaveHeightLocationsView(); @@ -364,7 +413,7 @@ private GrassCoverErosionOutwardsWaveHeightLocationsView ShowFullyConfiguredWaveHeightLocationsView() { - var view = ShowWaveHeightLocationsView(); + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowWaveHeightLocationsView(); ObservableList locations = new ObservableList { Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightLocationsViewIntegrationTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightLocationsViewIntegrationTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightLocationsViewIntegrationTest.cs (revision f93e79beccdd031927870b2db114c8a140e1e3fd) @@ -0,0 +1,106 @@ +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Utils.Reflection; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Forms.Views; +using Ringtoets.Integration.Data; + +namespace Ringtoets.GrassCoverErosionOutwards.Integration.Test +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveHeightLocationsViewIntegrationTest + { + private const int locationCalculateColumnIndex = 0; + + private Form testForm; + private MockRepository mockRepository; + + [SetUp] + public void Setup() + { + testForm = new Form(); + mockRepository = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(false, false, "De bijdrage van dit toetsspoor is nul.")] + [TestCase(true, false, "De bijdrage van dit toetsspoor is nul.")] + [TestCase(false, true, "Er zijn geen berekeningen geselecteerd.")] + [TestCase(true, true, "")] + public void CalculateForSelectedButton_FailureMechanismContributionChanged_ButtonAndErrorMessageSyncedAccordingly(bool rowSelected, bool contributionAfterChangeNotZero, string expectedErrorMessage) + { + // Setup + GrassCoverErosionOutwardsWaveHeightLocationsView view = ShowFullyConfiguredWaveHeightLocationsView(); + view.AssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + + if (rowSelected) + { + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + rows[0].Cells[locationCalculateColumnIndex].Value = true; + } + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + if (!contributionAfterChangeNotZero) + { + failureMechanism.Contribution = 5; + } + view.FailureMechanism = failureMechanism; + + // Precondition + var button = (Button) view.Controls.Find("CalculateForSelectedButton", true)[0]; + Assert.AreEqual(rowSelected && !contributionAfterChangeNotZero, button.Enabled); + var errorProvider = TypeUtils.GetField(view, "CalculateForSelectedButtonErrorProvider"); + Assert.AreNotEqual(expectedErrorMessage, errorProvider.GetError(button)); + + // Call + failureMechanism.Contribution = contributionAfterChangeNotZero ? 5 : 0; + view.AssessmentSection.NotifyObservers(); + + // Assert + Assert.AreEqual(rowSelected && contributionAfterChangeNotZero, button.Enabled); + Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); + } + + private GrassCoverErosionOutwardsWaveHeightLocationsView ShowWaveHeightLocationsView() + { + var view = new GrassCoverErosionOutwardsWaveHeightLocationsView(); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + + private GrassCoverErosionOutwardsWaveHeightLocationsView ShowFullyConfiguredWaveHeightLocationsView() + { + var view = ShowWaveHeightLocationsView(); + view.Data = new ObservableList + { + new HydraulicBoundaryLocation(1, "1", 1.0, 1.0), + new HydraulicBoundaryLocation(2, "2", 2.0, 2.0) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(1.23) + }, + new HydraulicBoundaryLocation(3, "3", 3.0, 3.0) + { + WaveHeightOutput = new TestHydraulicBoundaryLocationOutput(2.45) + } + }; + return view; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj =================================================================== diff -u -r70c6d25383da91912edb6e26dfcb748b1fe361ae -rf93e79beccdd031927870b2db114c8a140e1e3fd --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj) (revision 70c6d25383da91912edb6e26dfcb748b1fe361ae) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj) (revision f93e79beccdd031927870b2db114c8a140e1e3fd) @@ -62,6 +62,7 @@ Properties\GlobalAssembly.cs +