// Copyright (C) Stichting Deltares 2016. 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.ComponentModel; using Core.Common.Base; using Core.Common.Gui.PropertyBag; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Data.Properties; using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HeightStructures.Forms.PropertyClasses; namespace Ringtoets.HeightStructures.Forms.Test.PropertyClasses { [TestFixture] public class HeightStructuresFailureMechanismContextPropertiesTest { private const int namePropertyIndex = 0; private const int codePropertyIndex = 1; private const int gravitationalAccelerationPropertyIndex = 2; private const int lengthEffectPropertyIndex = 3; private const int modelFactorOvertoppingFlowPropertyIndex = 4; private const int modelFactorStorageVolumePropertyIndex = 5; private MockRepository mockRepository; [SetUp] public void SetUp() { mockRepository = new MockRepository(); } [Test] public void Constructor_ExpectedValues() { // Call var properties = new HeightStructuresFailureMechanismContextProperties(); // Assert Assert.IsInstanceOf>(properties); Assert.IsNull(properties.Data); } [Test] public void Data_SetNewFailureMechanismContextInstance_ReturnCorrectPropertyValues() { // Setup var assessmentSectionMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); var properties = new HeightStructuresFailureMechanismContextProperties(); // Call properties.Data = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock); // Assert Assert.AreEqual(Resources.HeightStructuresFailureMechanism_DisplayName, properties.Name); Assert.AreEqual(Resources.HeightStructuresFailureMechanism_Code, properties.Code); Assert.AreEqual(failureMechanism.GeneralInput.GravitationalAcceleration, properties.GravitationalAcceleration); Assert.AreEqual(2, properties.LengthEffect); var generalInput = failureMechanism.GeneralInput; Assert.AreEqual(generalInput.ModelFactorOvertoppingFlow.Mean, properties.ModelFactorOvertoppingFlow.Mean); Assert.AreEqual(generalInput.ModelFactorOvertoppingFlow.StandardDeviation, properties.ModelFactorOvertoppingFlow.StandardDeviation); Assert.AreEqual(generalInput.ModelFactorStorageVolume.Mean, properties.ModelFactorStorageVolume.Mean); Assert.AreEqual(generalInput.ModelFactorStorageVolume.StandardDeviation, properties.ModelFactorStorageVolume.StandardDeviation); mockRepository.VerifyAll(); } [Test] public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup var observerMock = mockRepository.StrictMock(); const int numberProperties = 1; observerMock.Expect(o => o.UpdateObserver()).Repeat.Times(numberProperties); var assessmentSectionMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.Attach(observerMock); var properties = new HeightStructuresFailureMechanismContextProperties { Data = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock) }; const int newLengthEffect = 10; // Call properties.LengthEffect = newLengthEffect; // Assert Assert.AreEqual(newLengthEffect, failureMechanism.GeneralInput.N); mockRepository.VerifyAll(); } [Test] public void PropertyAttributes_ReturnExpectedValues() { // Setup var assessmentSectionMock = mockRepository.StrictMock(); mockRepository.ReplayAll(); var failureMechanism = new HeightStructuresFailureMechanism(); // Call var properties = new HeightStructuresFailureMechanismContextProperties { Data = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSectionMock) }; // Assert var generalCategory = "Algemeen"; var lengthEffectCategory = "Lengte-effect parameters"; var modelSettingsCategory = "Modelinstellingen"; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(6, 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 gravitationalAccelerationProperty = dynamicProperties[gravitationalAccelerationPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(gravitationalAccelerationProperty, generalCategory, "Valversnelling [m/s²]", "Valversnelling.", true); PropertyDescriptor lengthEffectProperty = dynamicProperties[lengthEffectPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(lengthEffectProperty, lengthEffectCategory, "N [-]", "De parameter 'N' die gebruikt wordt om het lengte-effect mee te nemen in een semi-probabilistische beoordeling."); PropertyDescriptor modelFactorOvertoppingFlowProperty = dynamicProperties[modelFactorOvertoppingFlowPropertyIndex]; Assert.IsInstanceOf(modelFactorOvertoppingFlowProperty.Converter); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(modelFactorOvertoppingFlowProperty, modelSettingsCategory, "Modelfactor overslagdebiet [-]", "Modelfactor voor het overslagdebiet.", true); PropertyDescriptor modelFactorStorageVolumeProperty = dynamicProperties[modelFactorStorageVolumePropertyIndex]; Assert.IsInstanceOf(modelFactorStorageVolumeProperty.Converter); PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(modelFactorStorageVolumeProperty, modelSettingsCategory, "Modelfactor kombergend vermogen [-]", "Modelfactor kombergend vermogen.", true); mockRepository.VerifyAll(); } } }