// 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.TestUtil;
using NUnit.Framework;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.Revetment.Data;
namespace Ringtoets.GrassCoverErosionOutwards.Forms.Test
{
[TestFixture]
public class GrassCoverErosionOutwardsWaveConditionsCalculationHelperTest
{
[Test]
public void AddCalculationsFromLocations_LocationsIsNull_ThrowsArgumentNullException()
{
// Setup
var random = new Random(21);
var calculations = new List();
// Call
TestDelegate test = () => GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(null,
calculations,
random.NextEnumValue());
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("locations", paramName);
}
[Test]
public void AddCalculationsFromLocations_CalculationsIsNull_ThrowsArgumentNullException()
{
// Setup
var random = new Random(21);
IEnumerable locations = Enumerable.Empty();
// Call
TestDelegate test = () => GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(locations,
null,
random.NextEnumValue());
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("calculations", paramName);
}
[Test]
public void AddCalculationsFromLocations_EmptyCollections_ReturnsEmptyList()
{
// Setup
var random = new Random(21);
IEnumerable locations = Enumerable.Empty();
var calculationBases = new List();
// Call
GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(locations, calculationBases, random.NextEnumValue());
// Assert
CollectionAssert.IsEmpty(calculationBases);
}
[Test]
[TestCase(NormType.LowerLimit, FailureMechanismCategoryType.MechanismSpecificLowerLimitNorm)]
[TestCase(NormType.Signaling, FailureMechanismCategoryType.MechanismSpecificSignalingNorm)]
public void AddCalculationsFromLocations_MultipleLocationsEmptyCalculationBase_ReturnsUniquelyNamedCalculations(
NormType normType,
FailureMechanismCategoryType expectedFailureMechanismCategoryType)
{
// Setup
const string name = "name";
var locations = new[]
{
new HydraulicBoundaryLocation(1, name, 1, 1),
new HydraulicBoundaryLocation(2, name, 2, 2)
};
var calculationBases = new List();
// Call
GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(locations, calculationBases, normType);
// Assert
Assert.AreEqual(2, calculationBases.Count);
var firstCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation) calculationBases.First();
Assert.AreEqual(name, firstCalculation.Name);
FailureMechanismCategoryWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters;
Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation);
Assert.AreEqual(expectedFailureMechanismCategoryType, firstCalculationInput.CategoryType);
var secondCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation) calculationBases.ElementAt(1);
Assert.AreEqual($"{name} (1)", secondCalculation.Name);
FailureMechanismCategoryWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters;
Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation);
Assert.AreEqual(expectedFailureMechanismCategoryType, secondCalculationInput.CategoryType);
}
[Test]
[TestCase(NormType.LowerLimit, FailureMechanismCategoryType.MechanismSpecificLowerLimitNorm)]
[TestCase(NormType.Signaling, FailureMechanismCategoryType.MechanismSpecificSignalingNorm)]
public void AddCalculationsFromLocations_MultipleLocationsAndDuplicateNameInCalculationBase_ReturnsUniquelyNamedCalculations(
NormType normType,
FailureMechanismCategoryType expectedFailureMechanismCategoryType)
{
// Setup
const string name = "name";
var locations = new[]
{
new HydraulicBoundaryLocation(1, name, 1, 1),
new HydraulicBoundaryLocation(2, name, 2, 2)
};
var calculationBases = new List
{
new GrassCoverErosionOutwardsWaveConditionsCalculation
{
Name = name
}
};
// Call
GrassCoverErosionOutwardsWaveConditionsCalculationHelper.AddCalculationsFromLocations(locations, calculationBases, normType);
// Assert
Assert.AreEqual(3, calculationBases.Count);
var firstCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation) calculationBases.ElementAt(1);
Assert.AreEqual($"{name} (1)", firstCalculation.Name);
FailureMechanismCategoryWaveConditionsInput firstCalculationInput = firstCalculation.InputParameters;
Assert.AreEqual(locations[0], firstCalculationInput.HydraulicBoundaryLocation);
Assert.AreEqual(expectedFailureMechanismCategoryType, firstCalculationInput.CategoryType);
var secondCalculation = (GrassCoverErosionOutwardsWaveConditionsCalculation) calculationBases.ElementAt(2);
Assert.AreEqual($"{name} (2)", secondCalculation.Name);
FailureMechanismCategoryWaveConditionsInput secondCalculationInput = secondCalculation.InputParameters;
Assert.AreSame(locations[1], secondCalculationInput.HydraulicBoundaryLocation);
Assert.AreEqual(expectedFailureMechanismCategoryType, secondCalculationInput.CategoryType);
}
}
}