/// <summary> /// Process the <see cref="ParameterValueSet"/> . /// </summary> /// <param name="parameterValueSet"> /// The <see cref="ParameterValueSetBase"/> to be processed. /// </param> /// <param name="parameterOrOverrideBase"> /// The <see cref="ParameterOrOverrideBase"/> the <see cref="ParameterValueSetBase"/ belongs to. /// </param> /// <param name="componentIndex"> /// The index of the <see cref="ParameterTypeComponent"/>. /// </param> /// <param name="computedValue"> /// The manual value of the <see cref="ParameterValueSet"/>. /// </param> /// <param name="processedValueSets"> /// A <see cref="Dictionary{Guid,ProcessedValueSet}"/> of ProcessedValueSe that capture the updated <see cref="Thing"/>s with its value validation result /// </param> /// <param name="provider"> /// The <see cref="IFormatProvider"/> used to validate. /// </param> /// <param name="validationErrorText"> /// <see cref="String"/> that holds the validation error text. /// </param> /// <returns> /// The added or changed <see cref="ProcessedValueSet"/> /// </returns> private ProcessedValueSet ProcessValueSet(ParameterValueSetBase parameterValueSet, ParameterOrOverrideBase parameterOrOverrideBase, int componentIndex, string computedValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, IFormatProvider provider, out string validationErrorText) { var validationResult = ValidationResultKind.InConclusive; var switchKind = parameterValueSet.ValueSwitch; var measurementScale = parameterOrOverrideBase.Scale; var parameterType = parameterOrOverrideBase.ParameterType; validationErrorText = string.Empty; if (parameterType != null) { if (ValueSetConverter.TryParseDouble(computedValue, parameterType, out var convertedComputedValue)) { computedValue = convertedComputedValue.ToString(CultureInfo.InvariantCulture); } computedValue = computedValue?.ToValueSetObject(parameterType).ToValueSetString(parameterType) ?? parameterValueSet.Computed[componentIndex]; var validManualValue = parameterType.Validate(computedValue, measurementScale, provider); if (validManualValue.ResultKind > validationResult) { validationResult = validManualValue.ResultKind; validationErrorText = validManualValue.Message; } } var valueSetExists = processedValueSets.TryGetValue(parameterValueSet.Iid, out var processedValueSet); if (!valueSetExists) { processedValueSet = new ProcessedValueSet(parameterValueSet, validationResult); } if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, parameterValueSet.Manual[componentIndex], computedValue, parameterValueSet.Reference[componentIndex], computedValue, out var valueSetValues)) { processedValueSet.UpdateClone(valueSetValues); if (!valueSetExists) { processedValueSets.Add(parameterValueSet.Iid, processedValueSet); } } return(processedValueSet); }
public void VerifyThatValuesAreCalculatedCorrectly(string valueArrayValue, double expectedValue1, double expectedValue2, bool expectedTryParseResult, ParameterType parameterType) { var culture = new CultureInfo("en-GB") { NumberFormat = { NumberDecimalSeparator = ",", NumberGroupSeparator = "." } }; System.Threading.Thread.CurrentThread.CurrentCulture = culture; Assert.AreEqual(expectedTryParseResult, ValueSetConverter.TryParseDouble(valueArrayValue, parameterType, out var calculatedValue1)); Assert.AreEqual(expectedValue1, calculatedValue1); culture.NumberFormat.NumberDecimalSeparator = "."; culture.NumberFormat.NumberGroupSeparator = ","; Assert.AreEqual(expectedTryParseResult, ValueSetConverter.TryParseDouble(valueArrayValue, parameterType, out var calculatedValue2)); Assert.AreEqual(expectedValue2, calculatedValue2); }
[ExcludeFromCodeCoverage] // Remove attribute when more logic is added to this method. It's only SDK functionality now and that is fully covered. public override double Parse(string value) { ValueSetConverter.TryParseDouble(value, this.ParameterBase?.ParameterType, out var parsedValue); return(parsedValue); }