// 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 { [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 mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution( new IFailureMechanism[0], otherContribution, 0.1, 1.0 / 30000)); mocks.ReplayAll(); var failureMechanism = new TestFailureMechanism { IsRelevant = isRelevant }; // 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($"Overig ({otherContribution})", properties.Contribution); Assert.AreEqual(failureMechanism.IsRelevant, properties.IsRelevant); mocks.VerifyAll(); } [Test] [TestCase(true)] [TestCase(false)] public void Constructor_WithIsRelevant_ReturnCorrectPropertyValues(bool isRelevant) { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); mocks.ReplayAll(); var failureMechanism = new TestFailureMechanism { IsRelevant = isRelevant }; // Call var properties = new StandAloneFailureMechanismProperties(failureMechanism, assessmentSection); // Assert Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); Assert.AreEqual(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(4, dynamicProperties.Count); PropertyDescriptor nameProperty = dynamicProperties[0]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, generalCategory, "Naam", "De naam van het toetsspoor.", true); PropertyDescriptor codeProperty = dynamicProperties[1]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(codeProperty, generalCategory, "Label", "Het label van het toetsspoor.", true); PropertyDescriptor contributionProperty = dynamicProperties[2]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(contributionProperty, generalCategory, "Faalkansbijdrage [%]", "Procentuele bijdrage van dit toetsspoor aan de totale overstromingskans van het traject.", true); PropertyDescriptor isRelevantProperty = dynamicProperties[3]; 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(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); 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.IsRelevant))); Assert.AreEqual(isRelevant, properties.DynamicVisibleValidationMethod(nameof(properties.Contribution))); Assert.IsTrue(properties.DynamicVisibleValidationMethod(null)); mocks.VerifyAll(); } } }