Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs =================================================================== diff -u -r28e867674791c1111107ea44e960313f43fc6aea -rcd7fd343b85d2c9272033a59a0f1bc50bc8a8d0d --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision 28e867674791c1111107ea44e960313f43fc6aea) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/HydraulicBoundaryLocationsViewTest.cs (.../HydraulicBoundaryLocationsViewTest.cs) (revision cd7fd343b85d2c9272033a59a0f1bc50bc8a8d0d) @@ -25,25 +25,29 @@ using System.Windows.Forms; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.Base.Geometry; using Core.Common.Controls.Views; using Core.Common.Gui.Selection; -using Core.Common.Utils.Reflection; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; -using Ringtoets.Integration.Forms.Commands; +using Ringtoets.Integration.Forms.GuiServices; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.Views; namespace Ringtoets.Integration.Forms.Test.Views { + [TestFixture] public class HydraulicBoundaryLocationsViewTest { private const int locationCalculateColumnIndex = 0; + private const int locationNameColumnIndex = 1; + private const int locationIdColumnIndex = 2; + private const int locationColumnIndex = 3; private Form testForm; [SetUp] @@ -66,7 +70,7 @@ { // Assert Assert.IsInstanceOf(view); - Assert.IsInstanceOf(view); + Assert.IsInstanceOf(view); Assert.IsNull(view.Data); } } @@ -83,6 +87,37 @@ } [Test] + public void Constructor_DataGridViewCorrectlyInitialized() + { + // Setup & Call + ShowTestHydraulicBoundaryLocationsView(); + + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + Assert.AreEqual(4, dataGridView.ColumnCount); + + var locationCalculateColumn = (DataGridViewCheckBoxColumn) dataGridView.Columns[locationCalculateColumnIndex]; + const string expectedLocationCalculateHeaderText = "Berekenen"; + Assert.AreEqual(expectedLocationCalculateHeaderText, locationCalculateColumn.HeaderText); + + var locationNameColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[locationNameColumnIndex]; + const string expectedLocationNameHeaderText = "Naam"; + Assert.AreEqual(expectedLocationNameHeaderText, locationNameColumn.HeaderText); + + var locationIdColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[locationIdColumnIndex]; + const string expectedLocationIdHeaderText = "ID"; + Assert.AreEqual(expectedLocationIdHeaderText, locationIdColumn.HeaderText); + + var locationColumn = (DataGridViewTextBoxColumn) dataGridView.Columns[locationColumnIndex]; + const string expectedLocationHeaderText = "Coördinaten [m]"; + Assert.AreEqual(expectedLocationHeaderText, locationColumn.HeaderText); + + var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); + var button = (Button) buttonTester.TheObject; + Assert.IsFalse(button.Enabled); + } + + [Test] public void Data_IAssessmentSection_DataSet() { // Setup @@ -115,11 +150,76 @@ } [Test] - public void TestHydraulicBoundaryLocationsView_SelectingCellInRow_ApplicationSelectionCorrectlySynced() + public void HydraulicBoundaryLocationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized() { + // Setup & Call + ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); + + // Assert + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(3, rows.Count); + + var cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("1", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("1", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(1, 1).ToString(), cells[locationColumnIndex].FormattedValue); + + cells = rows[1].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("2", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("2", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(2, 2).ToString(), cells[locationColumnIndex].FormattedValue); + + cells = rows[2].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("3", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("3", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(3, 3).ToString(), cells[locationColumnIndex].FormattedValue); + } + + [Test] + public void HydraulicBoundaryLocationsView_HydraulicBoundaryDatabaseUpdated_DataGridViewCorrectlyUpdated() + { // Setup var view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); IAssessmentSection assessmentSection = (IAssessmentSection) view.Data; + HydraulicBoundaryDatabase newHydraulicBoundaryDatabase = new HydraulicBoundaryDatabase(); + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(10, "10", 10.0, 10.0) + { + DesignWaterLevel = (RoundedDouble) 10.23 + }; + newHydraulicBoundaryDatabase.Locations.Add(hydraulicBoundaryLocation); + + // Precondition + var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; + var rows = dataGridView.Rows; + Assert.AreEqual(3, rows.Count); + + // Call + assessmentSection.HydraulicBoundaryDatabase = newHydraulicBoundaryDatabase; + assessmentSection.NotifyObservers(); + + // Assert + Assert.AreEqual(1, rows.Count); + var cells = rows[0].Cells; + Assert.AreEqual(4, cells.Count); + Assert.AreEqual(false, cells[locationCalculateColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationNameColumnIndex].FormattedValue); + Assert.AreEqual("10", cells[locationIdColumnIndex].FormattedValue); + Assert.AreEqual(new Point2D(10, 10).ToString(), cells[locationColumnIndex].FormattedValue); + } + + [Test] + public void HydraulicBoundaryLocationsView_SelectingCellInRow_ApplicationSelectionCorrectlySynced() + { + // Setup + var view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); + IAssessmentSection assessmentSection = (IAssessmentSection) view.Data; var secondHydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.Skip(1).First(); var mocks = new MockRepository(); @@ -143,7 +243,7 @@ } [Test] - public void TestHydraulicBoundaryLocationsView_SelectingCellInAlreadySelectedRow_ApplicationSelectionNotSyncedRedundantly() + public void HydraulicBoundaryLocationsView_SelectingCellInAlreadySelectedRow_ApplicationSelectionNotSyncedRedundantly() { // Setup var view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); @@ -244,11 +344,11 @@ { // Setup var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); TestHydraulicBoundaryLocationsView view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -261,7 +361,7 @@ } [Test] - public void CalculateForSelectedButton_OneSelected_CallsCalculateDesignWaterLevels() + public void CalculateForSelectedButton_OneSelected_CallsCalculateHandleCalculateSelectedLocations() { // Setup TestHydraulicBoundaryLocationsView view = ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); @@ -271,10 +371,10 @@ rows[0].Cells[locationCalculateColumnIndex].Value = true; var mockRepository = new MockRepository(); - var commandHandlerMock = mockRepository.StrictMock(); + var guiServiceMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); - view.CalculationCommandHandler = commandHandlerMock; + view.CalculationGuiService = guiServiceMock; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call @@ -288,7 +388,7 @@ } [Test] - public void CalculateForSelectedButton_OneSelectedButCalculationCommandHandlerNotSet_DoesNotThrowException() + public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException() { // Setup ShowFullyConfiguredTestHydraulicBoundaryLocationsView(); @@ -373,21 +473,21 @@ : base(wrappedData, hydraulicBoundaryLocation) {} } - private class TestHydraulicBoundaryLocationContextRow : HydraulicBoundaryLocationContextRow { - public TestHydraulicBoundaryLocationContextRow(HydraulicBoundaryLocationContext hydraulicBoundaryLocationContext) + private class TestHydraulicBoundaryLocationContextRow : HydraulicBoundaryLocationContextRow + { + public TestHydraulicBoundaryLocationContextRow(HydraulicBoundaryLocationContext hydraulicBoundaryLocationContext) : base(hydraulicBoundaryLocationContext) {} } - private class TestHydraulicBoundaryLocationsView : HydraulicBoundaryLocationsView + private sealed class TestHydraulicBoundaryLocationsView : HydraulicBoundaryLocationsView { - - public TestHydraulicBoundaryLocationsView() { - dataGridViewControl.AddCheckBoxColumn(TypeUtils.GetMemberName(row => row.ToCalculate), ""); LocationsToCalculate = new List(); } + public IEnumerable LocationsToCalculate { get; private set; } + protected override void SetDataSource() { dataGridViewControl.SetDataSource(AssessmentSection != null && AssessmentSection.HydraulicBoundaryDatabase != null @@ -401,8 +501,6 @@ { LocationsToCalculate = locations; } - - public IEnumerable LocationsToCalculate { get; private set; } } } } \ No newline at end of file