Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/CalculationsViewSynchronizationTester.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/CalculationsViewSynchronizationTester.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/CalculationsViewSynchronizationTester.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,415 @@ +// 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.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Controls.DataGrid; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.Views; + +namespace Ringtoets.Common.Forms.TestUtil +{ + /// + /// Class for testing data and selection synchronization in derivatives. + /// + /// The type of the calculations contained by the view. + [TestFixture] + public abstract class CalculationsViewSynchronizationTester where T : class + { + private Form testForm; + + /// + /// Gets the index of the column containing the calculation output. + /// + protected abstract int OutputColumnIndex { get; } + + [SetUp] + public virtual void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + /// + /// Method for obtaining the view selection object related to the selected calculation row. + /// + /// The calculations view involved. + /// The selected calculation row object. + /// The view selection object. + protected abstract object GetCalculationSelection(CalculationsView view, object selectedRowObject); + + /// + /// Method for showing a fully configured calculations view. + /// + /// The form to use for showing the view. + /// + /// The view should contain the following calculation row data: + /// + /// Row 1: calculation without output + /// Row 2: calculation with output not containing a general result + /// Row 3: calculation with the flag for reading the general result set to true + /// Row 4: calculation with output containing a general result with two top level illustration points + /// + /// + /// The fully configured calculations view. + protected abstract CalculationsView ShowFullyConfiguredCalculationsView(Form form); + + /// + /// Method for getting the calculations in . + /// + /// The view to get the calculations from. + /// An of calculations. + protected abstract ObservableList GetCalculationsInView(CalculationsView view); + + private void ReplaceCalculationsAndNotifyObservers(CalculationsView view) + { + ObservableList calculations = GetCalculationsInView(view); + + calculations.Clear(); + calculations.Add(new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(10, "10", 10.0, 10.0))); + calculations.NotifyObservers(); + } + + private void ClearCalculationOutputAndNotifyObservers(CalculationsView view) + { + ObservableList calculations = GetCalculationsInView(view); + + calculations.ForEach(calculation => + { + calculation.Output = null; + calculation.NotifyObservers(); + }); + } + + private void SetCalculationOutputAndNotifyObservers(CalculationsView view) + { + ObservableList calculations = GetCalculationsInView(view); + + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = calculations.First(); + hydraulicBoundaryLocationCalculation.Output = new TestHydraulicBoundaryLocationOutput(new TestGeneralResultSubMechanismIllustrationPoint()); + hydraulicBoundaryLocationCalculation.NotifyObservers(); + } + + private DataGridView GetCalculationsDataGridView() + { + return ControlTestHelper.GetDataGridView(testForm, "DataGridView"); + } + + private DataGridViewControl GetCalculationsDataGridViewControl() + { + return ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl"); + } + + private IllustrationPointsControl GetIllustrationPointsControl() + { + return ControlTestHelper.GetControls(testForm, "IllustrationPointsControl").Single(); + } + + private DataGridView GetIllustrationPointsDataGridView() + { + return ControlTestHelper.GetDataGridView(GetIllustrationPointsControl(), "DataGridView"); + } + + #region Data synchronization + + [Test] + public void GivenFullyConfiguredView_WhenSelectingCalculationWithoutOutput_ThenIllustrationPointsControlDataSetToEmptyEnumeration() + { + // Given + ShowFullyConfiguredCalculationsView(testForm); + + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl calculationsDataGridViewControl = GetCalculationsDataGridViewControl(); + + // When + calculationsDataGridViewControl.SetCurrentCell(calculationsDataGridViewControl.GetCell(0, 1)); + + // Then + CollectionAssert.IsEmpty(illustrationPointsControl.Data); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingCalculationWithoutGeneralResult_ThenIllustrationPointsControlDataSetToEmptyEnumeration() + { + // Given + ShowFullyConfiguredCalculationsView(testForm); + + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl calculationsDataGridViewControl = GetCalculationsDataGridViewControl(); + + // When + calculationsDataGridViewControl.SetCurrentCell(calculationsDataGridViewControl.GetCell(1, 0)); + + // Then + CollectionAssert.IsEmpty(illustrationPointsControl.Data); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingCalculationWithGeneralResult_ThenGeneralResultSetOnIllustrationPointsControlData() + { + // Given + ShowFullyConfiguredCalculationsView(testForm); + + IllustrationPointsControl illustrationPointsControl = GetIllustrationPointsControl(); + DataGridViewControl calculationsDataGridViewControl = GetCalculationsDataGridViewControl(); + + // When + calculationsDataGridViewControl.SetCurrentCell(calculationsDataGridViewControl.GetCell(3, 0)); + + // Then + Assert.AreEqual(2, illustrationPointsControl.Data.Count()); + } + + [Test] + public void GivenFullyConfiguredViewWithFilledIllustrationPointsControl_WhenOutputCleared_ThenDataGridViewsUpdated() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + DataGridViewRowCollection dataGridViewRows = calculationsDataGridView.Rows; + calculationsDataGridView.CurrentCell = dataGridViewRows[3].Cells[0]; + + // Precondition + Assert.AreEqual(4, dataGridViewRows.Count); + Assert.AreEqual("-", dataGridViewRows[0].Cells[OutputColumnIndex].FormattedValue); + Assert.AreNotEqual("-", dataGridViewRows[1].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", dataGridViewRows[2].Cells[OutputColumnIndex].FormattedValue); + Assert.AreNotEqual("-", dataGridViewRows[3].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual(2, GetIllustrationPointsControl().Data.Count()); + + var refreshed = false; + calculationsDataGridView.Invalidated += (sender, args) => refreshed = true; + + // When + ClearCalculationOutputAndNotifyObservers(view); + + // Then + Assert.IsTrue(refreshed); + Assert.AreEqual(4, dataGridViewRows.Count); + Assert.AreEqual("-", dataGridViewRows[0].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", dataGridViewRows[1].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", dataGridViewRows[2].Cells[OutputColumnIndex].FormattedValue); + Assert.AreEqual("-", dataGridViewRows[3].Cells[OutputColumnIndex].FormattedValue); + CollectionAssert.IsEmpty(GetIllustrationPointsControl().Data); + } + + #endregion + + #region Selection synchronization + + [Test] + public void GivenFullyConfiguredView_WhenSelectingCalculation_ThenSelectionUpdated() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + + // When + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + + // Then + DataGridViewRow currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithCalculationSelection_WhenCalculationsReplaced_ThenSelectionUpdated() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + + // Precondition + DataGridViewRow currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + + // When + ReplaceCalculationsAndNotifyObservers(view); + + // Then + currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(0, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithCalculationSelection_WhenOutputCleared_ThenSelectionPreserved() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + + // Precondition + DataGridViewRow currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + + // When + ClearCalculationOutputAndNotifyObservers(view); + + // Then + currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithCalculationSelection_WhenOutputUpdated_ThenSelectionPreserved() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + + // Precondition + DataGridViewRow currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + + // When + SetCalculationOutputAndNotifyObservers(view); + + // Then + currentCalculationRow = GetCalculationsDataGridViewControl().CurrentRow; + Assert.AreEqual(3, currentCalculationRow.Index); + Assert.AreEqual(GetCalculationSelection(view, currentCalculationRow.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredView_WhenSelectingIllustrationPoint_ThenSelectionUpdated() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + + // When + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Then + AssertIllustrationPointControlSelection(view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenCalculationsReplaced_ThenSelectionSetToCalculation() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(3, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + AssertIllustrationPointControlSelection(view.Selection); + + // When + ReplaceCalculationsAndNotifyObservers(view); + + // Then + Assert.AreEqual(0, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(GetCalculationSelection(view, calculationsDataGridView.CurrentRow?.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputCleared_ThenSelectionSetToCalculation() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(3, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + AssertIllustrationPointControlSelection(view.Selection); + + // When + ClearCalculationOutputAndNotifyObservers(view); + + // Then + Assert.AreEqual(3, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(GetCalculationSelection(view, calculationsDataGridView.CurrentRow?.DataBoundItem), view.Selection); + } + + [Test] + public void GivenFullyConfiguredViewWithIllustrationPointSelection_WhenOutputUpdated_ThenSelectionPreserved() + { + // Given + CalculationsView view = ShowFullyConfiguredCalculationsView(testForm); + + DataGridView calculationsDataGridView = GetCalculationsDataGridView(); + calculationsDataGridView.CurrentCell = calculationsDataGridView.Rows[3].Cells[0]; + DataGridView illustrationPointsDataGridView = GetIllustrationPointsDataGridView(); + illustrationPointsDataGridView.CurrentCell = illustrationPointsDataGridView.Rows[1].Cells[0]; + + // Precondition + Assert.AreEqual(3, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + AssertIllustrationPointControlSelection(view.Selection); + + // When + SetCalculationOutputAndNotifyObservers(view); + + // Then + Assert.AreEqual(3, calculationsDataGridView.CurrentRow?.Index); + Assert.AreEqual(1, illustrationPointsDataGridView.CurrentRow?.Index); + AssertIllustrationPointControlSelection(view.Selection); + } + + private void AssertIllustrationPointControlSelection(object selection) + { + var illustrationPointSelection = selection as SelectedTopLevelSubMechanismIllustrationPoint; + Assert.IsNotNull(illustrationPointSelection); + Assert.AreSame(GetIllustrationPointsControl().Data.ElementAt(1).Source, illustrationPointSelection.TopLevelSubMechanismIllustrationPoint); + CollectionAssert.AreEqual(GetIllustrationPointsControl().Data.Select(data => data.ClosingSituation), illustrationPointSelection.ClosingSituations); + } + + #endregion + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/LocationsViewSynchronizationTester.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj =================================================================== diff -u -reafd42ded45d3c8c39100bc5318562f734af0302 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision eafd42ded45d3c8c39100bc5318562f734af0302) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.TestUtil/Ringtoets.Common.Forms.TestUtil.csproj (.../Ringtoets.Common.Forms.TestUtil.csproj) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -18,7 +18,7 @@ - + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewTest.cs =================================================================== diff -u -rc045873bae1b4daaf2325e9903dcf656702c24c1 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewTest.cs) (revision c045873bae1b4daaf2325e9903dcf656702c24c1) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewTest.cs (.../GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewTest.cs) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -696,7 +696,7 @@ } [TestFixture] - private class ViewSynchronizationTest : LocationsViewSynchronizationTester + private class ViewSynchronizationTest : CalculationsViewSynchronizationTester { private ObservableList calculations; Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightCalculationsViewTest.cs =================================================================== diff -u -r036dbc232fd0151d7612ea584b3b46f419b74eae -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightCalculationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightCalculationsViewTest.cs) (revision 036dbc232fd0151d7612ea584b3b46f419b74eae) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Forms.Test/Views/GrassCoverErosionOutwardsWaveHeightCalculationsViewTest.cs (.../GrassCoverErosionOutwardsWaveHeightCalculationsViewTest.cs) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -696,7 +696,7 @@ } [TestFixture] - private class ViewSynchronizationTest : LocationsViewSynchronizationTester + private class ViewSynchronizationTest : CalculationsViewSynchronizationTester { private ObservableList calculations; Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewIntegrationTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewIntegrationTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewIntegrationTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,127 @@ +// 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.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Util.Reflection; +using NUnit.Framework; +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 GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewIntegrationTest + { + private const int calculateColumnIndex = 0; + + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + [TestCase(false, false, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(false, false, message)")] + [TestCase(true, false, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(true, false, message)")] + [TestCase(false, true, "Er zijn geen berekeningen geselecteerd.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(false, true, message)")] + [TestCase(true, true, "", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(true, true, message)")] + public void GivenDesignWaterLevelLocationsView_WhenFailureMechanismContributionChanged_ThenButtonAndErrorMessageSyncedAccordingly(bool rowSelected, + bool contributionAfterChangeNotZero, + string expectedErrorMessage) + { + // Given + GrassCoverErosionOutwardsDesignWaterLevelCalculationsView view = ShowFullyConfiguredDesignWaterLevelLocationsView(); + + if (rowSelected) + { + var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true).First(); + DataGridViewRowCollection rows = dataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; + } + + GrassCoverErosionOutwardsFailureMechanism failureMechanism = view.FailureMechanism; + if (contributionAfterChangeNotZero) + { + failureMechanism.Contribution = 0; + failureMechanism.NotifyObservers(); + } + + // 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)); + + // When + failureMechanism.Contribution = contributionAfterChangeNotZero ? 5 : 0; + failureMechanism.NotifyObservers(); + + // Then + Assert.AreEqual(rowSelected && contributionAfterChangeNotZero, button.Enabled); + Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); + } + + private GrassCoverErosionOutwardsDesignWaterLevelCalculationsView ShowFullyConfiguredDesignWaterLevelLocationsView() + { + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 5 + }; + + var calculations = new ObservableList + { + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(1, "1", 1.0, 1.0)), + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(2, "2", 2.0, 2.0)) + { + Output = new TestHydraulicBoundaryLocationOutput(1.23) + }, + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(3, "3", 3.0, 3.0)) + { + Output = new TestHydraulicBoundaryLocationOutput(2.45) + } + }; + + var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(calculations, + failureMechanism, + new AssessmentSection(AssessmentSectionComposition.Dike), + () => 0.01); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightCalculationsViewIntegrationTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightCalculationsViewIntegrationTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightCalculationsViewIntegrationTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,127 @@ +// 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.Linq; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Util.Reflection; +using NUnit.Framework; +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 GrassCoverErosionOutwardsWaveHeightCalculationsViewIntegrationTest + { + private const int calculateColumnIndex = 0; + + private Form testForm; + + [SetUp] + public void Setup() + { + testForm = new Form(); + } + + [TearDown] + public void TearDown() + { + testForm.Dispose(); + } + + [Test] + [TestCase(false, false, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(false, false, message)")] + [TestCase(true, false, "De bijdrage van dit toetsspoor is nul.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(true, false, message)")] + [TestCase(false, true, "Er zijn geen berekeningen geselecteerd.", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(false, true, message)")] + [TestCase(true, true, "", TestName = "CalculateButton_ContributionChanged_SyncedAccordingly(true, true, message)")] + public void GivenWaveHeightLocationsView_WhenFailureMechanismContributionChanged_ThenButtonAndErrorMessageSyncedAccordingly(bool rowSelected, + bool contributionAfterChangeNotZero, + string expectedErrorMessage) + { + // Given + GrassCoverErosionOutwardsWaveHeightCalculationsView view = ShowFullyConfiguredWaveHeightLocationsView(); + + if (rowSelected) + { + var dataGridView = (DataGridView) view.Controls.Find("dataGridView", true).First(); + DataGridViewRowCollection rows = dataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; + } + + GrassCoverErosionOutwardsFailureMechanism failureMechanism = view.FailureMechanism; + if (contributionAfterChangeNotZero) + { + failureMechanism.Contribution = 0; + failureMechanism.NotifyObservers(); + } + + // 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)); + + // When + failureMechanism.Contribution = contributionAfterChangeNotZero ? 5 : 0; + failureMechanism.NotifyObservers(); + + // Then + Assert.AreEqual(rowSelected && contributionAfterChangeNotZero, button.Enabled); + Assert.AreEqual(expectedErrorMessage, errorProvider.GetError(button)); + } + + private GrassCoverErosionOutwardsWaveHeightCalculationsView ShowFullyConfiguredWaveHeightLocationsView() + { + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 5 + }; + + var calculations = new ObservableList + { + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(1, "1", 1.0, 1.0)), + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(2, "2", 2.0, 2.0)) + { + Output = new TestHydraulicBoundaryLocationOutput(1.23) + }, + new HydraulicBoundaryLocationCalculation(new HydraulicBoundaryLocation(3, "3", 3.0, 3.0)) + { + Output = new TestHydraulicBoundaryLocationOutput(2.45) + } + }; + + var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(calculations, + failureMechanism, + new AssessmentSection(AssessmentSectionComposition.Dike), + () => 0.01); + + testForm.Controls.Add(view); + testForm.Show(); + + return view; + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveHeightLocationsViewIntegrationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj =================================================================== diff -u -r8b8e62bfddfca997d2ed5df4a0c9c72648f1b5b4 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj) (revision 8b8e62bfddfca997d2ed5df4a0c9c72648f1b5b4) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Integration.Test.csproj) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -24,8 +24,8 @@ - - + + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test.csproj =================================================================== diff -u -r8b8e62bfddfca997d2ed5df4a0c9c72648f1b5b4 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Plugin.Test.csproj) (revision 8b8e62bfddfca997d2ed5df4a0c9c72648f1b5b4) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Plugin.Test.csproj) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -49,8 +49,8 @@ - - + + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewInfoTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,385 @@ +// 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.Collections.Generic; +using System.Drawing; +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; +using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; +using Ringtoets.GrassCoverErosionOutwards.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionOutwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class GrassCoverErosionOutwardsDesignWaterLevelCalculationsViewInfoTest + { + [Test] + public void Initialized_Always_DataTypeAndViewTypeAsExpected() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + // Call + ViewInfo info = GetInfo(plugin); + + // Assert + Assert.NotNull(info, "Expected a viewInfo definition for views with type {0}.", typeof(GrassCoverErosionOutwardsDesignWaterLevelCalculationsView)); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsDesignWaterLevelLocationsContext), info.DataType); + Assert.AreEqual(typeof(IEnumerable), info.ViewDataType); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsDesignWaterLevelCalculationsView), info.ViewType); + } + } + + [Test] + public void GetViewData_Always_ReturnWrappedDataInContext() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var expectedLocations = new ObservableList(); + + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + object locations = info.GetViewData(new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext( + expectedLocations, + assessmentSection, + new GrassCoverErosionOutwardsFailureMechanism())); + + // Assert + Assert.AreSame(locations, expectedLocations); + } + + mockRepository.VerifyAll(); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedProperties() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var mockRepository = new MockRepository(); + var gui = mockRepository.Stub(); + var window = mockRepository.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mockRepository.ReplayAll(); + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var context = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext( + new ObservableList(), + assessmentSection, + grassCoverErosionOutwardsFailureMechanism); + + plugin.Gui = gui; + plugin.Activate(); + + // Call + var view = (GrassCoverErosionOutwardsDesignWaterLevelCalculationsView) info.CreateInstance(context); + + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + + mockRepository.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + string name = info.GetViewName(null, null); + + // Assert + Assert.AreEqual(Resources.GrassCoverErosionOutwardsWaterLevelLocations_DisplayName, name); + } + } + + [Test] + public void AfterCreate_Always_SetsExpectedProperties() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + var gui = mockRepository.Stub(); + var window = mockRepository.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mockRepository.ReplayAll(); + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var data = new GrassCoverErosionOutwardsDesignWaterLevelLocationsContext( + new ObservableList(), + assessmentSection, + grassCoverErosionOutwardsFailureMechanism); + + plugin.Gui = gui; + plugin.Activate(); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + grassCoverErosionOutwardsFailureMechanism, + assessmentSection, + () => 0.01)) + { + // Call + info.AfterCreate(view, data); + + // Assert + Assert.AreSame(grassCoverErosionOutwardsFailureMechanism, view.FailureMechanism); + Assert.IsInstanceOf(view.CalculationGuiService); + } + } + + mockRepository.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + failureMechanism, + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + failureMechanism, + assessmentSectionA, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingFailureMechanismContext_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingFailureMechanismContext_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionB); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionA, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsDesignWaterLevelCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + private static ViewInfo GetInfo(PluginBase plugin) + { + return plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(GrassCoverErosionOutwardsDesignWaterLevelCalculationsView)); + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsDesignWaterLevelLocationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightCalculationsViewInfoTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,381 @@ +// 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.Collections.Generic; +using System.Drawing; +using System.Linq; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; +using Ringtoets.GrassCoverErosionOutwards.Forms.Properties; +using Ringtoets.GrassCoverErosionOutwards.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.GrassCoverErosionOutwards.Plugin.Test.ViewInfos +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveHeightCalculationsViewInfoTest + { + [Test] + public void Initialized_Always_DataTypeAndViewTypeAsExpected() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + // Call + ViewInfo info = GetInfo(plugin); + + // Assert + Assert.NotNull(info, "Expected a viewInfo definition for views with type {0}.", typeof(GrassCoverErosionOutwardsWaveHeightCalculationsView)); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsWaveHeightLocationsContext), info.DataType); + Assert.AreEqual(typeof(IEnumerable), info.ViewDataType); + Assert.AreEqual(typeof(GrassCoverErosionOutwardsWaveHeightCalculationsView), info.ViewType); + } + } + + [Test] + public void GetViewData_Always_ReturnWrappedDataInContext() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var expectedLocations = new ObservableList(); + + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + object locations = info.GetViewData(new GrassCoverErosionOutwardsWaveHeightLocationsContext( + expectedLocations, + assessmentSection, + new GrassCoverErosionOutwardsFailureMechanism())); + + // Assert + Assert.AreSame(locations, expectedLocations); + } + + mockRepository.VerifyAll(); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedProperties() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var mockRepository = new MockRepository(); + var gui = mockRepository.Stub(); + var window = mockRepository.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mockRepository.ReplayAll(); + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var context = new GrassCoverErosionOutwardsWaveHeightLocationsContext( + new ObservableList(), + assessmentSection, + grassCoverErosionOutwardsFailureMechanism); + + plugin.Gui = gui; + plugin.Activate(); + + // Call + var view = (GrassCoverErosionOutwardsWaveHeightCalculationsView) info.CreateInstance(context); + + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + + mockRepository.VerifyAll(); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + } + + [Test] + public void GetViewName_Always_ReturnsViewName() + { + // Setup + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + string name = info.GetViewName(null, null); + + // Assert + Assert.AreEqual(Resources.GrassCoverErosionOutwardsWaveHeightLocationsContext_DisplayName, name); + } + } + + [Test] + public void AfterCreate_Always_SetsExpectedProperties() + { + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + var gui = mockRepository.Stub(); + var window = mockRepository.Stub(); + gui.Stub(gs => gs.MainWindow).Return(window); + mockRepository.ReplayAll(); + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + var data = new GrassCoverErosionOutwardsWaveHeightLocationsContext( + new ObservableList(), + assessmentSection, + failureMechanism); + plugin.Gui = gui; + plugin.Activate(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + failureMechanism, + assessmentSection, + () => 0.01)) + { + info.AfterCreate(view, data); + + // Assert + Assert.AreSame(failureMechanism, view.FailureMechanism); + Assert.IsInstanceOf(view.CalculationGuiService); + } + } + + mockRepository.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + failureMechanism, + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + failureMechanism + }); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + failureMechanism, + assessmentSectionA, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingFailureMechanismContext_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsTrue(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForNonMatchingFailureMechanismContext_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSectionA = mocks.Stub(); + var assessmentSectionB = mocks.Stub(); + assessmentSectionA.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSectionA.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSectionA.Stub(a => a.Detach(null)).IgnoreArguments(); + assessmentSectionB.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + mocks.ReplayAll(); + + var grassCoverErosionOutwardsFailureMechanismContext = new GrassCoverErosionOutwardsFailureMechanismContext( + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionB); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSectionA, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, grassCoverErosionOutwardsFailureMechanismContext); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[] + { + new GrassCoverErosionOutwardsFailureMechanism() + }); + assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); + assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); + mocks.ReplayAll(); + + using (var view = new GrassCoverErosionOutwardsWaveHeightCalculationsView(new ObservableList(), + new GrassCoverErosionOutwardsFailureMechanism(), + assessmentSection, + () => 0.01)) + using (var plugin = new GrassCoverErosionOutwardsPlugin()) + { + ViewInfo info = GetInfo(plugin); + + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + + mocks.VerifyAll(); + } + + private static ViewInfo GetInfo(PluginBase plugin) + { + return plugin.GetViewInfos().FirstOrDefault(vi => vi.ViewType == typeof(GrassCoverErosionOutwardsWaveHeightCalculationsView)); + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ViewInfos/GrassCoverErosionOutwardsWaveHeightLocationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelCalculationsViewTest.cs =================================================================== diff -u -r8f71111fae4dc2d04afae34491748404c0466ce8 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelCalculationsViewTest.cs (.../DesignWaterLevelCalculationsViewTest.cs) (revision 8f71111fae4dc2d04afae34491748404c0466ce8) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/DesignWaterLevelCalculationsViewTest.cs (.../DesignWaterLevelCalculationsViewTest.cs) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -653,7 +653,7 @@ } [TestFixture] - private class ViewSynchronizationTest : LocationsViewSynchronizationTester + private class ViewSynchronizationTest : CalculationsViewSynchronizationTester { private ObservableList calculations; Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightCalculationsViewTest.cs =================================================================== diff -u -r8f71111fae4dc2d04afae34491748404c0466ce8 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightCalculationsViewTest.cs (.../WaveHeightCalculationsViewTest.cs) (revision 8f71111fae4dc2d04afae34491748404c0466ce8) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/WaveHeightCalculationsViewTest.cs (.../WaveHeightCalculationsViewTest.cs) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -653,7 +653,7 @@ } [TestFixture] - public class ViewSynchronizationTest : LocationsViewSynchronizationTester + public class ViewSynchronizationTest : CalculationsViewSynchronizationTester { private ObservableList calculations; Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj =================================================================== diff -u -r277474bff827855e198867eb1a794ec7f44d54b2 -r682dfada6e821a0dd7cf3f6be9a2823eb72d9302 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 277474bff827855e198867eb1a794ec7f44d54b2) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Ringtoets.Integration.Plugin.Test.csproj (.../Ringtoets.Integration.Plugin.Test.csproj) (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -99,7 +99,7 @@ - + @@ -109,7 +109,7 @@ - + Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelCalculationsViewInfoTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,376 @@ +// 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; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Commands; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.Common.Forms.TestUtil; +using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Integration.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Test.ViewInfos +{ + [TestFixture] + public class DesignWaterLevelCalculationsViewInfoTest + { + private const int calculateColumnIndex = 0; + private const int designWaterLevelColumnIndex = 5; + + private RingtoetsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + plugin = new RingtoetsPlugin(); + info = GetViewInfo(plugin); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void GetViewName_WithDesignWaterLevelLocationsContext_ReturnsViewNameContainingCategoryBoundaryName() + { + // Setup + const string categoryBoundaryName = "Category"; + + var context = new DesignWaterLevelLocationsContext(new ObservableList(), + new ObservableTestAssessmentSectionStub(), + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + categoryBoundaryName); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual($"Toetspeilen - {categoryBoundaryName}", viewName); + } + + [Test] + public void ViewDataType_Always_ReturnsViewDataType() + { + // Call + Type viewDataType = info.ViewDataType; + + // Assert + Assert.AreEqual(typeof(IEnumerable), viewDataType); + } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + Type dataType = info.DataType; + + // Assert + Assert.AreEqual(typeof(DesignWaterLevelLocationsContext), dataType); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void GetViewData_Always_ReturnsHydraulicBoundaryLocations() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + ObservableList locations = assessmentSection.HydraulicBoundaryDatabase.Locations; + var context = new DesignWaterLevelLocationsContext(locations, + assessmentSection, + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + "Category"); + + // Call + object viewData = info.GetViewData(context); + + // Assert + Assert.AreSame(locations, viewData); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedViewProperties() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var context = new DesignWaterLevelLocationsContext(new ObservableList(), + assessmentSection, + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + "Category"); + + // Call + var view = (DesignWaterLevelCalculationsView) info.CreateInstance(context); + + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedDataGridViewData() + { + // Setup + var random = new Random(); + + var hydraulicBoundaryLocations = new ObservableList + { + new TestHydraulicBoundaryLocation(), + new TestHydraulicBoundaryLocation() + }; + + var hydraulicBoundaryLocationCalculations = new[] + { + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocations[0]) + { + Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) + }, + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocations[1]) + { + Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) + } + }; + + var context = new DesignWaterLevelLocationsContext(hydraulicBoundaryLocations, + new ObservableTestAssessmentSectionStub(), + () => 0.01, + hbl => hydraulicBoundaryLocationCalculations.First(hblc => ReferenceEquals(hblc.HydraulicBoundaryLocation, hbl)), + "Category"); + + // Call + var view = (DesignWaterLevelCalculationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) + { + testForm.Controls.Add(view); + testForm.Show(); + + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + Assert.AreEqual(2, rows.Count); + Assert.AreEqual(hydraulicBoundaryLocationCalculations[0].Output.Result.ToString(), rows[0].Cells[designWaterLevelColumnIndex].FormattedValue); + Assert.AreEqual(hydraulicBoundaryLocationCalculations[1].Output.Result.ToString(), rows[1].Cells[designWaterLevelColumnIndex].FormattedValue); + } + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedCalculationData() + { + // Setup + Func getNormFunc = () => 0.01; + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation); + var hydraulicBoundaryLocations = new ObservableList + { + hydraulicBoundaryLocation + }; + + Func getCalculationFunc = hbl => hydraulicBoundaryLocationCalculation; + + var context = new DesignWaterLevelLocationsContext(hydraulicBoundaryLocations, + new ObservableTestAssessmentSectionStub(), + getNormFunc, + getCalculationFunc, + "Category"); + + var mockRepository = new MockRepository(); + var guiService = mockRepository.StrictMock(); + + double actualNormValue = double.NaN; + IEnumerable performedCalculations = null; + guiService.Expect(ch => ch.CalculateDesignWaterLevels(null, null, null, int.MinValue, null)).IgnoreArguments().WhenCalled( + invocation => + { + performedCalculations = (IEnumerable) invocation.Arguments[2]; + actualNormValue = (double) invocation.Arguments[3]; + }); + + mockRepository.ReplayAll(); + + // Call + var view = (DesignWaterLevelCalculationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) + { + view.CalculationGuiService = guiService; + testForm.Controls.Add(view); + testForm.Show(); + + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; + + view.CalculationGuiService = guiService; + var button = new ButtonTester("CalculateForSelectedButton", testForm); + + button.Click(); + + Assert.AreEqual(getNormFunc(), actualNormValue); + Assert.AreSame(hydraulicBoundaryLocationCalculation, performedCalculations.First()); + } + + mockRepository.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView() + { + // Setup + var mocks = new MockRepository(); + var gui = mocks.Stub(); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.DocumentViewController).Return(mocks.Stub()); + mocks.ReplayAll(); + + Func getNormFunc = () => 0.01; + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var locations = new ObservableList(); + + const string categoryBoundaryName = "Category"; + + Func getCalculationFunc = hbl => new HydraulicBoundaryLocationCalculation(hbl); + + var context = new DesignWaterLevelLocationsContext(locations, + assessmentSection, + getNormFunc, + getCalculationFunc, + categoryBoundaryName); + + using (var view = new DesignWaterLevelCalculationsView(new ObservableList(), + new ObservableTestAssessmentSectionStub(), + getNormFunc, + categoryBoundaryName)) + + using (var ringtoetsPlugin = new RingtoetsPlugin()) + { + ViewInfo viewInfo = GetViewInfo(ringtoetsPlugin); + ringtoetsPlugin.Gui = gui; + ringtoetsPlugin.Activate(); + + // Call + viewInfo.AfterCreate(view, context); + + // Assert + Assert.IsInstanceOf(view.CalculationGuiService); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + + using (var view = new DesignWaterLevelCalculationsView(new ObservableList(), + assessmentSection, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSectionA = new ObservableTestAssessmentSectionStub(); + var assessmentSectionB = new ObservableTestAssessmentSectionStub(); + + using (var view = new DesignWaterLevelCalculationsView(new ObservableList(), + assessmentSectionA, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var assessmentSectionA = new ObservableTestAssessmentSectionStub(); + + using (var view = new DesignWaterLevelCalculationsView(new ObservableList(), + assessmentSectionA, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + } + + private static ViewInfo GetViewInfo(RingtoetsPlugin plugin) + { + return plugin.GetViewInfos().First(tni => tni.ViewType == typeof(DesignWaterLevelCalculationsView)); + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/DesignWaterLevelLocationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightCalculationsViewInfoTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightCalculationsViewInfoTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightCalculationsViewInfoTest.cs (revision 682dfada6e821a0dd7cf3f6be9a2823eb72d9302) @@ -0,0 +1,378 @@ +// 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; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Threading; +using System.Windows.Forms; +using Core.Common.Base; +using Core.Common.Gui; +using Core.Common.Gui.Commands; +using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.ViewHost; +using Core.Common.Gui.Plugin; +using Core.Common.TestUtil; +using NUnit.Extensions.Forms; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Forms.GuiServices; +using Ringtoets.Common.Forms.TestUtil; +using Ringtoets.Integration.Forms.PresentationObjects; +using Ringtoets.Integration.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; + +namespace Ringtoets.Integration.Plugin.Test.ViewInfos +{ + [TestFixture] + public class WaveHeightCalculationsViewInfoTest + { + private const int calculateColumnIndex = 0; + private const int waveHeightColumnIndex = 5; + + private RingtoetsPlugin plugin; + private ViewInfo info; + + [SetUp] + public void SetUp() + { + plugin = new RingtoetsPlugin(); + info = GetViewInfo(plugin); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void GetViewName_WithWaveHeightLocationsContext_ReturnsViewNameContainingCategoryBoundaryName() + { + // Setup + const string categoryBoundaryName = "Category"; + + var context = new WaveHeightLocationsContext(new ObservableList(), + new ObservableTestAssessmentSectionStub(), + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + categoryBoundaryName); + + // Call + string viewName = info.GetViewName(null, context); + + // Assert + Assert.AreEqual($"Golfhoogtes - {categoryBoundaryName}", viewName); + } + + [Test] + public void ViewDataType_Always_ReturnsViewDataType() + { + // Call + Type viewDataType = info.ViewDataType; + + // Assert + Assert.AreEqual(typeof(IEnumerable), viewDataType); + } + + [Test] + public void DataType_Always_ReturnsDataType() + { + // Call + Type dataType = info.DataType; + + // Assert + Assert.AreEqual(typeof(WaveHeightLocationsContext), dataType); + } + + [Test] + public void Image_Always_ReturnsGenericInputOutputIcon() + { + // Call + Image image = info.Image; + + // Assert + TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GenericInputOutputIcon, image); + } + + [Test] + public void GetViewData_Always_ReturnsHydraulicBoundaryLocations() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + ObservableList locations = assessmentSection.HydraulicBoundaryDatabase.Locations; + + var context = new WaveHeightLocationsContext(locations, + assessmentSection, + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + "Category"); + + // Call + object viewData = info.GetViewData(context); + + // Assert + Assert.AreSame(locations, viewData); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedViewProperties() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var context = new WaveHeightLocationsContext(new ObservableList(), + assessmentSection, + () => 0.01, + hbl => new HydraulicBoundaryLocationCalculation(hbl), + "Category"); + + // Call + var view = (WaveHeightCalculationsView) info.CreateInstance(context); + + // Assert + Assert.AreSame(assessmentSection, view.AssessmentSection); + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedDataGridViewData() + { + // Setup + var random = new Random(); + + var hydraulicBoundaryLocations = new ObservableList + { + new TestHydraulicBoundaryLocation(), + new TestHydraulicBoundaryLocation() + }; + + var hydraulicBoundaryLocationCalculations = new[] + { + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocations[0]) + { + Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) + }, + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocations[1]) + { + Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) + } + }; + + var context = new WaveHeightLocationsContext(hydraulicBoundaryLocations, + new ObservableTestAssessmentSectionStub(), + () => 0.01, + hbl => hydraulicBoundaryLocationCalculations.First(hblc => ReferenceEquals(hblc.HydraulicBoundaryLocation, hbl)), + "Category"); + + // Call + var view = (WaveHeightCalculationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) + { + testForm.Controls.Add(view); + testForm.Show(); + + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + Assert.AreEqual(2, rows.Count); + Assert.AreEqual(hydraulicBoundaryLocationCalculations[0].Output.Result.ToString(), rows[0].Cells[waveHeightColumnIndex].FormattedValue); + Assert.AreEqual(hydraulicBoundaryLocationCalculations[1].Output.Result.ToString(), rows[1].Cells[waveHeightColumnIndex].FormattedValue); + } + } + + [Test] + public void CreateInstance_WithContext_SetsExpectedCalculationData() + { + // Setup + Func getNormFunc = () => 0.01; + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation); + var hydraulicBoundaryLocations = new ObservableList + { + hydraulicBoundaryLocation + }; + + Func getCalculationFunc = hbl => hydraulicBoundaryLocationCalculation; + + var context = new WaveHeightLocationsContext(hydraulicBoundaryLocations, + new ObservableTestAssessmentSectionStub(), + getNormFunc, + getCalculationFunc, + "Category"); + + var mockRepository = new MockRepository(); + var guiService = mockRepository.StrictMock(); + + double actualNormValue = double.NaN; + IEnumerable performedCalculations = null; + guiService.Expect(ch => ch.CalculateWaveHeights(null, null, null, int.MinValue, null)).IgnoreArguments().WhenCalled( + invocation => + { + performedCalculations = (IEnumerable) invocation.Arguments[2]; + actualNormValue = (double) invocation.Arguments[3]; + }); + + mockRepository.ReplayAll(); + + // Call + var view = (WaveHeightCalculationsView) info.CreateInstance(context); + + // Assert + using (var testForm = new Form()) + { + view.CalculationGuiService = guiService; + testForm.Controls.Add(view); + testForm.Show(); + + DataGridView locationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView"); + DataGridViewRowCollection rows = locationsDataGridView.Rows; + rows[0].Cells[calculateColumnIndex].Value = true; + + view.CalculationGuiService = guiService; + var button = new ButtonTester("CalculateForSelectedButton", testForm); + + button.Click(); + + Assert.AreEqual(getNormFunc(), actualNormValue); + Assert.AreSame(hydraulicBoundaryLocationCalculation, performedCalculations.First()); + } + + mockRepository.VerifyAll(); + } + + [Test] + [Apartment(ApartmentState.STA)] + public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView() + { + // Setup + var mocks = new MockRepository(); + var gui = mocks.Stub(); + gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); + gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.DocumentViewController).Return(mocks.Stub()); + + mocks.ReplayAll(); + + Func getNormFunc = () => 0.01; + var assessmentSection = new ObservableTestAssessmentSectionStub(); + var locations = new ObservableList(); + + const string categoryBoundaryName = "Category"; + + Func getCalculationFunc = hbl => new HydraulicBoundaryLocationCalculation(hbl); + + var context = new WaveHeightLocationsContext(locations, + assessmentSection, + getNormFunc, + getCalculationFunc, + categoryBoundaryName); + + using (var view = new WaveHeightCalculationsView(new ObservableList(), + assessmentSection, + getNormFunc, + categoryBoundaryName)) + + using (var ringtoetsPlugin = new RingtoetsPlugin()) + { + ViewInfo viewInfo = GetViewInfo(ringtoetsPlugin); + ringtoetsPlugin.Gui = gui; + ringtoetsPlugin.Activate(); + + // Call + viewInfo.AfterCreate(view, context); + + // Assert + Assert.IsInstanceOf(view.CalculationGuiService); + } + + mocks.VerifyAll(); + } + + [Test] + public void CloseViewForData_ForMatchingAssessmentSection_ReturnsTrue() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + + using (var view = new WaveHeightCalculationsView(new ObservableList(), + assessmentSection, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSection); + + // Assert + Assert.IsTrue(closeForData); + } + } + + [Test] + public void CloseViewForData_ForNonMatchingAssessmentSection_ReturnsFalse() + { + // Setup + var assessmentSectionA = new ObservableTestAssessmentSectionStub(); + var assessmentSectionB = new ObservableTestAssessmentSectionStub(); + + using (var view = new WaveHeightCalculationsView(new ObservableList(), + assessmentSectionA, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, assessmentSectionB); + + // Assert + Assert.IsFalse(closeForData); + } + } + + [Test] + public void CloseViewForData_ForOtherObjectType_ReturnsFalse() + { + // Setup + var assessmentSectionA = new ObservableTestAssessmentSectionStub(); + + using (var view = new WaveHeightCalculationsView(new ObservableList(), + assessmentSectionA, + () => 0.01, + "Category")) + { + // Call + bool closeForData = info.CloseForData(view, new object()); + + // Assert + Assert.IsFalse(closeForData); + } + } + + private static ViewInfo GetViewInfo(RingtoetsPlugin plugin) + { + return plugin.GetViewInfos().First(tni => tni.ViewType == typeof(WaveHeightCalculationsView)); + } + } +} \ No newline at end of file Fisheye: Tag 682dfada6e821a0dd7cf3f6be9a2823eb72d9302 refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/ViewInfos/WaveHeightLocationsViewInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff?