// 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.Generic; using System.Linq; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.Common.Data.TestUtil { /// /// Helper class for creating assessment sections that can be used for unit tests. /// public static class AssessmentSectionHelper { private static readonly RoundedDouble testAssessmentLevel = new Random(21).NextRoundedDouble(); /// /// Creates a stub of with a that is not linked. /// /// The mock repository to create the stub with. /// A stubbed . public static IAssessmentSection CreateAssessmentSectionStub(MockRepository mockRepository) { var assessmentSection = mockRepository.Stub(); assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase()); return assessmentSection; } /// /// Creates a stub of . /// /// The failure mechanism to set the contribution for. /// The mock repository to create the stub with. /// The file path to the hydraulic boundary database (optional). /// A stubbed . /// Whether is provided or not, a dummy location with id 1300001 is added to the /// hydraulic boundary database. public static IAssessmentSection CreateAssessmentSectionStub(IFailureMechanism failureMechanism, MockRepository mockRepository, string filePath = null) { IFailureMechanism[] failureMechanisms = GetFailureMechanisms(failureMechanism); var assessmentSection = mockRepository.Stub(); assessmentSection.Stub(a => a.Id).Return("21"); assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( failureMechanisms, 1, 0.1, 1.0 / 30000)); assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(failureMechanisms); assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(GetHydraulicBoundaryDatabase(filePath)); assessmentSection.Replay(); return assessmentSection; } /// /// Gets a random assessment level for testing purposes. /// /// The assessment level. /// The returned assessment level is random, though always the same. public static RoundedDouble GetTestAssessmentLevel() { return testAssessmentLevel; } /// /// Gets a collection of containing an assessment level /// configuration for all types of . /// /// A collection of , in which each item contains: /// /// the configured assessment section; /// the hydraulic boundary location for which the assessment level output has been set; /// the category type at stake; /// the set assessment level (which makes it the "expected assessment level" given the combination /// of the before-mentioned assessment section, hydraulic boundary location and category type). /// /// public static IEnumerable GetAssessmentLevelConfigurationPerAssessmentSectionCategoryType() { var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); yield return new TestCaseData( assessmentSection, hydraulicBoundaryLocation, AssessmentSectionCategoryType.FactorizedSignalingNorm, assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm.ElementAt(0).Output.Result ).SetName("FactorizedSignalingNorm"); yield return new TestCaseData( assessmentSection, hydraulicBoundaryLocation, AssessmentSectionCategoryType.SignalingNorm, assessmentSection.WaterLevelCalculationsForSignalingNorm.ElementAt(0).Output.Result ).SetName("SignalingNorm"); yield return new TestCaseData( assessmentSection, hydraulicBoundaryLocation, AssessmentSectionCategoryType.LowerLimitNorm, assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ElementAt(0).Output.Result ).SetName("LowerLimitNorm"); yield return new TestCaseData( assessmentSection, hydraulicBoundaryLocation, AssessmentSectionCategoryType.FactorizedLowerLimitNorm, assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm.ElementAt(0).Output.Result ).SetName("FactorizedLowerLimitNorm"); } private static IFailureMechanism[] GetFailureMechanisms(IFailureMechanism failureMechanism) { return failureMechanism == null ? Enumerable.Empty().ToArray() : new[] { failureMechanism }; } private static HydraulicBoundaryDatabase GetHydraulicBoundaryDatabase(string filePath) { return new HydraulicBoundaryDatabase { FilePath = filePath, Locations = { new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0) } }; } } }