Пример #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);
            }
            MinMaxValue <int> lengthMinMax;

            if (request.ExtraInfo is MemberInfo)
            {
                lengthMinMax = GetMemberInfoStringLength(request.ExtraInfo as MemberInfo);

                if (lengthMinMax.Min < 0)
                {
                    lengthMinMax.Min = 5;
                }
                if (lengthMinMax.Max == int.MaxValue)
                {
                    lengthMinMax.Max = 16;
                }
            }
            else
            {
                lengthMinMax = new MinMaxValue <int> {
                    Min = 5, Max = 16
                };
            }

            lengthMinMax.Min = _constraintHelper.GetValue(request.Constraints, lengthMinMax.Min, "min", "minlength");
            lengthMinMax.Max = _constraintHelper.GetValue(request.Constraints, lengthMinMax.Max, "max", "maxlength");

            var prefix = _constraintHelper.GetValue(request.Constraints, string.Empty, "prefix", "pre", "seed");

            if (!string.IsNullOrEmpty(prefix))
            {
                lengthMinMax.Min -= prefix.Length;
                lengthMinMax.Max -= prefix.Length;
            }

            var postfix = _constraintHelper.GetValue(request.Constraints, string.Empty, "postfix", "post");

            if (!string.IsNullOrEmpty(postfix))
            {
                lengthMinMax.Min -= postfix.Length;
                lengthMinMax.Max -= postfix.Length;
            }

            var stringType = _constraintHelper.GetValue(request.Constraints, StringType.MostCharacter, "stringType", "Type");

            if (lengthMinMax.Min > lengthMinMax.Max)
            {
                lengthMinMax.Min = lengthMinMax.Max;
            }

            return(prefix + _dataGenerator.NextString(stringType, lengthMinMax.Min, lengthMinMax.Max) + postfix);
        }
Пример #2
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 domain = _constraintHelper.GetValue(request.Constraints, "google.com", "uriDomain");
            var scheme = _constraintHelper.GetValue(request.Constraints, "http", "uriScheme");

            return(new Uri(string.Format("{0}://{1}", scheme, domain)));
        }
Пример #3
0
        public virtual IEnumerable <PropertyInfo> SelectProperties(object instance, DataRequest request, ComplexModel model)
        {
            var skipProperties = new List <string>();

            var skipPropertiesEnumerable = _helper.GetValue <IEnumerable <string> >(request.Constraints,
                                                                                    null,
                                                                                    "_skipProps",
                                                                                    "_skipProperties");

            if (skipPropertiesEnumerable != null)
            {
                skipProperties.AddRange(skipPropertiesEnumerable);
            }

            var returnProperties = instance.GetType()
                                   .GetRuntimeProperties()
                                   .Where(p => p.CanWrite &&
                                          p.SetMethod.IsPublic &&
                                          !p.SetMethod.IsStatic &&
                                          p.SetMethod.GetParameters().Count() == 1 &&
                                          !skipProperties.Contains(p.Name));

            if (request.ParentRequest != null &&
                _configuration.CircularReferenceHandling == CircularReferenceHandlingAlgorithm.OmitCircularReferences)
            {
                returnProperties = CheckForCircularProperties(request, returnProperties);
            }

            return(returnProperties);
        }
Пример #4
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));
        }
Пример #5
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 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)));
        }
Пример #6
0
        protected virtual void AutoFillRadioButtonGroup(string key, List <IWebElement> values)
        {
            string stringConstraintValue = null;

            if (_isSimpleSeed)
            {
                stringConstraintValue = GetStringFromValue(_seedWith);
            }
            else
            {
                object setValue = _constraintHelper.GetValue <object>(_seedWith, null, key);

                if (setValue != null)
                {
                    stringConstraintValue = GetStringFromValue(setValue);
                }
            }

            if (!string.IsNullOrEmpty(stringConstraintValue))
            {
                foreach (IWebElement webElement in values)
                {
                    if (webElement.GetAttribute(ElementContants.ValueAttribute) == stringConstraintValue)
                    {
                        webElement.Click();
                        return;
                    }
                }
            }

            var radioElement = _actionProvider.Generate <IRandomDataGeneratorService>().NextInSet(values);

            if (radioElement != null)
            {
                radioElement.Click();
            }
        }
Пример #7
0
        public IEnumerable <FieldInfo> SelectFields(object instance, DataRequest request, ComplexModel model)
        {
            var skipFields = new List <string>();

            var skipFieldsEnumerable = _helper.GetValue <IEnumerable <string> >(request.Constraints,
                                                                                null,
                                                                                "_skipFields");

            if (skipFieldsEnumerable != null)
            {
                skipFields.AddRange(skipFieldsEnumerable);
            }

            return(instance.GetType()
                   .GetRuntimeFields()
                   .Where(f => f.IsPublic && !skipFields.Contains(f.Name)));
        }
Пример #8
0
        private T GenerateClosedFake <T>(DataRequest request, IConstraintHelper helper)
        {
            Action <IFakeOptions <T> > options = helper.GetValue <Action <IFakeOptions <T> > >(request.Constraints, null, "builderOptions");

            return(options != null?A.Fake(options) : A.Fake <T>());
        }