Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PropertyClasses/HeightStructuresCalculationsProperties.cs =================================================================== diff -u --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PropertyClasses/HeightStructuresCalculationsProperties.cs (revision 0) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PropertyClasses/HeightStructuresCalculationsProperties.cs (revision 747f7f5a2b6628745f4fa5773ecf65e4e3323cca) @@ -0,0 +1,179 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Data; +using Core.Common.Util.Attributes; +using Core.Gui.Attributes; +using Core.Gui.PropertyBag; +using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.HeightStructures.Data; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.HeightStructures.Forms.PropertyClasses +{ + /// + /// ViewModel of for properties panel. + /// + public class HeightStructuresCalculationsProperties : ObjectProperties + { + private const int namePropertyIndex = 1; + private const int codePropertyIndex = 2; + private const int groupPropertyIndex = 3; + private const int contributionPropertyIndex = 4; + private const int gravitationalAccelerationPropertyIndex = 5; + private const int nPropertyIndex = 6; + private const int modelFactorOvertoppingFlowPropertyIndex = 7; + private const int modelFactorStorageVolumePropertyIndex = 8; + + /// + /// Creates a new instance of . + /// + /// The instance to show the properties of. + /// Thrown when + /// is null. + public HeightStructuresCalculationsProperties(HeightStructuresFailureMechanism data) + { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + + Data = data; + } + + #region Length effect parameters + + [PropertyOrder(nPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_LengthEffect))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_N_Description))] + public RoundedDouble N + { + get + { + return data.GeneralInput.N; + } + set + { + data.GeneralInput.N = value; + data.NotifyObservers(); + } + } + + #endregion + + #region General + + [PropertyOrder(namePropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Name_Description))] + public string Name + { + get + { + return data.Name; + } + } + + [PropertyOrder(codePropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Code_Description))] + public string Code + { + get + { + return data.Code; + } + } + + [PropertyOrder(groupPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Group_Description))] + public int Group + { + get + { + return data.Group; + } + } + + [PropertyOrder(contributionPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.FailureMechanism_Contribution_Description))] + public double Contribution + { + get + { + return data.Contribution; + } + } + + [PropertyOrder(gravitationalAccelerationPropertyIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_General))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.GravitationalAcceleration_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.GravitationalAcceleration_Description))] + public RoundedDouble GravitationalAcceleration + { + get + { + return data.GeneralInput.GravitationalAcceleration; + } + } + + #endregion + + #region Model settings + + [PropertyOrder(modelFactorOvertoppingFlowPropertyIndex)] + [TypeConverter(typeof(ExpandableObjectConverter))] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_ModelSettings))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.StructuresInputFailureMechanismContext_ModelFactorOvertoppingFlow_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.StructuresInputFailureMechanismContext_ModelFactorOvertoppingFlow_Description))] + public LogNormalDistributionProperties ModelFactorOvertoppingFlow + { + get + { + return new LogNormalDistributionProperties(data.GeneralInput.ModelFactorOvertoppingFlow); + } + } + + [PropertyOrder(modelFactorStorageVolumePropertyIndex)] + [TypeConverter(typeof(ExpandableObjectConverter))] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_ModelSettings))] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.StructuresInputFailureMechanismContext_ModelFactorStorageVolume_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.StructuresInputFailureMechanismContext_ModelFactorStorageVolume_Description))] + public LogNormalDistributionProperties ModelFactorStorageVolume + { + get + { + return new LogNormalDistributionProperties(data.GeneralInput.ModelFactorStorageVolume); + } + } + + #endregion + } +} \ No newline at end of file Fisheye: Tag 747f7f5a2b6628745f4fa5773ecf65e4e3323cca refers to a dead (removed) revision in file `Riskeer/HeightStructures/src/Riskeer.HeightStructures.Forms/PropertyClasses/HeightStructuresFailureMechanismProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -ra57ba8402ed8a4fbfc5d9f04ad40946746a4fbd6 -r747f7f5a2b6628745f4fa5773ecf65e4e3323cca --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision a57ba8402ed8a4fbfc5d9f04ad40946746a4fbd6) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 747f7f5a2b6628745f4fa5773ecf65e4e3323cca) @@ -70,9 +70,9 @@ { public override IEnumerable GetPropertyInfos() { - yield return new PropertyInfo + yield return new PropertyInfo { - CreateInstance = context => new HeightStructuresFailureMechanismProperties(context.WrappedData) + CreateInstance = context => new HeightStructuresCalculationsProperties(context.WrappedData) }; yield return new PropertyInfo(); yield return new PropertyInfo> Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresCalculationsPropertiesTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresCalculationsPropertiesTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresCalculationsPropertiesTest.cs (revision 747f7f5a2b6628745f4fa5773ecf65e4e3323cca) @@ -0,0 +1,210 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.TestUtil; +using Core.Gui.PropertyBag; +using Core.Gui.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.TestUtil; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Forms.PropertyClasses; + +namespace Riskeer.HeightStructures.Forms.Test.PropertyClasses +{ + [TestFixture] + public class HeightStructuresCalculationsPropertiesTest + { + private const int namePropertyIndex = 0; + private const int codePropertyIndex = 1; + private const int groupPropertyIndex = 2; + private const int contributionPropertyIndex = 3; + private const int gravitationalAccelerationPropertyIndex = 4; + private const int nPropertyIndex = 5; + private const int modelFactorOvertoppingFlowPropertyIndex = 6; + private const int modelFactorStorageVolumePropertyIndex = 7; + + [Test] + public void Constructor_DataNull_ThrowArgumentNullException() + { + // Call + void Call() => new HeightStructuresCalculationsProperties(null); + + // Assert + string paramName = Assert.Throws(Call).ParamName; + Assert.AreEqual("data", paramName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + var properties = new HeightStructuresCalculationsProperties(failureMechanism); + + // 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(failureMechanism.Contribution, properties.Contribution); + + GeneralHeightStructuresInput generalInput = failureMechanism.GeneralInput; + Assert.AreEqual(generalInput.N, properties.N); + Assert.AreEqual(generalInput.GravitationalAcceleration, properties.GravitationalAcceleration); + 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); + } + + [Test] + public void Constructor_Always_PropertiesHaveExpectedAttributeValues() + { + // Call + var properties = new HeightStructuresCalculationsProperties(new HeightStructuresFailureMechanism()); + + // Assert + const string generalCategory = "Algemeen"; + const string lengthEffectCategory = "Lengte-effect parameters"; + const string modelSettingsCategory = "Modelinstellingen"; + + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(8, 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 gravitationalAccelerationProperty = dynamicProperties[gravitationalAccelerationPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(gravitationalAccelerationProperty, + generalCategory, + "Valversnelling [m/s²]", + "Valversnelling.", + 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."); + + 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); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(0.0)] + [TestCase(-1.0)] + [TestCase(-20.0)] + public void N_InvalidValue_ThrowsArgumentOutOfRangeExceptionNoNotifications(double value) + { + // Setup + var mockRepository = new MockRepository(); + var observer = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.Attach(observer); + + var properties = new HeightStructuresCalculationsProperties(failureMechanism); + + // Call + TestDelegate test = () => properties.N = (RoundedDouble) value; + + // Assert + const string expectedMessage = "De waarde voor 'N' moet in het bereik [1,00, 20,00] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(1.0)] + [TestCase(10.0)] + [TestCase(20.0)] + public void N_SetValidValue_UpdateDataAndNotifyObservers(double value) + { + // Setup + var mockRepository = new MockRepository(); + var observer = mockRepository.StrictMock(); + observer.Expect(o => o.UpdateObserver()); + mockRepository.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + failureMechanism.Attach(observer); + + var properties = new HeightStructuresCalculationsProperties(failureMechanism); + + // Call + properties.N = (RoundedDouble) value; + + // Assert + Assert.AreEqual(value, failureMechanism.GeneralInput.N, failureMechanism.GeneralInput.N.GetAccuracy()); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Fisheye: Tag 747f7f5a2b6628745f4fa5773ecf65e4e3323cca refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresFailureMechanismPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs =================================================================== diff -u -r886b86a66f072735567285a3489923186c236c32 -r747f7f5a2b6628745f4fa5773ecf65e4e3323cca --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 886b86a66f072735567285a3489923186c236c32) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/HeightStructuresPluginTest.cs (.../HeightStructuresPluginTest.cs) (revision 747f7f5a2b6628745f4fa5773ecf65e4e3323cca) @@ -67,7 +67,7 @@ PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, typeof(HeightStructuresCalculationsContext), - typeof(HeightStructuresFailureMechanismProperties)); + typeof(HeightStructuresCalculationsProperties)); PluginTestHelper.AssertPropertyInfoDefined( propertyInfos, Fisheye: Tag 747f7f5a2b6628745f4fa5773ecf65e4e3323cca refers to a dead (removed) revision in file `Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/PropertyInfos/HeightStructuresCalculationsContextPropertyInfoTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/PropertyInfos/HeightStructuresCalculationsPropertyInfoTest.cs =================================================================== diff -u --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/PropertyInfos/HeightStructuresCalculationsPropertyInfoTest.cs (revision 0) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/PropertyInfos/HeightStructuresCalculationsPropertyInfoTest.cs (revision 747f7f5a2b6628745f4fa5773ecf65e4e3323cca) @@ -0,0 +1,82 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Linq; +using Core.Gui.Plugin; +using Core.Gui.PropertyBag; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Forms.PresentationObjects; +using Riskeer.HeightStructures.Forms.PropertyClasses; + +namespace Riskeer.HeightStructures.Plugin.Test.PropertyInfos +{ + [TestFixture] + public class HeightStructuresCalculationsPropertyInfoTest + { + private HeightStructuresPlugin plugin; + private PropertyInfo info; + + [SetUp] + public void SetUp() + { + plugin = new HeightStructuresPlugin(); + info = plugin.GetPropertyInfos().First(tni => tni.PropertyObjectType == typeof(HeightStructuresCalculationsProperties)); + } + + [TearDown] + public void TearDown() + { + plugin.Dispose(); + } + + [Test] + public void Initialized_Always_ExpectedPropertiesSet() + { + // Assert + Assert.AreEqual(typeof(HeightStructuresCalculationsContext), info.DataType); + Assert.AreEqual(typeof(HeightStructuresCalculationsProperties), info.PropertyObjectType); + } + + [Test] + public void CreateInstance_WithContext_NewPropertiesWithFailureMechanismAsData() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var context = new HeightStructuresCalculationsContext(failureMechanism, assessmentSection); + + // Call + IObjectProperties objectProperties = info.CreateInstance(context); + + // Assert + Assert.IsInstanceOf(objectProperties); + Assert.AreSame(failureMechanism, objectProperties.Data); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file