using System; using System.Security.Cryptography.X509Certificates; using System.Windows.Forms; using Deltares.DSoilModel.Data; using Deltares.Geotechnics; using Deltares.Probabilistic; using Deltares.Standard; using Deltares.Standard.Reflection; using NUnit.Framework; namespace Deltares.DSoilModel.Tests { [TestFixture] public class DSoilModelTransformerTest { private ITransformer oldTransformer; private bool oldReliability; [SetUp] public void Setup() { oldTransformer = TransformerManager.Transformer; oldReliability = ReliabilityView.IsReliability; } [TearDown] public void TearDown() { TransformerManager.Transformer = oldTransformer; ReliabilityView.IsReliability = oldReliability; } [Test] [TestCase(true)] [TestCase(false)] public void TransformerMapsSoilPropertiesToActualValues(bool reliability) { ReliabilityView.IsReliability = reliability; var transformer = new DSoilModelTransformer(); TransformerManager.Transformer = transformer; var soil = new Soil(); var stochastProperties = PropertyInfoSupport.GetPropertiesOfType(typeof(Soil), typeof(Stochast)); foreach (BindPropertyInfo stochastPropertyInfo in stochastProperties) { var stochast = (Stochast)stochastPropertyInfo.GetValue(soil, null); stochast.ActualValue = 1.23; stochast.Mean = double.NaN; // call transformer directly, always returns ActualValue, ignoring measuredValue input Assert.AreEqual(1.23, transformer.GetTransformedValue(soil, stochast.AssociatedPropertyName, 9999)); // check associated property indeed returns ActualValue var propertyInfo = typeof(Soil).GetProperty(stochast.AssociatedPropertyName); var value = propertyInfo.GetValue(soil, null); if (propertyInfo.PropertyType == typeof(double)) { Assert.AreEqual(1.23, value); } // reverse transformation, directly transformer.SetTransformedValue(soil, stochast.AssociatedPropertyName, 3.21); Assert.AreEqual(3.21, stochast.ActualValue); // reverse via associated property if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(soil, 9.87, null); Assert.AreEqual(9.87, stochast.ActualValue); } } } } }