// 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.ComponentModel; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.TestUtil; using Ringtoets.GrassCoverErosionOutwards.Data.TestUtil; namespace Ringtoets.GrassCoverErosionOutwards.Data.Test { [TestFixture] public class GrassCoverErosionOutwardsFailureMechanismExtensionsTest { [Test] public void GetAssessmentLevel_FailureMechanismNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => GrassCoverErosionOutwardsFailureMechanismExtensions.GetAssessmentLevel(null, new AssessmentSectionStub(), new TestHydraulicBoundaryLocation(), FailureMechanismCategoryType.FactorizedLowerLimitNorm); // Assert string paramName = Assert.Throws(test).ParamName; Assert.AreEqual("failureMechanism", paramName); } [Test] public void GetAssessmentLevel_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); // Call TestDelegate test = () => failureMechanism.GetAssessmentLevel(null, new TestHydraulicBoundaryLocation(), FailureMechanismCategoryType.FactorizedLowerLimitNorm); // Assert string paramName = Assert.Throws(test).ParamName; Assert.AreEqual("assessmentSection", paramName); } [Test] public void GetAssessmentLevel_InvalidAssessmentSectionCategoryType_ThrowsInvalidEnumArgumentException() { // Setup const int invalidValue = 9999; var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); // Call TestDelegate test = () => failureMechanism.GetAssessmentLevel(assessmentSection, new TestHydraulicBoundaryLocation(), (FailureMechanismCategoryType) invalidValue); // Assert string expectedMessage = $"The value of argument 'categoryType' ({invalidValue}) is invalid for Enum type '{nameof(FailureMechanismCategoryType)}'."; string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage).ParamName; Assert.AreEqual("categoryType", parameterName); } [Test] public void GetAssessmentLevel_HydraulicBoundaryLocationNull_ReturnsNaN() { // Setup var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); // Call RoundedDouble assessmentLevel = failureMechanism.GetAssessmentLevel(assessmentSection, null, new Random(32).NextEnumValue()); // Assert Assert.IsNaN(assessmentLevel); } [Test] public void GetAssessmentLevel_NoCorrespondingCalculation_ReturnsNaN() { var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); // Call RoundedDouble assessmentLevel = failureMechanism.GetAssessmentLevel(assessmentSection, new TestHydraulicBoundaryLocation(), new Random(32).NextEnumValue()); // Assert Assert.IsNaN(assessmentLevel); } [Test] public void GetAssessmentLevel_NoCorrespondingAssessmentLevelOutput_ReturnsNaN() { var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); // Call RoundedDouble assessmentLevel = failureMechanism.GetAssessmentLevel(assessmentSection, hydraulicBoundaryLocation, new Random(32).NextEnumValue()); // Assert Assert.IsNaN(assessmentLevel); } [Test] [TestCaseSource( typeof(GrassCoverErosionOutwardsAssessmentSectionHelper), nameof(GrassCoverErosionOutwardsAssessmentSectionHelper.GetAssessmentLevelConfigurationPerFailureMechanismCategoryType))] public void GetAssessmentLevel_HydraulicBoundaryLocationWithOutput_ReturnsCorrespondingAssessmentLevel( IAssessmentSection assessmentSection, GrassCoverErosionOutwardsFailureMechanism failureMechanism, HydraulicBoundaryLocation hydraulicBoundaryLocation, FailureMechanismCategoryType categoryType, RoundedDouble expectedAssessmentLevel) { // Call RoundedDouble assessmentLevel = failureMechanism.GetAssessmentLevel(assessmentSection, hydraulicBoundaryLocation, categoryType); // Assert Assert.AreEqual(expectedAssessmentLevel, assessmentLevel); } } }