Esempio n. 1
0
        /// <summary>
        /// Generate data for the request, return Constrain.NoValue instead of null
        /// </summary>
        /// <param name="request">data request</param>
        /// <returns>generated data</returns>
        public override object GenerateData(DataRequest request)
        {
            if (!request.Populate)
            {
                return(LocateValue);
            }

            var minMax = _constraintHelper.GetMinMax(request, short.MinValue, short.MaxValue);

            minMax.Min = _constraintHelper.GetValue(request.Constraints, minMax.Min, "min", "minValue");
            minMax.Max = _constraintHelper.GetValue(request.Constraints, minMax.Max, "max", "maxValue");

            if (minMax.Min.CompareTo(minMax.Max) > 0)
            {
                minMax.Min = minMax.Max;
            }

            return(_dataGenerator.NextShort(minMax.Min, minMax.Max));
        }
        /// <summary>
        /// Generate data for the request, return Constrain.NoValue instead of null
        /// </summary>
        /// <param name="request">data request</param>
        /// <returns>generated data</returns>
        public override object GenerateData(DataRequest request)
        {
            if (!request.Populate)
            {
                return(LocateValue);
            }

            var min = _helper.GetValue <DateTime?>(request.Constraints, null, "min", "minDate");
            var max = _helper.GetValue <DateTime?>(request.Constraints, null, "max", "maxDate");

            if (!min.HasValue)
            {
                if (!max.HasValue)
                {
                    min = DateTime.Today.AddYears(-5);
                    max = min.Value.AddYears(10);
                }
                else
                {
                    min = max.Value.AddYears(-100);
                }
            }
            else if (!max.HasValue)
            {
                max = min.Value.AddYears(100);
            }

            if (min.Value.CompareTo(max.Value) > 0)
            {
                min = max;
            }

            var minMax = _helper.GetMinMax(request, min.Value, max.Value);

            var timeSpan = minMax.Max.Subtract(minMax.Min);

            return(minMax.Min.AddSeconds(_dataGenerator.NextDouble(0, timeSpan.TotalSeconds)));
        }