From a82a845c6f397a1fd021c45604944203362b3315 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Fri, 8 Apr 2022 12:12:53 -0400 Subject: [PATCH] Fixes #2183 wrong error range (#2184) * Fixes #2183 wrong error range * Also update rules setter for other rules --- src/PKSim.Assets/PKSimConstants.cs | 16 +-- src/PKSim.BatchTool/DTO/FolderDTO.cs | 29 ++--- src/PKSim.Core/Model/ParameterRange.cs | 102 +++++++----------- .../PopulationAnalysisFieldBase.cs | 31 ++---- .../Parameters/ParameterScaleWithFactorDTO.cs | 14 +-- .../DTO/PopulationAnalyses/GroupingItemDTO.cs | 5 +- .../DTO/Populations/ExtractIndividualsDTO.cs | 20 ++-- .../ImportPopulationSettingsDTO.cs | 30 ++---- .../DTO/Populations/ParameterRangeDTO.cs | 27 ++--- .../CompoundParameterSelectionDTO.cs | 22 ++-- src/PKSim.UI/UserSettings.cs | 46 +++----- tests/PKSim.Tests/Core/ParameterRangeSpecs.cs | 41 +++++-- 12 files changed, 152 insertions(+), 231 deletions(-) diff --git a/src/PKSim.Assets/PKSimConstants.cs b/src/PKSim.Assets/PKSimConstants.cs index 4eca66f03..079d47882 100644 --- a/src/PKSim.Assets/PKSimConstants.cs +++ b/src/PKSim.Assets/PKSimConstants.cs @@ -1449,24 +1449,24 @@ public static class Parameter public static string ValueShouldBeGreaterThanOrEqualToZero(string parameterName) => $"{parameterName} value should be greater than or equal to 0."; - public static string MinGreaterThanDbMinValue(string parameterName, double? dbMinValue, string unit) + public static string MinGreaterThanDbMinValue(string parameterName, string displayMinValue, string unit) { - return $"Minimum value for {parameterName} should be greater than or equal to {dbMinValue} {unit}."; + return $"Minimum value for {parameterName} should be greater than or equal to {displayMinValue} {unit}."; } - public static string MaxGreaterThanDbMinValue(string parameterName, double? dbMinValue, string unit) + public static string MaxGreaterThanDbMinValue(string parameterName, string displayMinValue, string unit) { - return $"Maximum value for {parameterName} should be greater than or equal to {dbMinValue} {unit}."; + return $"Maximum value for {parameterName} should be greater than or equal to {displayMinValue} {unit}."; } - public static string MaxLessThanDbMaxValue(string parameterName, double? dbMaxValue, string unit) + public static string MaxLessThanDbMaxValue(string parameterName, string displayMaxValue, string unit) { - return $"Maximum value for {parameterName} should be less than or equal to {dbMaxValue} {unit}."; + return $"Maximum value for {parameterName} should be less than or equal to {displayMaxValue} {unit}."; } - public static string MinLessThanDbMaxValue(string parameterName, double? dbMaxValue, string unit) + public static string MinLessThanDbMaxValue(string parameterName, string displayMaxValue, string unit) { - return $"Minimum value for {parameterName} should be less than or equal to {dbMaxValue} {unit}."; + return $"Minimum value for {parameterName} should be less than or equal to {displayMaxValue} {unit}."; } public static string ValueSmallerThanMax(string parameterName, string value, string unit) diff --git a/src/PKSim.BatchTool/DTO/FolderDTO.cs b/src/PKSim.BatchTool/DTO/FolderDTO.cs index 52206feec..070598bab 100644 --- a/src/PKSim.BatchTool/DTO/FolderDTO.cs +++ b/src/PKSim.BatchTool/DTO/FolderDTO.cs @@ -28,28 +28,19 @@ public FolderDTO() private static class AllRules { - public static IBusinessRule FolderDefined - { - get { return GenericRules.NonEmptyRule(x => x.Folder); } - } + public static IBusinessRule FolderDefined { get; } = GenericRules.NonEmptyRule(x => x.Folder); - public static IBusinessRule FolderExists - { - get + public static IBusinessRule FolderExists { get; } = CreateRule.For() + .Property(item => item.Folder) + .WithRule((dto, folder) => { - return CreateRule.For() - .Property(item => item.Folder) - .WithRule((dto, folder) => - { - if (string.IsNullOrEmpty(folder)) - return false; + if (string.IsNullOrEmpty(folder)) + return false; - new DirectoryInfo(folder); - return true; - }) - .WithError(PKSimConstants.Error.ValueIsRequired); - } - } + new DirectoryInfo(folder); + return true; + }) + .WithError(PKSimConstants.Error.ValueIsRequired); } } } \ No newline at end of file diff --git a/src/PKSim.Core/Model/ParameterRange.cs b/src/PKSim.Core/Model/ParameterRange.cs index b73aa4926..d69d31108 100644 --- a/src/PKSim.Core/Model/ParameterRange.cs +++ b/src/PKSim.Core/Model/ParameterRange.cs @@ -2,6 +2,7 @@ using OSPSuite.Core.Domain; using OSPSuite.Core.Domain.Services; using OSPSuite.Core.Domain.UnitSystem; +using OSPSuite.Utility.Format; using OSPSuite.Utility.Reflection; using OSPSuite.Utility.Validation; using PKSim.Assets; @@ -18,6 +19,7 @@ public class ParameterRange : Notifier, IValidatable, IUpdatable public double? MaxValue { get; set; } public IDimension Dimension { get; set; } public Unit Unit { get; set; } + private static readonly NumericFormatter _numericFormatter = new NumericFormatter(NumericFormatterOptions.Instance); public ParameterRange() { @@ -57,6 +59,10 @@ public double? MaxValueInDisplayUnit set => MaxValue = baseValueFrom(value); } + public double? DbMinValueInDisplayUnit => displayValueFrom(DbMinValue); + + public double? DbMaxValueInDisplayUnit => displayValueFrom(DbMaxValue); + private double? baseValueFrom(double? displayValue) { if (!displayValue.HasValue) @@ -86,71 +92,35 @@ public override string ToString() private static class AllRules { - public static IBusinessRule MinLessThanMax - { - get - { - return CreateRule.For() - .Property(item => item.MinValueInDisplayUnit) - .WithRule(minLessThanMax) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MinLessThanMax(param.ParameterName)); - } - } - - public static IBusinessRule MaxGreaterThanMin - { - get - { - return CreateRule.For() - .Property(item => item.MaxValueInDisplayUnit) - .WithRule(maxGreaterThanMin) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxGreaterThanMin(param.ParameterName)); - } - } - - public static IBusinessRule MinGreaterThanDbMin - { - get - { - return CreateRule.For() - .Property(item => item.MinValueInDisplayUnit) - .WithRule(minGreaterThanDbMin) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MinGreaterThanDbMinValue(param.ParameterName, param.DbMinValue, param.Unit.ToString())); - } - } - - public static IBusinessRule MaxLessThanDbMax - { - get - { - return CreateRule.For() - .Property(item => item.MaxValueInDisplayUnit) - .WithRule(maxLessThanDbMax) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxLessThanDbMaxValue(param.ParameterName, param.DbMaxValue, param.Unit.ToString())); - } - } - - public static IBusinessRule MinLessThanDbMax - { - get - { - return CreateRule.For() - .Property(item => item.MinValueInDisplayUnit) - .WithRule(minLessThanDbMax) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MinLessThanDbMaxValue(param.ParameterName, param.DbMaxValue, param.Unit.ToString())); - } - } - - public static IBusinessRule MaxGreaterThanDbMin - { - get - { - return CreateRule.For() - .Property(item => item.MaxValueInDisplayUnit) - .WithRule(maxGreaterThanDbMin) - .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxGreaterThanDbMinValue(param.ParameterName, param.DbMinValue, param.Unit.ToString())); - } - } + public static IBusinessRule MinLessThanMax { get; } = CreateRule.For() + .Property(item => item.MinValueInDisplayUnit) + .WithRule(minLessThanMax) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MinLessThanMax(param.ParameterName)); + + public static IBusinessRule MaxGreaterThanMin { get; } = CreateRule.For() + .Property(item => item.MaxValueInDisplayUnit) + .WithRule(maxGreaterThanMin) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxGreaterThanMin(param.ParameterName)); + + public static IBusinessRule MinGreaterThanDbMin { get; } = CreateRule.For() + .Property(item => item.MinValueInDisplayUnit) + .WithRule(minGreaterThanDbMin) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MinGreaterThanDbMinValue(param.ParameterName, displayFor(param.DbMinValueInDisplayUnit), param.Unit.ToString())); + + public static IBusinessRule MaxLessThanDbMax { get; } = CreateRule.For() + .Property(item => item.MaxValueInDisplayUnit) + .WithRule(maxLessThanDbMax) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxLessThanDbMaxValue(param.ParameterName, displayFor(param.DbMaxValueInDisplayUnit), param.Unit.ToString())); + + public static IBusinessRule MinLessThanDbMax { get; } = CreateRule.For() + .Property(item => item.MinValueInDisplayUnit) + .WithRule(minLessThanDbMax) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MinLessThanDbMaxValue(param.ParameterName, displayFor(param.DbMaxValueInDisplayUnit), param.Unit.ToString())); + + public static IBusinessRule MaxGreaterThanDbMin { get; } = CreateRule.For() + .Property(item => item.MaxValueInDisplayUnit) + .WithRule(maxGreaterThanDbMin) + .WithError((param, value) => PKSimConstants.Rules.Parameter.MaxGreaterThanDbMinValue(param.ParameterName, displayFor(param.DbMinValueInDisplayUnit), param.Unit.ToString())); private static bool minLessThanMax(ParameterRange param, double? minValueInDisplayUnit) { @@ -212,6 +182,8 @@ private static bool doesNotNeedCheck(double? referenceValue, double? valueToChec return false; } + + private static string displayFor(double? value) => _numericFormatter.Format(value ?? double.NaN); } public virtual void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager) diff --git a/src/PKSim.Core/Model/PopulationAnalyses/PopulationAnalysisFieldBase.cs b/src/PKSim.Core/Model/PopulationAnalyses/PopulationAnalysisFieldBase.cs index a5a3c955d..622368f3a 100644 --- a/src/PKSim.Core/Model/PopulationAnalyses/PopulationAnalysisFieldBase.cs +++ b/src/PKSim.Core/Model/PopulationAnalyses/PopulationAnalysisFieldBase.cs @@ -62,30 +62,21 @@ public static IEnumerable All } } - private static IBusinessRule nameNotEmpty - { - get { return GenericRules.NonEmptyRule(x => x.Name); } - } + private static IBusinessRule nameNotEmpty { get; } = GenericRules.NonEmptyRule(x => x.Name); - private static IBusinessRule nameUnique - { - get + private static IBusinessRule nameUnique { get; } = CreateRule.For() + .Property(x => x.Name) + .WithRule((field, name) => { - return CreateRule.For() - .Property(x => x.Name) - .WithRule((field, name) => - { - var populationAnalysis = field.PopulationAnalysis; + var populationAnalysis = field.PopulationAnalysis; - var otherField = populationAnalysis?.FieldByName(name); - if (otherField == null) - return true; + var otherField = populationAnalysis?.FieldByName(name); + if (otherField == null) + return true; - return otherField == field; - }) - .WithError((field, name) => PKSimConstants.Error.NameAlreadyExistsInContainerType(name, PKSimConstants.ObjectTypes.PopulationAnalysis)); - } - } + return otherField == field; + }) + .WithError((field, name) => PKSimConstants.Error.NameAlreadyExistsInContainerType(name, PKSimConstants.ObjectTypes.PopulationAnalysis)); } } } \ No newline at end of file diff --git a/src/PKSim.Presentation/DTO/Parameters/ParameterScaleWithFactorDTO.cs b/src/PKSim.Presentation/DTO/Parameters/ParameterScaleWithFactorDTO.cs index 2b0292906..881cc6c75 100644 --- a/src/PKSim.Presentation/DTO/Parameters/ParameterScaleWithFactorDTO.cs +++ b/src/PKSim.Presentation/DTO/Parameters/ParameterScaleWithFactorDTO.cs @@ -16,16 +16,10 @@ public ParameterScaleWithFactorDTO() private static class AllRules { - private static IBusinessRule factorBiggerThanZero - { - get - { - return CreateRule.For() - .Property(item => item.Factor) - .WithRule((param, value) => value > 0) - .WithError((param, value) => PKSimConstants.Error.FactorShouldBeBiggerThanZero); - } - } + private static IBusinessRule factorBiggerThanZero { get; } = CreateRule.For() + .Property(item => item.Factor) + .WithRule((param, value) => value > 0) + .WithError((param, value) => PKSimConstants.Error.FactorShouldBeBiggerThanZero); public static IEnumerable All() { diff --git a/src/PKSim.Presentation/DTO/PopulationAnalyses/GroupingItemDTO.cs b/src/PKSim.Presentation/DTO/PopulationAnalyses/GroupingItemDTO.cs index e1ab0157f..1c7becb50 100644 --- a/src/PKSim.Presentation/DTO/PopulationAnalyses/GroupingItemDTO.cs +++ b/src/PKSim.Presentation/DTO/PopulationAnalyses/GroupingItemDTO.cs @@ -79,10 +79,7 @@ public virtual void UpdateFrom(GroupingItem groupingItem) private static class AllRules { - private static IBusinessRule labelDefined - { - get { return GenericRules.NonEmptyRule(x => x.Label); } - } + private static IBusinessRule labelDefined { get; } = GenericRules.NonEmptyRule(x => x.Label); public static IEnumerable All { diff --git a/src/PKSim.Presentation/DTO/Populations/ExtractIndividualsDTO.cs b/src/PKSim.Presentation/DTO/Populations/ExtractIndividualsDTO.cs index 9cf1fd084..26da5bb93 100644 --- a/src/PKSim.Presentation/DTO/Populations/ExtractIndividualsDTO.cs +++ b/src/PKSim.Presentation/DTO/Populations/ExtractIndividualsDTO.cs @@ -85,24 +85,18 @@ public int CountFor(string individualIds) private static class AllRules { private static IBusinessRule namingPatternDefined { get; } = GenericRules.NonEmptyRule(x => x.NamingPattern); - private static IBusinessRule indiviudalIdsDefined { get; } = GenericRules.NonEmptyRule(x => x.IndividualIdsExpression); + private static IBusinessRule individualIdsDefined { get; } = GenericRules.NonEmptyRule(x => x.IndividualIdsExpression); - private static IBusinessRule indiviudalIdsWellFormatted - { - get - { - return CreateRule.For() - .Property(dto => dto.IndividualIdsExpression) - .WithRule((dto, individualIds) => dto.CountFor(individualIds) > 0) - .WithError((dto, individualIds) => PKSimConstants.Error.AtLeastOneIndividualIdRequiredToPerformPopulationExtraction); - } - } + private static IBusinessRule individualIdsWellFormatted { get; } = CreateRule.For() + .Property(dto => dto.IndividualIdsExpression) + .WithRule((dto, individualIds) => dto.CountFor(individualIds) > 0) + .WithError((dto, individualIds) => PKSimConstants.Error.AtLeastOneIndividualIdRequiredToPerformPopulationExtraction); internal static IEnumerable All() { yield return namingPatternDefined; - yield return indiviudalIdsDefined; - yield return indiviudalIdsWellFormatted; + yield return individualIdsDefined; + yield return individualIdsWellFormatted; } } } diff --git a/src/PKSim.Presentation/DTO/Populations/ImportPopulationSettingsDTO.cs b/src/PKSim.Presentation/DTO/Populations/ImportPopulationSettingsDTO.cs index 308d3d295..e05459421 100644 --- a/src/PKSim.Presentation/DTO/Populations/ImportPopulationSettingsDTO.cs +++ b/src/PKSim.Presentation/DTO/Populations/ImportPopulationSettingsDTO.cs @@ -22,27 +22,15 @@ public ImportPopulationSettingsDTO() private static class AllRules { - private static IBusinessRule atLeastOneFileDefined - { - get - { - return CreateRule.For() - .Property(item => item.PopulationFiles) - .WithRule((item, files) => files.Any()) - .WithError((item, files) => PKSimConstants.Error.AtLeastOneFileRequiredToStartPopulationImport); - } - } - - private static IBusinessRule individualDefined - { - get - { - return CreateRule.For() - .Property(item => item.Individual) - .WithRule((item, ind) => ind != null) - .WithError((dto, ind) => PKSimConstants.Error.BuildingBlockNotDefined(PKSimConstants.ObjectTypes.Individual)); - } - } + private static IBusinessRule atLeastOneFileDefined { get; } = CreateRule.For() + .Property(item => item.PopulationFiles) + .WithRule((item, files) => files.Any()) + .WithError((item, files) => PKSimConstants.Error.AtLeastOneFileRequiredToStartPopulationImport); + + private static IBusinessRule individualDefined { get; } = CreateRule.For() + .Property(item => item.Individual) + .WithRule((item, ind) => ind != null) + .WithError((dto, ind) => PKSimConstants.Error.BuildingBlockNotDefined(PKSimConstants.ObjectTypes.Individual)); internal static IEnumerable All() { diff --git a/src/PKSim.Presentation/DTO/Populations/ParameterRangeDTO.cs b/src/PKSim.Presentation/DTO/Populations/ParameterRangeDTO.cs index 4a1949e94..dcbd9f219 100644 --- a/src/PKSim.Presentation/DTO/Populations/ParameterRangeDTO.cs +++ b/src/PKSim.Presentation/DTO/Populations/ParameterRangeDTO.cs @@ -9,7 +9,7 @@ namespace PKSim.Presentation.DTO.Populations { public class ParameterRangeDTO : DxValidatableDTO { - public ParameterRange ParameterRange { get; private set; } + public ParameterRange ParameterRange { get; } public ParameterRangeDTO(ParameterRange parameterRange) : base(parameterRange) @@ -17,31 +17,25 @@ public ParameterRangeDTO(ParameterRange parameterRange) ParameterRange = parameterRange; } - public string ParameterName - { - get { return ParameterRange.ParameterName; } - } + public string ParameterName => ParameterRange.ParameterName; - public string ParameterDisplayName - { - get { return ParameterRange.ParameterDisplayName; } - } + public string ParameterDisplayName => ParameterRange.ParameterDisplayName; public double? MinValueInDisplayUnit { - get { return ParameterRange.MinValueInDisplayUnit; } - set { ParameterRange.MinValueInDisplayUnit = value; } + get => ParameterRange.MinValueInDisplayUnit; + set => ParameterRange.MinValueInDisplayUnit = value; } public double? MaxValueInDisplayUnit { - get { return ParameterRange.MaxValueInDisplayUnit; } - set { ParameterRange.MaxValueInDisplayUnit = value; } + get => ParameterRange.MaxValueInDisplayUnit; + set => ParameterRange.MaxValueInDisplayUnit = value; } public Unit Unit { - get { return ParameterRange.Unit; } + get => ParameterRange.Unit; set { var minDisplayValue = MinValueInDisplayUnit; @@ -52,10 +46,7 @@ public Unit Unit } } - public bool IsDiscrete - { - get { return ParameterRange.IsAnImplementationOf(); } - } + public bool IsDiscrete => ParameterRange.IsAnImplementationOf(); public IEnumerable ListOfValues { diff --git a/src/PKSim.Presentation/DTO/Simulations/CompoundParameterSelectionDTO.cs b/src/PKSim.Presentation/DTO/Simulations/CompoundParameterSelectionDTO.cs index 0b91b9653..91b021489 100644 --- a/src/PKSim.Presentation/DTO/Simulations/CompoundParameterSelectionDTO.cs +++ b/src/PKSim.Presentation/DTO/Simulations/CompoundParameterSelectionDTO.cs @@ -9,20 +9,16 @@ namespace PKSim.Presentation.DTO.Simulations { public class CompoundParameterSelectionDTO : DxValidatableDTO { - private readonly ParameterAlternativeGroup _compoundParameterGroup; public ParameterAlternative SelectedAlternative { get; set; } public string ParameterName { get; set; } public CompoundParameterSelectionDTO(ParameterAlternativeGroup compoundParameterGroup) { - _compoundParameterGroup = compoundParameterGroup; + CompoundParameterGroup = compoundParameterGroup; Rules.AddRange(AllRules.All()); } - public ParameterAlternativeGroup CompoundParameterGroup - { - get { return _compoundParameterGroup; } - } + public ParameterAlternativeGroup CompoundParameterGroup { get; } private static class AllRules { @@ -32,15 +28,9 @@ public static IEnumerable All() } } - private static IBusinessRule selectionNotEmpty - { - get - { - return CreateRule.For() - .Property(item => item.SelectedAlternative) - .WithRule((param, value) => value != null) - .WithError((param, value) => PKSimConstants.Error.CompoundParameterSelectionNeededFor(param.ParameterName)); - } - } + private static IBusinessRule selectionNotEmpty { get; } = CreateRule.For() + .Property(item => item.SelectedAlternative) + .WithRule((param, value) => value != null) + .WithError((param, value) => PKSimConstants.Error.CompoundParameterSelectionNeededFor(param.ParameterName)); } } \ No newline at end of file diff --git a/src/PKSim.UI/UserSettings.cs b/src/PKSim.UI/UserSettings.cs index 3ea53dba3..eeda15039 100644 --- a/src/PKSim.UI/UserSettings.cs +++ b/src/PKSim.UI/UserSettings.cs @@ -3,16 +3,9 @@ using System.Drawing; using System.IO; using System.Linq.Expressions; -using OSPSuite.Assets; -using OSPSuite.Utility.Extensions; -using OSPSuite.Utility.Format; -using OSPSuite.Utility.Validation; using DevExpress.XtraBars.Docking; using DevExpress.XtraBars.Ribbon; -using PKSim.Assets; -using PKSim.Core; -using PKSim.Core.Model; -using PKSim.Presentation; +using OSPSuite.Assets; using OSPSuite.Core.Comparison; using OSPSuite.Core.Diagram; using OSPSuite.Core.Domain; @@ -22,7 +15,13 @@ using OSPSuite.Presentation.Presenters.SensitivityAnalyses; using OSPSuite.Presentation.Services; using OSPSuite.Presentation.Settings; -using OSPSuite.UI; +using OSPSuite.Utility.Extensions; +using OSPSuite.Utility.Format; +using OSPSuite.Utility.Validation; +using PKSim.Assets; +using PKSim.Core; +using PKSim.Core.Model; +using PKSim.Presentation; namespace PKSim.UI { @@ -33,7 +32,6 @@ public class UserSettings : ValidatableDTO, IUserSettings private readonly INumericFormatterOptions _numericFormatterOptions; private readonly ISkinManager _skinManager; public Scalings DefaultChartYScaling { get; set; } - private readonly DirectoryMapSettings _directoryMapSettings; public bool ShouldRestoreWorkspaceLayout { get; set; } public ParameterGroupingModeId DefaultParameterGroupingMode { get; set; } public string MainViewLayout { get; set; } @@ -78,10 +76,10 @@ public UserSettings(DockManager dockManager, RibbonBarManager ribbonManager, INu _ribbonManager = ribbonManager; _numericFormatterOptions = numericFormatterOptions; _skinManager = skinManager; - _directoryMapSettings = directoryMapSettings; + DirectoryMapSettings = directoryMapSettings; DisplayUnits = new DisplayUnitsManager(); - ComparerSettings = new ComparerSettings { CompareHiddenEntities = false }; + ComparerSettings = new ComparerSettings {CompareHiddenEntities = false}; ProjectFiles = new List(); Rules.AddRange(AllRules.All()); DiagramOptions = new DiagramOptions(); @@ -119,9 +117,9 @@ public void ResetToDefault() DefaultChartEditorLayout = Constants.DEFAULT_CHART_LAYOUT; } - public DirectoryMapSettings DirectoryMapSettings => _directoryMapSettings; + public DirectoryMapSettings DirectoryMapSettings { get; } - public IEnumerable UsedDirectories => _directoryMapSettings.UsedDirectories; + public IEnumerable UsedDirectories => DirectoryMapSettings.UsedDirectories; public void RestoreLayout() { @@ -290,21 +288,12 @@ public Color DisabledColor private static class AllRules { - private static IBusinessRule nonEmpty(Expression> expression) - { - return GenericRules.NonEmptyRule(expression); - } + private static IBusinessRule nonEmpty(Expression> expression) => GenericRules.NonEmptyRule(expression); - private static IBusinessRule numberOfCoreSmallerThanNumberOfProcessor - { - get - { - return CreateRule.For() - .Property(x => x.MaximumNumberOfCoresToUse) - .WithRule((x, numCore) => numCore > 0 && numCore <= Environment.ProcessorCount) - .WithError(OSPSuite.Assets.Error.NumberOfCoreToUseShouldBeInferiorAsTheNumberOfProcessor(Environment.ProcessorCount)); - } - } + private static IBusinessRule numberOfCoreSmallerThanNumberOfProcessor { get; } = CreateRule.For() + .Property(x => x.MaximumNumberOfCoresToUse) + .WithRule((x, numCore) => numCore > 0 && numCore <= Environment.ProcessorCount) + .WithError(Error.NumberOfCoreToUseShouldBeInferiorAsTheNumberOfProcessor(Environment.ProcessorCount)); public static IEnumerable All() { @@ -317,6 +306,5 @@ public static IEnumerable All() }; } } - } } \ No newline at end of file diff --git a/tests/PKSim.Tests/Core/ParameterRangeSpecs.cs b/tests/PKSim.Tests/Core/ParameterRangeSpecs.cs index a002f10be..a7505be0b 100644 --- a/tests/PKSim.Tests/Core/ParameterRangeSpecs.cs +++ b/tests/PKSim.Tests/Core/ParameterRangeSpecs.cs @@ -1,8 +1,9 @@ -using FakeItEasy; +using NUnit.Framework; using OSPSuite.BDDHelper; using OSPSuite.BDDHelper.Extensions; +using OSPSuite.Utility.Format; using OSPSuite.Utility.Validation; -using NUnit.Framework; +using PKSim.Assets; using PKSim.Core.Model; namespace PKSim.Core @@ -11,7 +12,11 @@ public abstract class concern_for_ParameterRange : ContextSpecification x.MinValueInDisplayUnit, valueInHours).IsEmpty.ShouldBeEqualTo(valid); + InitRange(null, max, dbMin, dbMax); + sut.Validate(x => x.MinValueInDisplayUnit, valueInHours).IsEmpty.ShouldBeEqualTo(valid); + } + + [TestCase(90, 1)] + public void should_return_a_message_when_invalid_using_the_display_database_values(double? dbMin, double? valueInHours) + { + InitRange(null, null, dbMin); + var formatter = new NumericFormatter(NumericFormatterOptions.Instance); + var validation = sut.Validate(x => x.MinValueInDisplayUnit, valueInHours); + validation.IsEmpty.ShouldBeEqualTo(false); + validation.Message.ShouldBeEqualTo(PKSimConstants.Rules.Parameter.MinGreaterThanDbMinValue(sut.ParameterName, formatter.Format(sut.DbMinValueInDisplayUnit.Value), sut.Unit.Name)); } } @@ -45,10 +60,20 @@ public class When_checking_if_a_value_in_display_unit_for_maximum_is_valid : con [TestCase(null, 60.0, 120.0, 3.0, false)] [TestCase(80.0, 60.0, 120.0, 1.0, false)] [TestCase(60.0, null, null, 2.0, true)] - public void should_return_the_validation_according_to_acceptable_range(double? min, double? dbMin, double? dbMax, double? valueInHours, bool valid) + public void should_return_the_validation_according_to_acceptable_range(double? min, double? dbMin, double? dbMax, double? valueInHours, bool valid) { InitRange(min, null, dbMin, dbMax); sut.Validate(x => x.MaxValueInDisplayUnit, valueInHours).IsEmpty.ShouldBeEqualTo(valid); } + + [TestCase(90, 2)] + public void should_return_a_message_when_invalid_using_the_display_database_values(double? dbMax, double? valueInHours) + { + InitRange(null, null, null, dbMax); + var formatter = new NumericFormatter(NumericFormatterOptions.Instance); + var validation = sut.Validate(x => x.MaxValueInDisplayUnit, valueInHours); + validation.IsEmpty.ShouldBeEqualTo(false); + validation.Message.ShouldBeEqualTo(PKSimConstants.Rules.Parameter.MaxLessThanDbMaxValue(sut.ParameterName, formatter.Format(sut.DbMaxValueInDisplayUnit.Value), sut.Unit.Name)); + } } -} \ No newline at end of file +} \ No newline at end of file