// Copyright (C) Stichting Deltares 2016. 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.Windows.Forms; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using NUnit.Extensions.Forms; using NUnit.Framework; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.Views; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.StabilityPointStructures.Forms.Test.Views { [TestFixture] public class StabilityPointStructuresResultViewTest { private const int nameColumnIndex = 0; private const int assessmentLayerTwoAIndex = 1; private const int assessmentLayerThreeIndex = 2; [Test] public void GivenFormWithStabilityPointStructuresFailureMechanismResultView_ThenExpectedColumnsAreVisible() { // Given using (var form = new Form()) using (var view = new StabilityPointStructuresResultView()) { form.Controls.Add(view); form.Show(); // Then var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; Assert.AreEqual(3, dataGridView.ColumnCount); Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerTwoAIndex]); Assert.IsInstanceOf(dataGridView.Columns[assessmentLayerThreeIndex]); Assert.AreEqual(RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, dataGridView.Columns[assessmentLayerTwoAIndex].HeaderText); Assert.AreEqual(RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, dataGridView.Columns[assessmentLayerThreeIndex].HeaderText); Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); } } [Test] public void GivenFormWithStabilityPointStructuresFailureMechanismResultView_WhenDataSourceWithStabilityPointStructuresFailureMechanismSectionResultAssigned_ThenSectionsAddedAsRows() { // Given var section1 = new FailureMechanismSection("Section 1", new[] { new Point2D(0, 0) }); var section2 = new FailureMechanismSection("Section 2", new[] { new Point2D(0, 0) }); Random random = new Random(21); var result1 = new StabilityPointStructuresFailureMechanismSectionResult(section1) { AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(), AssessmentLayerThree = (RoundedDouble) random.NextDouble() }; var result2 = new StabilityPointStructuresFailureMechanismSectionResult(section2) { AssessmentLayerTwoA = (RoundedDouble) random.NextDouble(), AssessmentLayerThree = (RoundedDouble) random.NextDouble() }; using (var form = new Form()) using (var view = new StabilityPointStructuresResultView()) { form.Controls.Add(view); form.Show(); // When view.Data = new[] { result1, result2 }; // Then var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; var rows = dataGridView.Rows; Assert.AreEqual(2, rows.Count); var cells = rows[0].Cells; Assert.AreEqual(3, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); var expectedAssessmentLayer2AString1 = ProbabilityFormattingHelper.Format(result1.AssessmentLayerTwoA); Assert.AreEqual(expectedAssessmentLayer2AString1, cells[assessmentLayerTwoAIndex].FormattedValue); Assert.AreEqual(result1.AssessmentLayerThree.ToString(), cells[assessmentLayerThreeIndex].FormattedValue); cells = rows[1].Cells; Assert.AreEqual(3, cells.Count); Assert.AreEqual("Section 2", cells[nameColumnIndex].FormattedValue); var expectedAssessmentLayer2AString2 = ProbabilityFormattingHelper.Format(result2.AssessmentLayerTwoA); Assert.AreEqual(expectedAssessmentLayer2AString2, cells[assessmentLayerTwoAIndex].FormattedValue); Assert.AreEqual(result2.AssessmentLayerThree.ToString(), cells[assessmentLayerThreeIndex].FormattedValue); } } [Test] public void GivenFormWithStabilityPointStructuresFailureMechanismResultView_WhenDataSourceWithOtherFailureMechanismSectionResultAssigned_ThenSectionsNotAdded() { // Given var section1 = new FailureMechanismSection("Section 1", new[] { new Point2D(0, 0) }); var section2 = new FailureMechanismSection("Section 2", new[] { new Point2D(0, 0) }); var result1 = new TestFailureMechanismSectionResult(section1); var result2 = new TestFailureMechanismSectionResult(section2); using (var form = new Form()) using (var view = new StabilityPointStructuresResultView()) { form.Controls.Add(view); form.Show(); // When view.Data = new[] { result1, result2 }; // Then var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; var rows = dataGridView.Rows; Assert.AreEqual(0, rows.Count); } } } }