Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/CalculationState/ClosingStructuresCalculationsProperties.cs =================================================================== diff -u -r03d5bf1707d5be972547304b4a8888b0aff3f511 -rfbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/CalculationState/ClosingStructuresCalculationsProperties.cs (.../ClosingStructuresCalculationsProperties.cs) (revision 03d5bf1707d5be972547304b4a8888b0aff3f511) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/CalculationState/ClosingStructuresCalculationsProperties.cs (.../ClosingStructuresCalculationsProperties.cs) (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -33,7 +33,7 @@ /// /// Calculation related ViewModel of for properties panel. /// - public class ClosingStructuresCalculationsProperties : ClosingStructuresFailureMechanismProperties + public class ClosingStructuresCalculationsProperties : ClosingStructuresFailureMechanismPropertiesBase { private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; Fisheye: Tag fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 refers to a dead (removed) revision in file `Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismProperties.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBase.cs =================================================================== diff -u --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBase.cs (revision 0) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBase.cs (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -0,0 +1,127 @@ +// 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.Collections.Generic; +using Core.Common.Util.Attributes; +using Core.Gui.Attributes; +using Core.Gui.PropertyBag; +using Riskeer.ClosingStructures.Data; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.ClosingStructures.Forms.PropertyClasses +{ + /// + /// Base ViewModel of for properties panel. + /// + public abstract class ClosingStructuresFailureMechanismPropertiesBase : ObjectProperties + { + private readonly Dictionary propertyIndexLookup; + + /// + /// Creates a new instance of . + /// + /// The instance to show the properties of. + /// The property values required to create an instance of . + /// Thrown when any parameter is null. + protected ClosingStructuresFailureMechanismPropertiesBase(ClosingStructuresFailureMechanism data, + ConstructionProperties constructionProperties) + { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + + if (constructionProperties == null) + { + throw new ArgumentNullException(nameof(constructionProperties)); + } + + Data = data; + + propertyIndexLookup = new Dictionary + { + { + nameof(Name), constructionProperties.NamePropertyIndex + }, + { + nameof(Code), constructionProperties.CodePropertyIndex + } + }; + } + + [DynamicPropertyOrderEvaluationMethod] + public int DynamicPropertyOrderEvaluationMethod(string propertyName) + { + propertyIndexLookup.TryGetValue(propertyName, out int propertyIndex); + + return propertyIndex; + } + + /// + /// Class holding the various construction parameters for . + /// + public class ConstructionProperties + { + #region General + + /// + /// Gets or sets the property index for . + /// + public int NamePropertyIndex { get; set; } + + /// + /// Gets or sets the property index for . + /// + public int CodePropertyIndex { get; set; } + + #endregion + } + + #region General + + [DynamicPropertyOrder] + [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; + } + } + + [DynamicPropertyOrder] + [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; + } + } + + #endregion + } +} \ No newline at end of file Index: Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/RegistrationState/ClosingStructuresFailurePathProperties.cs =================================================================== diff -u -r03d5bf1707d5be972547304b4a8888b0aff3f511 -rfbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 --- Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/RegistrationState/ClosingStructuresFailurePathProperties.cs (.../ClosingStructuresFailurePathProperties.cs) (revision 03d5bf1707d5be972547304b4a8888b0aff3f511) +++ Riskeer/ClosingStructures/src/Riskeer.ClosingStructures.Forms/PropertyClasses/RegistrationState/ClosingStructuresFailurePathProperties.cs (.../ClosingStructuresFailurePathProperties.cs) (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -32,7 +32,7 @@ /// /// Failure path related ViewModel of for properties panel. /// - public class ClosingStructuresFailurePathProperties : ClosingStructuresFailureMechanismProperties + public class ClosingStructuresFailurePathProperties : ClosingStructuresFailureMechanismPropertiesBase { private const int namePropertyIndex = 1; private const int codePropertyIndex = 2; Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/CalculationState/ClosingStructuresCalculationsPropertiesTest.cs =================================================================== diff -u -r5d64efd20be27a696d70f00dcca9b407380a1473 -rfbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/CalculationState/ClosingStructuresCalculationsPropertiesTest.cs (.../ClosingStructuresCalculationsPropertiesTest.cs) (revision 5d64efd20be27a696d70f00dcca9b407380a1473) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/CalculationState/ClosingStructuresCalculationsPropertiesTest.cs (.../ClosingStructuresCalculationsPropertiesTest.cs) (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -62,7 +62,7 @@ var properties = new ClosingStructuresCalculationsProperties(failureMechanism); // Assert - Assert.IsInstanceOf(properties); + Assert.IsInstanceOf(properties); Assert.AreSame(failureMechanism, properties.Data); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBaseTest.cs =================================================================== diff -u --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBaseTest.cs (revision 0) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesBaseTest.cs (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -0,0 +1,113 @@ +// 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.Gui.PropertyBag; +using Core.Gui.TestUtil; +using NUnit.Framework; +using Riskeer.ClosingStructures.Data; +using Riskeer.ClosingStructures.Forms.PropertyClasses; + +namespace Riskeer.ClosingStructures.Forms.Test.PropertyClasses +{ + public class ClosingStructuresFailureMechanismPropertiesBaseTest + { + private const int namePropertyIndex = 1; + private const int codePropertyIndex = 0; + + [Test] + public void Constructor_DataNull_ThrowArgumentNullException() + { + // Call + void Call() => new TestClosingStructuresFailureMechanismProperties(null, new ClosingStructuresFailureMechanismPropertiesBase.ConstructionProperties()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("data", exception.ParamName); + } + + [Test] + public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException() + { + // Call + void Call() => new TestClosingStructuresFailureMechanismProperties(new ClosingStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("constructionProperties", exception.ParamName); + } + + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + var properties = new TestClosingStructuresFailureMechanismProperties(failureMechanism, new ClosingStructuresFailureMechanismPropertiesBase.ConstructionProperties()); + + // Assert + Assert.IsInstanceOf>(properties); + Assert.AreSame(failureMechanism, properties.Data); + Assert.AreEqual(failureMechanism.Name, properties.Name); + Assert.AreEqual(failureMechanism.Code, properties.Code); + } + + [Test] + public void Constructor_Always_PropertiesHaveExpectedAttributeValues() + { + // Call + var properties = new TestClosingStructuresFailureMechanismProperties(new ClosingStructuresFailureMechanism(), new ClosingStructuresFailureMechanismPropertiesBase.ConstructionProperties + { + NamePropertyIndex = namePropertyIndex, + CodePropertyIndex = codePropertyIndex + }); + + // Assert + const string generalCategory = "Algemeen"; + + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(2, dynamicProperties.Count); + + PropertyDescriptor nameProperty = dynamicProperties[namePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty, + generalCategory, + "Naam", + "De naam van het faalmechanisme.", + true); + + PropertyDescriptor codeProperty = dynamicProperties[codePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(codeProperty, + generalCategory, + "Label", + "Het label van het faalmechanisme.", + true); + } + + private class TestClosingStructuresFailureMechanismProperties : ClosingStructuresFailureMechanismPropertiesBase + { + public TestClosingStructuresFailureMechanismProperties(ClosingStructuresFailureMechanism data, + ConstructionProperties constructionProperties) + : base(data, constructionProperties) {} + } + } +} \ No newline at end of file Fisheye: Tag fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 refers to a dead (removed) revision in file `Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresFailureMechanismPropertiesTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/RegistrationState/ClosingStructuresFailurePathPropertiesTest.cs =================================================================== diff -u -r5d64efd20be27a696d70f00dcca9b407380a1473 -rfbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6 --- Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/RegistrationState/ClosingStructuresFailurePathPropertiesTest.cs (.../ClosingStructuresFailurePathPropertiesTest.cs) (revision 5d64efd20be27a696d70f00dcca9b407380a1473) +++ Riskeer/ClosingStructures/test/Riskeer.ClosingStructures.Forms.Test/PropertyClasses/RegistrationState/ClosingStructuresFailurePathPropertiesTest.cs (.../ClosingStructuresFailurePathPropertiesTest.cs) (revision fbedcc0d6fe8f7c9252ed1bfc9d24d757f7c21a6) @@ -57,7 +57,7 @@ var properties = new ClosingStructuresFailurePathProperties(failureMechanism); // Assert - Assert.IsInstanceOf(properties); + Assert.IsInstanceOf(properties); Assert.AreSame(failureMechanism, properties.Data); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code);