// 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 Core.Common.Base;
using Core.Common.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.Probability;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Forms.PropertyClasses;
namespace Ringtoets.MacroStabilityInwards.Forms.Test.PropertyClasses
{
[TestFixture]
public class MacroStabilityInwardsFailureMechanismPropertiesTest
{
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 modelFactorPropertyIndex = 5;
private const int aPropertyIndex = 6;
private const int bPropertyIndex = 7;
private const int sectionLengthPropertyIndex = 8;
private const int nPropertyIndex = 9;
[Test]
public void Constructor_DataNull_ThrowArgumentNullException()
{
// Call
TestDelegate test = () => new MacroStabilityInwardsFailureMechanismProperties(null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("data", paramName);
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void Constructor_ExpectedValues(bool isRelevant)
{
// Setup
var failureMechanism = new MacroStabilityInwardsFailureMechanism
{
IsRelevant = isRelevant
};
// Call
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// Assert
Assert.IsInstanceOf>(properties);
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);
MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput;
Assert.AreEqual(probabilityAssessmentInput.A, properties.A);
Assert.AreEqual(probabilityAssessmentInput.B, properties.B);
Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
Assert.AreEqual(probabilityAssessmentInput.GetN(
probabilityAssessmentInput.SectionLength),
properties.N,
properties.N.GetAccuracy());
Assert.AreEqual(2, properties.SectionLength.NumberOfDecimalPlaces);
Assert.AreEqual(probabilityAssessmentInput.SectionLength,
properties.SectionLength,
properties.SectionLength.GetAccuracy());
}
[Test]
public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues()
{
// Setup
var failureMechanism = new MacroStabilityInwardsFailureMechanism
{
IsRelevant = true
};
// Call
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(10, 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 labelProperty = dynamicProperties[codePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty,
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 modelFactorProperty = dynamicProperties[modelFactorPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(modelFactorProperty,
modelSettingsCategory,
"Modelfactor [-]",
"Modelfactor die wordt gebruikt bij de berekening van de benaderde faalkans op basis van de berekende stabiliteitsfactor.",
true);
PropertyDescriptor aProperty = dynamicProperties[aPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(aProperty,
lengthEffectCategory,
"a [-]",
"De parameter 'a' die gebruikt wordt voor het lengte-effect in berekening van de maximaal toelaatbare faalkans.");
PropertyDescriptor bProperty = dynamicProperties[bPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(bProperty,
lengthEffectCategory,
"b [m]",
"De parameter 'b' die gebruikt wordt voor het lengte-effect in berekening van de maximaal toelaatbare faalkans.",
true);
PropertyDescriptor sectionLengthProperty = dynamicProperties[sectionLengthPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(sectionLengthProperty,
lengthEffectCategory,
"Lengte* [m]",
"Totale lengte van het traject in meters (afgerond).",
true);
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);
}
[Test]
public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues()
{
// Setup
var failureMechanism = new MacroStabilityInwardsFailureMechanism
{
IsRelevant = false
};
// Call
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// 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 labelProperty = dynamicProperties[codePropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty,
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);
}
[Test]
[SetCulture("nl-NL")]
[TestCase(-1)]
[TestCase(-0.1)]
[TestCase(1.1)]
[TestCase(8)]
public void A_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value)
{
// Setup
var mocks = new MockRepository();
var observer = mocks.StrictMock();
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
failureMechanism.Attach(observer);
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// Call
TestDelegate call = () => properties.A = value;
// Assert
const string expectedMessage = "De waarde voor 'a' moet in het bereik [0,0, 1,0] liggen.";
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
mocks.VerifyAll();
}
[Test]
[TestCase(0)]
[TestCase(0.1)]
[TestCase(1)]
[TestCase(0.0000001)]
[TestCase(0.9999999)]
public void A_SetValidValue_SetsValueAndUpdatesObservers(double value)
{
// Setup
var mocks = new MockRepository();
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
var failureMechanism = new MacroStabilityInwardsFailureMechanism();
failureMechanism.Attach(observer);
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// Call
properties.A = value;
// Assert
Assert.AreEqual(value, failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.A);
mocks.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant)
{
// Setup
var failureMechanism = new MacroStabilityInwardsFailureMechanism
{
IsRelevant = isRelevant
};
var properties = new MacroStabilityInwardsFailureMechanismProperties(failureMechanism);
// 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.A)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.B)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.SectionLength)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.N)));
Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.ModelFactor)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(null));
}
}
}