// 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.Geometry; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.Common.Data.TestUtil.Test { [TestFixture] public class AssessmentSectionTestHelperTest { [Test] public void CreateAssessmentSectionStub_WithoutFailureMechanismAndFilePath_ReturnsExpectedAssessmentSectionStub() { // Setup var mocks = new MockRepository(); // Call IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); mocks.ReplayAll(); // Assert Assert.IsNotNull(assessmentSection); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; Assert.IsNotNull(hydraulicBoundaryDatabase); Assert.IsNull(hydraulicBoundaryDatabase.FilePath); Assert.IsNull(hydraulicBoundaryDatabase.Version); CollectionAssert.IsEmpty(hydraulicBoundaryDatabase.Locations); Assert.IsFalse(hydraulicBoundaryDatabase.CanUsePreprocessor); Assert.IsFalse(hydraulicBoundaryDatabase.UsePreprocessor); Assert.IsNull(hydraulicBoundaryDatabase.PreprocessorDirectory); mocks.VerifyAll(); } [Test] public void CreateAssessmentSectionStub_WithFailureMechanismOnly_ReturnsExpectedAssessmentSectionStub() { // Setup var failureMechanism = new TestFailureMechanism(); var mocks = new MockRepository(); // Call IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); mocks.ReplayAll(); // Assert Assert.IsNotNull(assessmentSection); Assert.AreEqual("21", assessmentSection.Id); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; Assert.IsNotNull(hydraulicBoundaryDatabase); Assert.IsNull(hydraulicBoundaryDatabase.FilePath); Assert.IsNull(hydraulicBoundaryDatabase.Version); Assert.AreEqual(1, hydraulicBoundaryDatabase.Locations.Count); HydraulicBoundaryLocation hydraulicBoundaryLocation = hydraulicBoundaryDatabase.Locations.First(); Assert.AreEqual(1300001, hydraulicBoundaryLocation.Id); Assert.IsEmpty(hydraulicBoundaryLocation.Name); Assert.AreEqual(new Point2D(0, 0), hydraulicBoundaryLocation.Location); Assert.IsFalse(hydraulicBoundaryDatabase.CanUsePreprocessor); Assert.IsFalse(hydraulicBoundaryDatabase.UsePreprocessor); Assert.IsNull(hydraulicBoundaryDatabase.PreprocessorDirectory); CollectionAssert.AreEqual(new[] { failureMechanism }, assessmentSection.GetFailureMechanisms()); FailureMechanismContribution contribution = assessmentSection.FailureMechanismContribution; Assert.AreEqual(1.0 / 10, contribution.LowerLimitNorm); Assert.AreEqual(1.0 / 30000, contribution.SignalingNorm); Assert.AreEqual(NormType.LowerLimit, contribution.NormativeNorm); mocks.VerifyAll(); } [Test] public void CreateAssessmentSectionStub_WithFailureMechanismAndFilePath_ReturnsExpectedAssessmentSectionStub() { // Setup const string path = "C://temp"; var failureMechanism = new TestFailureMechanism(); var mocks = new MockRepository(); // Call IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks, path); mocks.ReplayAll(); // Assert Assert.IsNotNull(assessmentSection); Assert.AreEqual("21", assessmentSection.Id); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; Assert.IsNotNull(hydraulicBoundaryDatabase); Assert.AreEqual(path, hydraulicBoundaryDatabase.FilePath); Assert.IsNull(hydraulicBoundaryDatabase.Version); Assert.AreEqual(1, hydraulicBoundaryDatabase.Locations.Count); HydraulicBoundaryLocation hydraulicBoundaryLocation = hydraulicBoundaryDatabase.Locations.First(); Assert.AreEqual(1300001, hydraulicBoundaryLocation.Id); Assert.IsEmpty(hydraulicBoundaryLocation.Name); Assert.AreEqual(new Point2D(0, 0), hydraulicBoundaryLocation.Location); Assert.IsFalse(hydraulicBoundaryDatabase.CanUsePreprocessor); Assert.IsFalse(hydraulicBoundaryDatabase.UsePreprocessor); Assert.IsNull(hydraulicBoundaryDatabase.PreprocessorDirectory); CollectionAssert.AreEqual(new[] { failureMechanism }, assessmentSection.GetFailureMechanisms()); FailureMechanismContribution contribution = assessmentSection.FailureMechanismContribution; Assert.AreEqual(1.0 / 10, contribution.LowerLimitNorm); Assert.AreEqual(1.0 / 30000, contribution.SignalingNorm); Assert.AreEqual(NormType.LowerLimit, contribution.NormativeNorm); mocks.VerifyAll(); } [Test] public void GetTestNormativeAssessmentLevel_Always_ReturnsTheSameRandomValue() { // Call & Assert Assert.AreEqual(AssessmentSectionTestHelper.GetTestAssessmentLevel(), AssessmentSectionTestHelper.GetTestAssessmentLevel()); } [Test] public void GetHydraulicBoundaryLocationCalculationConfigurationPerAssessmentSectionCategoryType_Always_ReturnsExpectedTestCaseDataCollection() { // Call TestCaseData[] testCaseDataCollection = AssessmentSectionTestHelper.GetHydraulicBoundaryLocationCalculationConfigurationPerAssessmentSectionCategoryType().ToArray(); // Assert AssertTestCaseData(testCaseDataCollection, "FactorizedSignalingNorm", AssessmentSectionCategoryType.FactorizedSignalingNorm, a => a.WaterLevelCalculationsForFactorizedSignalingNorm); AssertTestCaseData(testCaseDataCollection, "SignalingNorm", AssessmentSectionCategoryType.SignalingNorm, a => a.WaterLevelCalculationsForSignalingNorm); AssertTestCaseData(testCaseDataCollection, "LowerLimitNorm", AssessmentSectionCategoryType.LowerLimitNorm, a => a.WaterLevelCalculationsForLowerLimitNorm); AssertTestCaseData(testCaseDataCollection, "FactorizedLowerLimitNorm", AssessmentSectionCategoryType.FactorizedLowerLimitNorm, a => a.WaterLevelCalculationsForFactorizedLowerLimitNorm); } private static void AssertTestCaseData(IEnumerable testCaseDataCollection, string expectedTestName, AssessmentSectionCategoryType categoryType, Func> getCalculationsFunc) { TestCaseData testCaseData = testCaseDataCollection.Single(td => categoryType.Equals(td.Arguments.ElementAt(2))); Assert.AreEqual(expectedTestName, testCaseData.TestName); var assessmentSection = (IAssessmentSection) testCaseData.Arguments.ElementAt(0); var hydraulicBoundaryLocation = (HydraulicBoundaryLocation) testCaseData.Arguments.ElementAt(1); var hydraulicBoundaryLocationCalculation = (HydraulicBoundaryLocationCalculation) testCaseData.Arguments.ElementAt(3); HydraulicBoundaryLocationCalculation expectedHydraulicBoundaryLocationCalculation = getCalculationsFunc(assessmentSection).First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation)); Assert.AreSame(expectedHydraulicBoundaryLocationCalculation, hydraulicBoundaryLocationCalculation); } } }