// 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.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Integration.Forms.PropertyClasses.StandAlone;
using Riskeer.Integration.Data.StandAlone;
namespace Ringtoets.Integration.Forms.Test.PropertyClasses.StandAlone
{
public class PipingStructureFailureMechanismPropertiesTest
{
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 nPropertyIndex = 5;
[Test]
public void Constructor_DataIsNull_ThrowArgumentNullException()
{
// Call
TestDelegate test = () => new PipingStructureFailureMechanismProperties(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 PipingStructureFailureMechanism
{
IsRelevant = isRelevant
};
// Call
var properties = new PipingStructureFailureMechanismProperties(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);
Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
Assert.AreEqual(failureMechanism.N,
properties.N,
properties.N.GetAccuracy());
}
[Test]
public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues()
{
// Setup
var failureMechanism = new PipingStructureFailureMechanism
{
IsRelevant = true
};
// Call
var properties = new PipingStructureFailureMechanismProperties(failureMechanism);
// Assert
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(6, dynamicProperties.Count);
const string generalCategory = "Algemeen";
const string lengthEffectCategory = "Lengte-effect parameters";
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 nProperty = dynamicProperties[nPropertyIndex];
PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nProperty,
lengthEffectCategory,
"N [-]",
"De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in de beoordeling.");
}
[Test]
public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues()
{
// Setup
var failureMechanism = new PipingStructureFailureMechanism
{
IsRelevant = false
};
// Call
var properties = new PipingStructureFailureMechanismProperties(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.9)]
[TestCase(20.1)]
[TestCase(30)]
public void N_SetInvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value)
{
// Setup
var mocks = new MockRepository();
var observer = mocks.StrictMock();
mocks.ReplayAll();
var failureMechanism = new PipingStructureFailureMechanism();
failureMechanism.Attach(observer);
var properties = new PipingStructureFailureMechanismProperties(failureMechanism);
// Call
TestDelegate call = () => properties.N = (RoundedDouble) value;
// Assert
const string expectedMessage = "De waarde voor 'N' moet in het bereik [1,00, 20,00] liggen.";
TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
mocks.VerifyAll();
}
[Test]
[TestCase(1)]
[TestCase(12)]
[TestCase(20)]
public void N_SetValidValue_SetsValueAndUpdatesObserver(double value)
{
// Setup
var mocks = new MockRepository();
var observer = mocks.StrictMock();
observer.Expect(o => o.UpdateObserver());
mocks.ReplayAll();
var failureMechanism = new PipingStructureFailureMechanism();
failureMechanism.Attach(observer);
var properties = new PipingStructureFailureMechanismProperties(failureMechanism);
// Call
properties.N = (RoundedDouble) value;
// Assert
Assert.AreEqual(value, failureMechanism.N, failureMechanism.N.GetAccuracy());
mocks.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant)
{
// Setup
var failureMechanism = new PipingStructureFailureMechanism
{
IsRelevant = isRelevant
};
var properties = new PipingStructureFailureMechanismProperties(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.N)));
Assert.IsTrue(properties.DynamicVisibleValidationMethod(null));
}
}
}