Ejemplo n.º 1
0
        public static int RandomInt(ISpecificationProperty specificationProperty)
        {
            if (specificationProperty.PropertyType != "int" && specificationProperty.PropertyType != "int?")
            {
                throw new ArgumentException("Specification Property " + specificationProperty.Name + " is not an integer!");
            }

            int randomInt;

            if (specificationProperty.Minimum == null && specificationProperty.Maximum == null)
            {
                randomInt = TemplatesHelper.RandomInt(int.MinValue, int.MaxValue);
            }
            else if (specificationProperty.Minimum == null)
            {
                randomInt = TemplatesHelper.RandomInt(int.MinValue, (int)specificationProperty.Maximum);
            }
            else if (specificationProperty.Maximum == null)
            {
                randomInt = TemplatesHelper.RandomInt((int)specificationProperty.Minimum, int.MaxValue);
            }
            else
            {
                randomInt = TemplatesHelper.RandomInt((int)specificationProperty.Minimum, (int)specificationProperty.Maximum);
            }

            return(randomInt);
        }
Ejemplo n.º 2
0
        public static string RandomString(ISpecificationProperty specificationProperty)
        {
            if (specificationProperty.PropertyType != "string")
            {
                throw new ArgumentException("Specification Property " + specificationProperty.Name + " is not an string!");
            }

            if (specificationProperty.Name.ToLower().Contains("number"))
            {
                int digits = 0;

                digits = specificationProperty.Minimum == null ? 0 : ((int?)specificationProperty.Minimum).Value > 6 ? 6 : ((int?)specificationProperty.Minimum).Value;
                int minimum = Convert.ToInt32(Math.Pow(10, digits)) - 1;

                digits = ((int?)specificationProperty.Maximum).Value > 6 ? 6 : ((int?)specificationProperty.Maximum).Value;
                int maximum = Convert.ToInt32(Math.Pow(10, digits)) - 1;

                return(TemplatesHelper.RandomInt(minimum, maximum).ToString());
            }

            return(TemplatesHelper.RandomString((int)specificationProperty.Maximum));
        }