// Copyright (C) Stichting Deltares 2018. 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;
using Core.Common.Base.Data;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Revetment.Data;
using Ringtoets.WaveImpactAsphaltCover.Data;
using Ringtoets.WaveImpactAsphaltCover.Forms.PropertyClasses;
namespace Ringtoets.WaveImpactAsphaltCover.Forms.Test.PropertyClasses
{
[TestFixture]
public class WaveImpactAsphaltCoverFailureMechanismPropertiesTest
{
private const int namePropertyIndex = 0;
private const int codePropertyIndex = 1;
private const int groupPropertyIndex = 2;
private const int contributionPropertyIndex = 3;
private const int isRelevantPropertyIndex = 4;
private const int sectionLengthPropertyIndex = 5;
private const int deltaLPropertyIndex = 6;
private const int nPropertyIndex = 7;
private const int aPropertyIndex = 8;
private const int bPropertyIndex = 9;
private const int cPropertyIndex = 10;
[Test]
public void Constructor_DataNull_ThrowsArgumentNullException()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
// Call
TestDelegate test = () => new WaveImpactAsphaltCoverFailureMechanismProperties(null, assessmentSection);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("data", paramName);
mocks.VerifyAll();
}
[Test]
public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
TestDelegate call = () => new WaveImpactAsphaltCoverFailureMechanismProperties(new WaveImpactAsphaltCoverFailureMechanism(), null);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("assessmentSection", exception.ParamName);
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void Constructor_WithWaveImpactAsphaltCoverFailureMechanism_ReturnsCorrectPropertyValues(bool isRelevant)
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
assessmentSection.ReferenceLine = new ReferenceLine();
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism
{
IsRelevant = isRelevant
};
// Call
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(failureMechanism, assessmentSection);
// Assert
Assert.AreSame(failureMechanism, properties.Data);
Assert.AreEqual(failureMechanism.Name, properties.Name);
Assert.AreEqual(failureMechanism.Code, properties.Code);
Assert.AreEqual(failureMechanism.Group, properties.Group);
Assert.AreEqual(failureMechanism.Contribution, properties.Contribution);
Assert.AreEqual(isRelevant, properties.IsRelevant);
GeneralWaveConditionsInput generalWaveConditionsInput = failureMechanism.GeneralInput;
Assert.AreEqual(generalWaveConditionsInput.A, properties.A);
Assert.AreEqual(generalWaveConditionsInput.B, properties.B);
Assert.AreEqual(generalWaveConditionsInput.C, properties.C);
GeneralWaveImpactAsphaltCoverInput generalWaveImpactAsphaltCoverInput = failureMechanism.GeneralWaveImpactAsphaltCoverInput;
Assert.AreEqual(generalWaveImpactAsphaltCoverInput.DeltaL, properties.DeltaL);
Assert.AreEqual(2, properties.SectionLength.NumberOfDecimalPlaces);
Assert.AreEqual(assessmentSection.ReferenceLine.Length,
properties.SectionLength,
properties.SectionLength.GetAccuracy());
Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
Assert.AreEqual(generalWaveImpactAsphaltCoverInput.GetN(assessmentSection.ReferenceLine.Length),
properties.N,
properties.N.GetAccuracy());
mocks.VerifyAll();
}
[Test]
public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
// Call
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(
new WaveImpactAsphaltCoverFailureMechanism
{
IsRelevant = true
}, assessmentSection);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(11, dynamicProperties.Count);
const string generalCategory = "Algemeen";
const string lengthEffectCategory = "Lengte-effect parameters";
const string modelSettingsCategory = "Modelinstellingen";
PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
generalCategory,
"Naam",
"De naam van het toetsspoor.",
true);
PropertyDescriptor codeProperty = dynamicProperties[codePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(codeProperty,
generalCategory,
"Label",
"Het label van het toetsspoor.",
true);
PropertyDescriptor groupProperty = dynamicProperties[groupPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(groupProperty,
generalCategory,
"Groep",
"De groep waar het toetsspoor toe behoort.",
true);
PropertyDescriptor contributionProperty = dynamicProperties[contributionPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(contributionProperty,
generalCategory,
"Faalkansbijdrage [%]",
"Procentuele bijdrage van dit toetsspoor aan de totale overstromingskans van het traject.",
true);
PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty,
generalCategory,
"Is relevant",
"Geeft aan of dit toetsspoor relevant is of niet.",
true);
PropertyDescriptor sectionLength = dynamicProperties[sectionLengthPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(sectionLength,
lengthEffectCategory,
"Lengte* [m]",
"Totale lengte van het traject in meters (afgerond).",
true);
PropertyDescriptor deltaLProperty = dynamicProperties[deltaLPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(deltaLProperty,
lengthEffectCategory,
"ΔL [m]",
"Lengte van onafhankelijke dijkstrekkingen voor dit toetsspoor.");
PropertyDescriptor nProperty = dynamicProperties[nPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nProperty,
lengthEffectCategory,
"N* [-]",
"De parameter 'N' die gebruikt wordt om het lengte-effect " +
"mee te nemen in de beoordeling (afgerond).",
true);
PropertyDescriptor aProperty = dynamicProperties[aPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(aProperty,
modelSettingsCategory,
"a",
"De waarde van de parameter 'a' in de berekening voor golf condities.",
true);
PropertyDescriptor bProperty = dynamicProperties[bPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(bProperty,
modelSettingsCategory,
"b",
"De waarde van de parameter 'b' in de berekening voor golf condities.",
true);
PropertyDescriptor cProperty = dynamicProperties[cPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(cProperty,
modelSettingsCategory,
"c",
"De waarde van de parameter 'c' in de berekening voor golf condities.",
true);
mocks.VerifyAll();
}
[Test]
public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
// Call
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(
new WaveImpactAsphaltCoverFailureMechanism
{
IsRelevant = false
}, assessmentSection);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(4, dynamicProperties.Count);
const string generalCategory = "Algemeen";
PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
generalCategory,
"Naam",
"De naam van het toetsspoor.",
true);
PropertyDescriptor codeProperty = dynamicProperties[codePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(codeProperty,
generalCategory,
"Label",
"Het label van het toetsspoor.",
true);
PropertyDescriptor groupProperty = dynamicProperties[groupPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(groupProperty,
generalCategory,
"Groep",
"De groep waar het toetsspoor toe behoort.",
true);
PropertyDescriptor isRelevantProperty = dynamicProperties[isRelevantPropertyIndex - 1];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty,
generalCategory,
"Is relevant",
"Geeft aan of dit toetsspoor relevant is of niet.",
true);
mocks.VerifyAll();
}
[Test]
[SetCulture("nl-NL")]
[TestCase(-1)]
[TestCase(-0.005)]
[TestCase(-1000)]
[TestCase(double.NegativeInfinity)]
[TestCase(double.NaN)]
public void DeltaL_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value)
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
var observer = mocks.StrictMock();
mocks.ReplayAll();
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.Attach(observer);
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(failureMechanism, assessmentSection);
// Call
TestDelegate call = () => properties.DeltaL = (RoundedDouble) value;
// Assert
const string expectedMessage = "De waarde voor 'ΔL' moet groter zijn dan 0.";
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
mocks.VerifyAll();
}
[Test]
[TestCase(0.005)]
[TestCase(1)]
[TestCase(1000)]
[TestCase(double.PositiveInfinity)]
public void DeltaL_SetValidValue_SetsValueAndUpdatesObservers(double value)
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
failureMechanism.Attach(observer);
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(failureMechanism, assessmentSection);
// Call
properties.DeltaL = (RoundedDouble) value;
// Assert
Assert.AreEqual(value,
failureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL,
failureMechanism.GeneralWaveImpactAsphaltCoverInput.DeltaL.GetAccuracy());
mocks.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnsExpectedVisibility(bool isRelevant)
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var properties = new WaveImpactAsphaltCoverFailureMechanismProperties(
new WaveImpactAsphaltCoverFailureMechanism
{
IsRelevant = isRelevant
}, assessmentSection);
// Call & Assert
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Group)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.Contribution)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.SectionLength)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.DeltaL)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.N)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.A)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.B)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.C)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(null));
mocks.VerifyAll();
}
}
}