private static decimal GetMaxValueAndCheckRange(DataGenerationHint[] hints, out decimal minValue, ref int scale) { decimal maxValue = GetNumericMaxValueAndCheckRange(hints, decimal.MinValue, decimal.MaxValue, out minValue); int?precisionFromHint = hints.OfType <NumericPrecisionHint>().Any() ? hints.OfType <NumericPrecisionHint>().Min(h => h.Value) : (int?)null; int?scaleFromHint = hints.OfType <NumericScaleHint>().Any() ? hints.OfType <NumericScaleHint>().Min(h => h.Value) : (int?)null; if (!precisionFromHint.HasValue && !scaleFromHint.HasValue) { scale = -1; } else { scale = !scaleFromHint.HasValue ? Math.Min(precisionFromHint.Value, scale) : scaleFromHint.Value; DataGenerationUtilities.CheckNumericScale(scale); minValue = AdjustMin(minValue, scale); maxValue = AdjustMax(maxValue, scale); if (precisionFromHint.HasValue) { DataGenerationUtilities.CheckNumericPrecisionAndScale(precisionFromHint.Value, scale); decimal maxBasedOnPrecisionAndScale = (decimal)Math.Pow(10, precisionFromHint.Value - scale) - (1 / (decimal)Math.Pow(10, scale)); decimal minBasedOnPrecisionAndScale = -maxBasedOnPrecisionAndScale; minValue = Math.Max(minValue, minBasedOnPrecisionAndScale); maxValue = Math.Min(maxValue, maxBasedOnPrecisionAndScale); } ExceptionUtilities.CheckValidRange(minValue, "minimum value based on hints", maxValue, "maximum value based on hints"); } return(maxValue); }
/// <summary> /// DateTimeOffset 'FromSeed' strategy that returns DateTimeOffset(seed, offset). /// </summary> /// <param name="offset">The offset.</param> /// <returns>DateTimeOffset 'FromSeed' delegate.</returns> public static Func <long, DateTimeOffset> DateTimeOffsetFromSeed(TimeSpan offset) { return(delegate(long seed) { try { return new DateTimeOffset(seed, offset); } catch (ArgumentOutOfRangeException ex) { throw DataGenerationUtilities.FromSeedFailedException <DateTimeOffset>(seed, ex); } }); }
/// <summary> /// FromSeed strategy that converts seed to the targeted type using IConvertible. /// </summary> /// <typeparam name="TData">The targeted type.</typeparam> /// <returns>'FromSeed' delegate.</returns> /// <remarks>The <typeparamref name="TData"/> such that long can be converted to.</remarks> public static Func <long, TData> ConvertSeed <TData>() { Type clrType = typeof(TData); if (!supportedTypesForConvertSeed.Contains(typeof(TData))) { throw new TaupoNotSupportedException("This strategy is not supported for the type " + clrType.FullName + ". Try other strategies."); } return(delegate(long seed) { try { var value = seed.ConvertToType <TData>(); return value; } catch (OverflowException ex) { throw DataGenerationUtilities.FromSeedFailedException <TData>(seed, ex); } }); }