// 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; using System.Globalization; using System.Windows.Forms; using Core.Common.Base; using Core.Common.TestUtil; using NUnit.Extensions.Forms; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityPointStructures.Forms.Views; namespace Ringtoets.StabilityPointStructures.Forms.Test.Views { [TestFixture] public class StabilityPointStructuresFailureMechanismResultViewTest { private const int nameColumnIndex = 0; private const int simpleAssessmentResultIndex = 1; private const int detailedAssessmentProbabilityIndex = 2; private const int tailorMadeAssessmentProbabilityIndex = 3; private Form testForm; [SetUp] public void Setup() { testForm = new Form(); } [TearDown] public void TearDown() { testForm.Dispose(); } [Test] public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new StabilityPointStructuresFailureMechanism(); // Call using (var view = new StabilityPointStructuresFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism, assessmentSection)) { // Assert Assert.IsInstanceOf>(view); Assert.IsNull(view.Data); Assert.AreSame(failureMechanism, view.FailureMechanism); } mocks.VerifyAll(); } [Test] public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup var failureMechanism = new StabilityPointStructuresFailureMechanism(); // Call TestDelegate call = () => new StabilityPointStructuresFailureMechanismResultView(failureMechanism.SectionResults, failureMechanism, null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("assessmentSection", exception.ParamName); } [Test] public void GivenFormWithClosingStructuresFailureMechanismResultView_ThenExpectedColumnsAreVisible() { // Given using (ShowFailureMechanismResultsView(new ObservableList())) { // Then var dataGridView = (DataGridView)new ControlTester("dataGridView").TheObject; Assert.AreEqual(4, dataGridView.ColumnCount); Assert.IsInstanceOf(dataGridView.Columns[nameColumnIndex]); Assert.IsInstanceOf(dataGridView.Columns[simpleAssessmentResultIndex]); Assert.IsInstanceOf(dataGridView.Columns[detailedAssessmentProbabilityIndex]); Assert.IsInstanceOf(dataGridView.Columns[tailorMadeAssessmentProbabilityIndex]); Assert.AreEqual("Vak", dataGridView.Columns[nameColumnIndex].HeaderText); Assert.AreEqual("Eenvoudige toets", dataGridView.Columns[simpleAssessmentResultIndex].HeaderText); Assert.AreEqual("Gedetailleerde toets per vak\r\nfaalkans", dataGridView.Columns[detailedAssessmentProbabilityIndex].HeaderText); Assert.AreEqual("Toets op maat\r\nfaalkans", dataGridView.Columns[tailorMadeAssessmentProbabilityIndex].HeaderText); Assert.IsTrue(dataGridView.Columns[nameColumnIndex].ReadOnly); Assert.IsFalse(dataGridView.Columns[simpleAssessmentResultIndex].ReadOnly); Assert.IsTrue(dataGridView.Columns[detailedAssessmentProbabilityIndex].ReadOnly); Assert.IsFalse(dataGridView.Columns[tailorMadeAssessmentProbabilityIndex].ReadOnly); Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); } } [Test] public void GivenFailureMechanismResultsView_WhenAllDataSet_ThenDataGridViewCorrectlyInitialized() { // Given var results = new ObservableList { new StabilityPointStructuresFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1")) }; StabilityPointStructuresFailureMechanismResultView failureMechanismResultView = ShowFailureMechanismResultsView(results); using (failureMechanismResultView) { // Then var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(4, cells.Count); Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue); Assert.AreEqual(SimpleAssessmentResultValidityOnlyType.None, cells[simpleAssessmentResultIndex].Value); Assert.AreEqual("-", cells[detailedAssessmentProbabilityIndex].FormattedValue); Assert.AreEqual("-", cells[tailorMadeAssessmentProbabilityIndex].FormattedValue); } } private StabilityPointStructuresFailureMechanismResultView ShowFailureMechanismResultsView( IObservableEnumerable sectionResults) { var failureMechanismResultView = new StabilityPointStructuresFailureMechanismResultView(sectionResults, new StabilityPointStructuresFailureMechanism(), new ObservableTestAssessmentSectionStub()); testForm.Controls.Add(failureMechanismResultView); testForm.Show(); return failureMechanismResultView; } } }