// 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 System.Linq; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.TestUtil; namespace Ringtoets.Common.Data.Test.AssessmentSection { [TestFixture] public class AssessmentSectionExtensionsTest { [Test] public void GetNormativeAssessmentLevel_AssessmentSectionNull_ThrowsArgumentNullException() { // Call TestDelegate test = () => AssessmentSectionExtensions.GetNormativeAssessmentLevel(null, new TestHydraulicBoundaryLocation()); // Assert string paramName = Assert.Throws(test).ParamName; Assert.AreEqual("assessmentSection", paramName); } [Test] public void GetNormativeAssessmentLevel_AssessmentSectionWithInvalidNormType_ThrowsInvalidEnumArgumentException() { // Setup const int invalidValue = 9999; var assessmentSection = new AssessmentSectionStub(); assessmentSection.FailureMechanismContribution.NormativeNorm = (NormType) invalidValue; // Call TestDelegate test = () => assessmentSection.GetNormativeAssessmentLevel(new TestHydraulicBoundaryLocation()); // Assert string expectedMessage = $"The value of argument 'normType' ({invalidValue}) is invalid for Enum type '{nameof(NormType)}'."; string parameterName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage).ParamName; Assert.AreEqual("normType", parameterName); } [Test] public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeSignaling_ReturnsCorrespondingAssessmentLevel() { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.FailureMechanismContribution.NormativeNorm = NormType.Signaling; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert Assert.AreEqual(assessmentSection.WaterLevelCalculationsForSignalingNorm.ElementAt(0).Output.Result, normativeAssessmentLevel); } [Test] public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeLowerLimit_ReturnsCorrespondingAssessmentLevel() { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.FailureMechanismContribution.NormativeNorm = NormType.LowerLimit; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert Assert.AreEqual(assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0).Output.Result, normativeAssessmentLevel); } [TestCase(NormType.Signaling)] [TestCase(NormType.LowerLimit)] public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNull_ReturnsNaN(NormType normType) { // Setup var assessmentSection = new AssessmentSectionStub(); // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(null); // Assert Assert.IsNaN(normativeAssessmentLevel); } [TestCase(NormType.Signaling)] [TestCase(NormType.LowerLimit)] public void GetNormativeAssessmentLevel_NoCorrespondingCalculation_ReturnsNaN(NormType normType) { var assessmentSection = new AssessmentSectionStub(); assessmentSection.FailureMechanismContribution.NormativeNorm = normType; // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(new TestHydraulicBoundaryLocation()); // Assert Assert.IsNaN(normativeAssessmentLevel); } [TestCase(NormType.Signaling)] [TestCase(NormType.LowerLimit)] public void GetNormativeAssessmentLevel_NoCorrespondingAssessmentLevelOutput_ReturnsNaN(NormType normType) { var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.FailureMechanismContribution.NormativeNorm = normType; assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert Assert.IsNaN(normativeAssessmentLevel); } } }