Index: src/DSoilModel.sln =================================================================== diff -u -r63 -r131 --- src/DSoilModel.sln (.../DSoilModel.sln) (revision 63) +++ src/DSoilModel.sln (.../DSoilModel.sln) (revision 131) @@ -17,6 +17,8 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{EEEE9444-BDDA-44ED-A139-4A7B6F93BBCA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Deltares.DSoilModel.Data.Tests", "Deltares.DSoilModel.Data.Tests\Deltares.DSoilModel.Data.Tests.csproj", "{7FA5B2F2-3FEE-4706-908C-68BA03FDF084}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -49,12 +51,17 @@ {7F3A1524-E28B-47BF-94BB-4571D304BE16}.Release|x86.Build.0 = Release|x86 {E3E0CC29-5031-47E2-B230-C077B9BB5061}.Debug|x86.ActiveCfg = Debug|x86 {E3E0CC29-5031-47E2-B230-C077B9BB5061}.Release|x86.ActiveCfg = Release|x86 + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084}.Debug|x86.ActiveCfg = Debug|x86 + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084}.Debug|x86.Build.0 = Debug|x86 + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084}.Release|x86.ActiveCfg = Release|x86 + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {7F3A1524-E28B-47BF-94BB-4571D304BE16} = {EEEE9444-BDDA-44ED-A139-4A7B6F93BBCA} {7DD9B469-0E1C-4592-8ED8-197128D012CA} = {EEEE9444-BDDA-44ED-A139-4A7B6F93BBCA} + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084} = {EEEE9444-BDDA-44ED-A139-4A7B6F93BBCA} EndGlobalSection EndGlobal Index: src/Deltares.DSoilModel.Data.Tests/Properties/AssemblyInfo.cs =================================================================== diff -u --- src/Deltares.DSoilModel.Data.Tests/Properties/AssemblyInfo.cs (revision 0) +++ src/Deltares.DSoilModel.Data.Tests/Properties/AssemblyInfo.cs (revision 131) @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Deltares.DSoilModel.Data.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Deltares.DSoilModel.Data.Tests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f4e63c96-f642-4b77-81ea-c956250e0175")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Index: src/packages/repositories.config =================================================================== diff -u -r18 -r131 --- src/packages/repositories.config (.../repositories.config) (revision 18) +++ src/packages/repositories.config (.../repositories.config) (revision 131) @@ -1,6 +1,7 @@  + Index: src/Deltares.DSoilModel.Data.Tests/packages.config =================================================================== diff -u --- src/Deltares.DSoilModel.Data.Tests/packages.config (revision 0) +++ src/Deltares.DSoilModel.Data.Tests/packages.config (revision 131) @@ -0,0 +1,4 @@ + + + + \ No newline at end of file Index: src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs =================================================================== diff -u -r99 -r131 --- src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs (.../DSoilModelTransformer.cs) (revision 99) +++ src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs (.../DSoilModelTransformer.cs) (revision 131) @@ -1,5 +1,6 @@ using System; using Deltares.Geotechnics; +using Deltares.Probabilistic; using Deltares.Standard; namespace Deltares.DSoilModel.Data @@ -11,24 +12,48 @@ /// public class DSoilModelTransformer : ITransformer { + /// + /// Gets a stochast by associated property name + /// + /// + private Stochast FindAutoStochastProperty(object obj, string property) + { + // AutoStochastProperty convention, in fact, is the naming convention "{property name}Stochast" only + // so, for best performance we can locate the Stochast by name rather than looping over all stochasts checking their property association + if (!String.IsNullOrEmpty(property)) + { + var propertyInfo = obj.GetType().GetProperty(property + "Stochast"); + if (propertyInfo != null) + { + var stochast = (Stochast)propertyInfo.GetValue(obj, null); + if (stochast.AssociatedPropertyName == property || stochast.Name == property) + { + return stochast; + } + } + } + return null; + } + public double GetTransformedValue(object owner, string property, double measuredValue) { - if (owner is Soil) + if (owner is Soil || owner is PreConsolidationStress) { - var stochast = ((Soil)owner).GetStochast(property); + var stochast = FindAutoStochastProperty(owner, property); if (stochast != null) { return stochast.ActualValue; } } + return measuredValue; } public double SetTransformedValue(object owner, string property, double transformedValue) { - if (owner is Soil) + if (owner is Soil || owner is PreConsolidationStress) { - var stochast = ((Soil)owner).GetStochast(property); + var stochast = FindAutoStochastProperty(owner, property); if (stochast != null) { stochast.ActualValue = transformedValue; @@ -37,6 +62,7 @@ return stochast.Mean; } } + return transformedValue; } } Index: src/Deltares.DSoilModel.Data.Tests/Deltares.DSoilModel.Data.Tests.csproj =================================================================== diff -u --- src/Deltares.DSoilModel.Data.Tests/Deltares.DSoilModel.Data.Tests.csproj (revision 0) +++ src/Deltares.DSoilModel.Data.Tests/Deltares.DSoilModel.Data.Tests.csproj (revision 131) @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {7FA5B2F2-3FEE-4706-908C-68BA03FDF084} + Library + Properties + Deltares.DSoilModel.Data.Tests + Deltares.DSoilModel.Data.Tests + v4.0 + 512 + + + + x86 + ..\bin\Debug\ + false + + + x86 + ..\bin\Release\ + false + + + + False + ..\..\lib\Deltares\DslGeo\Deltares.Geometry.dll + + + False + ..\..\lib\Deltares\DslGeo\Deltares.Geotechnics.dll + + + False + ..\..\lib\Deltares\DslProbabilistic\Deltares.Probabilistic.dll + + + False + ..\..\lib\Deltares\DslGeo\Deltares.Standard.dll + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + True + + + + + + + + + + + + + + {37BC4D84-386E-425C-967B-CCF83E48A5F3} + Deltares.DSoilModel.Data + + + + + \ No newline at end of file Index: src/Deltares.DSoilModel.Data.Tests/DSoilModelTransformerTests.cs =================================================================== diff -u --- src/Deltares.DSoilModel.Data.Tests/DSoilModelTransformerTests.cs (revision 0) +++ src/Deltares.DSoilModel.Data.Tests/DSoilModelTransformerTests.cs (revision 131) @@ -0,0 +1,52 @@ +using System; +using System.Reflection; +using Deltares.Geotechnics; +using Deltares.Probabilistic; +using Deltares.Standard; +using Deltares.Standard.EventPublisher; +using Deltares.Standard.Reflection; +using NUnit.Framework; + +namespace Deltares.DSoilModel.Data.Tests +{ + [TestFixture] + public class DSoilModelTransformerTests + { + private bool oldIsDataEventPublishStopped; + + [TestFixtureSetUp] + public void FixtureSetup() + { + oldIsDataEventPublishStopped = DataEventPublisher.IsDataEventPublishStopped; + DataEventPublisher.IsDataEventPublishStopped = true; + + TransformerManager.Transformer = new DSoilModelTransformer(); + } + + [TestFixtureTearDown] + public void FixtureTearDown() + { + DataEventPublisher.IsDataEventPublishStopped = oldIsDataEventPublishStopped; + } + + private Stochast FindAutoStochastProperty(object obj, string property) + { + var instance = TransformerManager.Transformer as DSoilModelTransformer; + return (Stochast)instance.GetType().GetMethod("FindAutoStochastProperty", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(instance, new[] {obj, property}); + } + + [Test] + [TestCase(typeof(Soil))] +// [TestCase(typeof(PreConsolidationStress))] // TODO: yet to check + public void TestStochasticPropertiesUncoupled(Type classType) + { + var obj = Activator.CreateInstance(classType); + var stochastProperties = PropertyInfoSupport.GetPropertiesOfType(obj.GetType(), typeof (Stochast)); + foreach (BindPropertyInfo propertyInfo in stochastProperties) + { + var stochast = (Stochast) propertyInfo.GetValue(obj, null); + Assert.AreSame(stochast, FindAutoStochastProperty(obj, stochast.AssociatedPropertyName)); + } + } + } +}