// 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.Gui.PropertyBag;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Integration.Forms.PropertyClasses.StandAlone;
namespace Ringtoets.Integration.Forms.Test.PropertyClasses.StandAlone
{
[TestFixture]
public class StandAloneFailureMechanismPropertiesTest
{
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;
[Test]
public void Constructor_FailureMechanismNull_ThrowsArgumentNullException()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
// Call
TestDelegate test = () => new StandAloneFailureMechanismProperties(null, assessmentSection);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("failureMechanism", paramName);
mocks.VerifyAll();
}
[Test]
public void Constructor_AssessmentSectionNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => new StandAloneFailureMechanismProperties(new TestFailureMechanism(), null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("assessmentSection", paramName);
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void Constructor_ExpectedValues(bool isRelevant)
{
// Setup
var random = new Random(39);
double otherContribution = random.NextDouble();
var failureMechanism = new TestFailureMechanism
{
IsRelevant = isRelevant
};
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
assessmentSection.Stub(section => section.GetContributingFailureMechanisms()).Return(new IFailureMechanism[]
{
failureMechanism,
new OtherFailureMechanism
{
Contribution = otherContribution
}
});
mocks.ReplayAll();
// Call
var properties = new StandAloneFailureMechanismProperties(failureMechanism, assessmentSection);
// Assert
Assert.IsInstanceOf>(properties);
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($"Overig ({otherContribution})", properties.Contribution);
Assert.AreEqual(failureMechanism.IsRelevant, properties.IsRelevant);
mocks.VerifyAll();
}
[Test]
public void Constructor_IsRelevantTrue_PropertiesHaveExpectedAttributesValues()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new TestFailureMechanism
{
IsRelevant = true
};
// Call
var properties = new StandAloneFailureMechanismProperties(failureMechanism, assessmentSection);
// Assert
const string generalCategory = "Algemeen";
PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);
Assert.AreEqual(5, dynamicProperties.Count);
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);
mocks.VerifyAll();
}
[Test]
public void Constructor_IsRelevantFalse_PropertiesHaveExpectedAttributesValues()
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new TestFailureMechanism
{
IsRelevant = false
};
// Call
var properties = new StandAloneFailureMechanismProperties(failureMechanism, 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 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);
mocks.VerifyAll();
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void DynamicVisibleValidationMethod_DependingOnRelevancy_ReturnExpectedVisibility(bool isRelevant)
{
// Setup
var mocks = new MockRepository();
var assessmentSection = mocks.Stub();
mocks.ReplayAll();
var failureMechanism = new TestFailureMechanism
{
IsRelevant = isRelevant
};
var properties = new StandAloneFailureMechanismProperties(failureMechanism, 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.IsTrue(properties.DynamicVisibleValidationMethod(null));
mocks.VerifyAll();
}
}
}