// 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.Integration.Data.StandAlone;
using Ringtoets.Integration.Data.StandAlone.Input;
using Ringtoets.Integration.Forms.PropertyClasses;
namespace Ringtoets.Integration.Forms.Test.PropertyClasses
{
public class MacroStabilityOutwardsFailureMechanismPropertiesTest
{
[Test]
public void Constructor_DataIsNull_ThrowArgumentNullException()
{
// Call
TestDelegate test = () => new MacroStabilityOutwardsFailureMechanismProperties(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 MacroStabilityOutwardsFailureMechanism
{
IsRelevant = isRelevant
};
// Call
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Assert
Assert.IsInstanceOf>(properties);
Assert.AreEqual(failureMechanism.Name, properties.Name);
Assert.AreEqual(failureMechanism.Code, properties.Code);
Assert.AreEqual(isRelevant, properties.IsRelevant);
MacroStabilityOutwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput;
Assert.AreEqual(probabilityAssessmentInput.A, properties.A);
Assert.AreEqual(probabilityAssessmentInput.B, properties.B);
Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
Assert.AreEqual(probabilityAssessmentInput.GetSectionSpecificN(
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 MacroStabilityOutwardsFailureMechanism
{
IsRelevant = true
};
// Call
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(7, dynamicProperties.Count);
const string generalCategory = "Algemeen";
const string lengthEffectCategory = "Lengte-effect parameters";
PropertyDescriptor nameProperty = dynamicProperties[0];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
generalCategory,
"Naam",
"De naam van het toetsspoor.",
true);
PropertyDescriptor labelProperty = dynamicProperties[1];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty,
generalCategory,
"Label",
"Het label van het toetsspoor.",
true);
PropertyDescriptor isRelevantProperty = dynamicProperties[2];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isRelevantProperty,
generalCategory,
"Is relevant",
"Geeft aan of dit toetsspoor relevant is of niet.",
true);
PropertyDescriptor aProperty = dynamicProperties[3];
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[4];
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[5];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(sectionLengthProperty,
lengthEffectCategory,
"Lengte* [m]",
"Totale lengte van het traject in meters (afgerond).",
true);
PropertyDescriptor nProperty = dynamicProperties[6];
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 MacroStabilityOutwardsFailureMechanism
{
IsRelevant = false
};
// Call
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(3, dynamicProperties.Count);
const string generalCategory = "Algemeen";
PropertyDescriptor nameProperty = dynamicProperties[0];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
generalCategory,
"Naam",
"De naam van het toetsspoor.",
true);
PropertyDescriptor labelProperty = dynamicProperties[1];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(labelProperty,
generalCategory,
"Label",
"Het label van het toetsspoor.",
true);
PropertyDescriptor isRelevantProperty = dynamicProperties[2];
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 MacroStabilityOutwardsFailureMechanism();
failureMechanism.Attach(observer);
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Call
TestDelegate call = () => properties.A = value;
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("De waarde moet in het bereik [0,0, 1,0] liggen.", exception.Message);
mocks.VerifyAll();
}
[Test]
[TestCase(0)]
[TestCase(0.1)]
[TestCase(1)]
[TestCase(0.0000001)]
[TestCase(0.9999999)]
public void A_SetValidValue_SetsValueAndUpdatesObserver(double value)
{
// Setup
var mocks = new MockRepository();
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
var failureMechanism = new MacroStabilityOutwardsFailureMechanism();
failureMechanism.Attach(observer);
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Call
properties.A = value;
// Assert
Assert.AreEqual(value, failureMechanism.MacroStabilityOutwardsProbabilityAssessmentInput.A);
mocks.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant)
{
// Setup
var failureMechanism = new MacroStabilityOutwardsFailureMechanism
{
IsRelevant = isRelevant
};
var properties = new MacroStabilityOutwardsFailureMechanismProperties(failureMechanism);
// Call & Assert
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Name)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.Code)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(nameof(properties.IsRelevant)));
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.IsTrue(properties.DynamicVisibleValidationMethod(null));
}
}
}