// 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.Collections.Generic; using System.Windows.Forms; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Primitives; namespace Ringtoets.Common.Forms.Test.Helpers { [TestFixture] public class FailureMechanismSectionResultRowHelperTest { [Test] public void SetDetailedAssessmentErrorSimpleAssessmentResultType_DataGridViewCellNull_ThrowsArgumentNullException() { // Setup var mockRepository = new MockRepository(); var calculation = mockRepository.Stub(); mockRepository.ReplayAll(); var simpleAssessmentResult = new Random(21).NextEnumValue(); // Call TestDelegate call = () => FailureMechanismSectionResultRowHelper.SetDetailedAssessmentError(null, simpleAssessmentResult, 0.0, calculation); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("dataGridViewCell", paramName); mockRepository.VerifyAll(); } [Test] [TestCaseSource(nameof(GetSimpleAssessmentResultNotApplicableConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultProbabilityNegligibleConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationNullConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationWithoutOutputConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationWithOutputConfigurations))] public void SetDetailedAssessmentError_WithSimpleAssessmentResultConfigurations_SetsErrorText(DataGridViewCell dataGridViewCell, SimpleAssessmentResultType simpleAssessmentResult, double detailedAssessmentResult, ICalculation normativeCalculation, string expectedErrorText) { // Call FailureMechanismSectionResultRowHelper.SetDetailedAssessmentError(dataGridViewCell, simpleAssessmentResult, detailedAssessmentResult, normativeCalculation); // Assert Assert.AreEqual(expectedErrorText, dataGridViewCell.ErrorText); } [Test] public void SetDetailedAssessmentErrorSimpleAssessmentValidityOnlyType_DataGridViewCellNull_ThrowsArgumentNullException() { // Setup var mockRepository = new MockRepository(); var calculation = mockRepository.Stub(); mockRepository.ReplayAll(); var simpleAssessmentResult = new Random(21).NextEnumValue(); // Call TestDelegate call = () => FailureMechanismSectionResultRowHelper.SetDetailedAssessmentError(null, simpleAssessmentResult, 0.0, calculation); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("dataGridViewCell", paramName); mockRepository.VerifyAll(); } [Test] [TestCaseSource(nameof(GetSimpleAssessmentResultValidityOnlyIsNotApplicableConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationNullConfigurations))] [TestCaseSource(nameof(GetSimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationWithoutOutputConfigurations))] [TestCaseSource(nameof(SimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationWithOutput))] public void SetAssessmentDetailedAssessmentError_WithSimpleAssessmentValidityOnlyConfigurations_SetsErrorText(DataGridViewCell dataGridViewCell, SimpleAssessmentResultValidityOnlyType simpleAssessmentResult, double detailedAssessmentResult, ICalculation normativeCalculation, string expectedErrorText) { // Call FailureMechanismSectionResultRowHelper.SetDetailedAssessmentError(dataGridViewCell, simpleAssessmentResult, detailedAssessmentResult, normativeCalculation); // Assert Assert.AreEqual(expectedErrorText, dataGridViewCell.ErrorText); } [Test] [TestCaseSource(nameof(GetCalculationNullConfigurations))] [TestCaseSource(nameof(GetCalculationWithoutOutputConfigurations))] [TestCaseSource(nameof(GetCalculationWithOutputConfigurations))] public void GetAssessmentDetailedAssessmentError_WithVariousConfigurations_GetsExpectedErrorText(double detailedAssessmentResult, ICalculation normativeCalculation, string expectedErrorText) { // Call string errorText = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentError(detailedAssessmentResult, normativeCalculation); // Assert Assert.AreEqual(expectedErrorText, errorText); } private class TestDataGridViewCell : DataGridViewCell {} #region Test cases private static IEnumerable GetCalculationNullConfigurations() { const string expectedErrorMessage = "Er moet een maatgevende berekening voor dit vak worden geselecteerd."; yield return new TestCaseData(double.NaN, null, expectedErrorMessage) .SetName("InvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(0.0, null, expectedErrorMessage) .SetName("ValidDetailedAssessmentAndNoCalculation"); } private static IEnumerable GetCalculationWithoutOutputConfigurations() { const string expectedErrorMessage = "De maatgevende berekening voor dit vak moet nog worden uitgevoerd."; yield return new TestCaseData(double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("InvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("ValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable GetCalculationWithOutputConfigurations() { const string expectedErrorMessageOutputInvalid = "De maatgevende berekening voor dit vak moet een geldige uitkomst hebben."; string expectedEmptyErrorMessage = string.Empty; yield return new TestCaseData(double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessageOutputInvalid) .SetName("InvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedEmptyErrorMessage) .SetName("ValidDetailedAssessmentAndCalculationWithOutput"); } #endregion #region Test cases simple assessment (result) private static IEnumerable GetSimpleAssessmentResultNotApplicableConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; string expectedErrorMessage = string.Empty; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, double.NaN, null, string.Empty) .SetName("SufficientWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, 0.0, null, string.Empty) .SetName("SufficientWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, double.NaN, null, expectedErrorMessage) .SetName("NotApplicableWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, 0.0, null, expectedErrorMessage) .SetName("NotApplicableWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("SufficientWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("SufficientWithValidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("SufficientWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.NotApplicable, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("SufficientWithValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable GetSimpleAssessmentResultProbabilityNegligibleConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; string expectedErrorMessage = string.Empty; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, double.NaN, null, expectedErrorMessage) .SetName("ProbabilityNegligibleWithWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, 0.0, null, expectedErrorMessage) .SetName("ProbabilityNegligibleWithWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, double.NaN, null, expectedErrorMessage) .SetName("ProbabilityNegligibleWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, 0.0, null, expectedErrorMessage) .SetName("ProbabilityNegligibleWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("ProbabilityNegligibleWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("ProbabilityNegligibleWithValidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("ProbabilityNegligibleWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.ProbabilityNegligible, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("ProbabilityNegligibleWithValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationNullConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessage = "Er moet een maatgevende berekening voor dit vak worden geselecteerd."; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, double.NaN, null, expectedErrorMessage) .SetName("AssessFurtherWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, 0.0, null, expectedErrorMessage) .SetName("AssessFurtherWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, double.NaN, null, expectedErrorMessage) .SetName("NoneWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, 0.0, null, expectedErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndNoCalculation"); } private static IEnumerable GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationWithoutOutputConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessage = "De maatgevende berekening voor dit vak moet nog worden uitgevoerd."; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("AssessFurtherWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("AssessFurtherWithValidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NoneWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable GetSimpleAssessmentResultAssessFurtherOrNoneAndCalculationWithOutputConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessageOutputInvalid = "De maatgevende berekening voor dit vak moet een geldige uitkomst hebben."; string expectedEmptyErrorMessage = string.Empty; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessageOutputInvalid) .SetName("AssessFurtherWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.AssessFurther, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedEmptyErrorMessage) .SetName("AssessFurtherWithValidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessageOutputInvalid) .SetName("NoneWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultType.None, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedEmptyErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndCalculationWithOutput"); } #endregion #region Test cases simple assessment (validity only) private static IEnumerable GetSimpleAssessmentResultValidityOnlyIsNotApplicableConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; string expectedErrorMessage = string.Empty; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, double.NaN, null, expectedErrorMessage) .SetName("NotApplicableWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, 0.0, null, expectedErrorMessage) .SetName("NotApplicableWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("NotApplicableWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessage) .SetName("NotApplicableWithValidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NotApplicableWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.NotApplicable, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NotApplicableWithValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable GetSimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationNullConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessage = "Er moet een maatgevende berekening voor dit vak worden geselecteerd."; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, double.NaN, null, expectedErrorMessage) .SetName("NoneWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, 0.0, null, expectedErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, double.NaN, null, expectedErrorMessage) .SetName("ApplicableWithInvalidDetailedAssessmentAndNoCalculation"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, 0.0, null, expectedErrorMessage) .SetName("ApplicableWithValidDetailedAssessmentAndNoCalculation"); } private static IEnumerable GetSimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationWithoutOutputConfigurations() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessage = "De maatgevende berekening voor dit vak moet nog worden uitgevoerd."; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NoneWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("ApplicableWithInvalidDetailedAssessmentAndCalculationWithoutOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, 0.0, CalculationTestDataFactory.CreateCalculationWithoutOutput(), expectedErrorMessage) .SetName("ApplicableWithValidDetailedAssessmentAndCalculationWithoutOutput"); } private static IEnumerable SimpleAssessmentResultValidityOnlyIsNotApplicableAndCalculationWithOutput() { var dataGridViewCell = new TestDataGridViewCell { ErrorText = "Default text" }; const string expectedErrorMessageOutputInvalid = "De maatgevende berekening voor dit vak moet een geldige uitkomst hebben."; string expectedEmptyErrorMessage = string.Empty; yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessageOutputInvalid) .SetName("NoneWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.None, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedEmptyErrorMessage) .SetName("NoneWithValidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, double.NaN, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedErrorMessageOutputInvalid) .SetName("ApplicableWithInvalidDetailedAssessmentAndCalculationWithOutput"); yield return new TestCaseData(dataGridViewCell, SimpleAssessmentResultValidityOnlyType.Applicable, 0.0, CalculationTestDataFactory.CreateCalculationWithOutput(), expectedEmptyErrorMessage) .SetName("ApplicableWithValidDetailedAssessmentAndCalculationWithOutput"); } #endregion } }