// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of the D-Soil Model application. // // The D-Soil Model application 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.Collections.Generic; using System.Linq; using Deltares.Geotechnics; using Deltares.Geotechnics.Mechanisms; using Deltares.Probabilistic; using Deltares.Standard; using Deltares.Standard.Reflection; using NUnit.Framework; namespace Deltares.DSoilModel.Data.Tests { [TestFixture] class DSoilModelDataSourceRedirectorTests { [TestCase("DistributionType")] [TestCase("Mean")] [TestCase("Deviation")] [TestCase("Variation")] [TestCase("DeviationType")] [TestCase("Shift")] [TestCase("Minimum")] [TestCase("Maximum")] [TestCase("Shape")] [TestCase("ShapeB")] [TestCase("Scale")] [TestCase("Rate")] public void StochastPropertiesTest(string propertyName) { var pi = PropertyInfoSupport.GetPropertyInfo(typeof (Stochast), propertyName); Assert.Contains(pi, DSoilModelDataSourceRedirector.StochastProperties); } [TestCase("CohesionStochast")] [TestCase("AbovePhreaticLevelStochast")] public void GetRedirectedDataSourcesTest_SourceSoilStochast(string propertyName) { var redirector = new DSoilModelDataSourceRedirector(); var source = new Soil(); var propertyInfo = PropertyInfoSupport.GetPropertyInfo(typeof(Soil), propertyName); var stochast = (Stochast)propertyInfo.GetValue(source, null); // Enable the data source manager DataSourceManager.DataSources = new List(); DataSourceManager.Active = true; DataSourceManager.StartListening(); DataSourceManager.Redirector = new DSoilModelDataSourceRedirector(); // Set user as CurrentSource DataSourceManager.CurrentSource = DataSourceSystemType.User; var dataSources = redirector.GetRedirectedDataSources(source, propertyName).ToList(); // As there are no datasources in the manager, source and property must not be redirected Assert.IsNotNull(dataSources); Assert.AreEqual(1, dataSources.Count); Assert.AreEqual(source, dataSources[0].Source); Assert.AreEqual(propertyName, dataSources[0].Property); // Add redirection info var listdsi = new List(); var dsi1 = new DataSourceInfo { Source = stochast //source.CohesionStochast }; dsi1.AddChangedProperty(propertyName, DataSourceSystemType.User); listdsi.Add(dsi1); DataSourceManager.DataSources = listdsi; dataSources = redirector.GetRedirectedDataSources(source, propertyName).ToList(); // source/property must now be found and return the subproperties of the stochast Assert.IsNotNull(dataSources); Assert.AreEqual(7, dataSources.Count); Assert.AreEqual("DistributionType", dataSources[0].Property); Assert.AreEqual("Mean", dataSources[1].Property); Assert.AreEqual("Deviation", dataSources[2].Property); Assert.AreEqual("Variation", dataSources[3].Property); Assert.AreEqual("DeviationType", dataSources[4].Property); Assert.AreEqual("Shift", dataSources[5].Property); Assert.AreEqual(propertyName, dataSources[6].Property); // Changing CurrentSource should not matter DataSourceManager.CurrentSource = DataSourceSystemType.MGeobase; dataSources = redirector.GetRedirectedDataSources(source, propertyName).ToList(); Assert.IsNotNull(dataSources); Assert.AreEqual(7, dataSources.Count); Assert.AreEqual("DistributionType", dataSources[0].Property); Assert.AreEqual("Mean", dataSources[1].Property); Assert.AreEqual("Deviation", dataSources[2].Property); Assert.AreEqual("Variation", dataSources[3].Property); Assert.AreEqual("DeviationType", dataSources[4].Property); Assert.AreEqual("Shift", dataSources[5].Property); Assert.AreEqual(propertyName, dataSources[6].Property); } [TestCase("Cohesion")] [TestCase("AbovePhreaticLevel")] public void GetRedirectedDataSourcesTest_SourceSoilNonStochastWithAssociatedStochast(string propertyName) { var redirector = new DSoilModelDataSourceRedirector(); var source = new Soil(); // Empty mechanisms for Soil Soil.Mechanisms = new Mechanism[0]; var propertyInfo = PropertyInfoSupport.GetPropertyInfo(typeof(Soil), propertyName + "Stochast"); var stochast = (Stochast)propertyInfo.GetValue(source, null); // Enable the data source manager DataSourceManager.Active = true; DataSourceManager.StartListening(); DataSourceManager.Redirector = new DSoilModelDataSourceRedirector(); // Set user as CurrentSource DataSourceManager.CurrentSource = DataSourceSystemType.User; var dataSources = redirector.GetRedirectedDataSources(source, propertyName).ToList(); // As there are no stochasts visible in a default soil without mechanisms, source and property must not be redirected Assert.IsNotNull(dataSources); Assert.AreEqual(1, dataSources.Count); Assert.AreEqual(source, dataSources[0].Source); Assert.AreEqual(propertyName, dataSources[0].Property); // Set mechanism for Soil so the stochasts become visible Soil.Mechanisms = new[] { Mechanism.None }; // Now the redirection must take place dataSources = redirector.GetRedirectedDataSources(source, propertyName).ToList(); Assert.IsNotNull(dataSources); Assert.AreEqual(2, dataSources.Count); Assert.AreEqual(stochast, dataSources[0].Source); Assert.AreEqual("ActualValue", dataSources[0].Property); Assert.AreEqual(source, dataSources[1].Source); Assert.AreEqual(propertyName, dataSources[1].Property); } [TestCase("Variation")] [TestCase("DeviationVariation")] public void GetRedirectedDataSourcesTest_SourceStochastVariations(string propertyName) { var redirector = new DSoilModelDataSourceRedirector(); var source = new Soil(); // Enable the data source manager DataSourceManager.Active = true; DataSourceManager.StartListening(); DataSourceManager.Redirector = new DSoilModelDataSourceRedirector(); // Set user as CurrentSource DataSourceManager.CurrentSource = DataSourceSystemType.User; var dataSources = redirector.GetRedirectedDataSources(source.CohesionStochast, propertyName).ToList(); // property must be redirected to deviation Assert.IsNotNull(dataSources); Assert.AreEqual("Deviation", dataSources[0].Property); DataSourceManager.CurrentSource = DataSourceSystemType.Csv; dataSources = redirector.GetRedirectedDataSources(source.CohesionStochast, propertyName).ToList(); // property must always be redirected as it is independend of the CurrentSource Assert.IsNotNull(dataSources); Assert.AreEqual("Deviation", dataSources[0].Property); } [Test] public void GetRedirectedDataSourcesTest_SourceStochastDeviationType() { string propertyName = "DeviationTypeString"; var redirector = new DSoilModelDataSourceRedirector(); var source = new Soil(); // Enable the data source manager DataSourceManager.Active = true; DataSourceManager.StartListening(); DataSourceManager.Redirector = new DSoilModelDataSourceRedirector(); // Set user as CurrentSource DataSourceManager.CurrentSource = DataSourceSystemType.User; var dataSources = redirector.GetRedirectedDataSources(source.CohesionStochast, propertyName).ToList(); // property must be redirected to deviation Assert.IsNotNull(dataSources); Assert.AreEqual("DeviationType", dataSources[0].Property); DataSourceManager.CurrentSource = DataSourceSystemType.Csv; dataSources = redirector.GetRedirectedDataSources(source.CohesionStochast, propertyName).ToList(); // property must always be redirected as it is independend of the CurrentSource Assert.IsNotNull(dataSources); Assert.AreEqual("DeviationType", dataSources[0].Property); } } }