Esempio n. 1
0
        public string NextUnicodeUrl(int maxLength)
        {
            if (maxLength < 12)
            {
                throw new ArgumentOutOfRangeException("maxLength", "Urls must be at least 12 characters");
            }

            string fqdn    = NextAsciiFullyQualifiedDomainName(maxLength - 9);
            string baseUrl = RegexGen.NextString(Random, "https?://") + fqdn;
            string fullUrl;

            int remainingLength = maxLength - baseUrl.Length;
            int numberOfParts   = NextInt32(0, remainingLength / 2);

            if (numberOfParts == 0)
            {
                fullUrl = baseUrl + (NextBoolean() ? "/" : "");
            }
            else
            {
                string[] parts         = new string[numberOfParts];
                int      maxPartLength = (remainingLength / numberOfParts) - 1;
                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = NextUnicodeWord(1, maxPartLength);
                }
                fullUrl = baseUrl + "/" + String.Join("/", parts);
            }

            Assert.IsTrue(fullUrl.Length <= maxLength, "Internal error in NextUrl, generated string was " + fullUrl.Length + " characters, maxLength was " + maxLength + ".  Generated string: " + fullUrl);
            return(fullUrl);
        }
Esempio n. 2
0
 /// <summary>
 /// This function used to generate random string with the specified length which is not
 /// less than minLength and not greater than maxLength.
 /// It can be a combination of alphabets - both cases, integers and special characters
 /// The string will be of at minLength characters character, and no more than
 /// maxLength characters.
 /// </summary>
 /// <param name="minLength">Minimum Length of the string to be generated.</param>
 /// /// <param name="maxLength">Maximum Length of the string to be generated.</param>
 /// <returns>String with the length provided, if length is Less than or equal 0 then the string returned is empty.</returns>
 public string NextAsciiStringWithSpecialChars(int minLength, int maxLength)
 {
     return(RegexGen.NextString(Random, @"[a-zA-Z0-9{!@#$%^&\*()~_+=\-/?.>,<';:}\t]{" + minLength + "," + maxLength + "}"));
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a random North American phone number.  Note that this
 /// seems to be somewhat buggy.
 /// </summary>
 /// <returns>North American phone number</returns>
 public string NextNorthAmericaPhoneNumber()
 {
     return(RegexGen.NextString(Random, @"((\(\d{3}\)?)|(\d{3}-))\d{3}-\d{4}"));
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a random digit string with length.
        /// </summary>
        /// <returns>Digitial string</returns>
        public string NextDigits(int length)
        {
            string len = length.ToString(CultureInfo.InvariantCulture);

            return(RegexGen.NextString(Random, @"\d{" + len + "}"));
        }
Esempio n. 5
0
 /// <summary>
 /// Returns a random English word with lower case.
 ///  The string will be of at least minLength
 /// characters, and no more than maxLength characters.
 /// </summary>
 /// <param name="minLength">The minimum length of the returned string</param>
 /// <param name="maxLength">The maximum length of the returned string</param>
 /// <returns>Random string</returns>
 public string NextEnglishWordLowercase(int minLength, int maxLength)
 {
     return(RegexGen.NextString(Random, @"[a-z]{" + minLength + "," + maxLength + "}"));
 }
Esempio n. 6
0
 /// <summary>
 /// Returns a random string without spaces containing only
 /// valid alphabetic letters (upper and lower case) and numerals in various
 /// scripts, dash and underscore.  The string will be of at least minLength
 /// characters, and no more than maxLength characters.
 /// </summary>
 /// <param name="minLength">The minimum length of the returned string</param>
 /// <param name="maxLength">The maximum length of the returned string</param>
 /// <returns>Random string</returns>
 public string NextUnicodeWord(int minLength, int maxLength)
 {
     return(RegexGen.NextString(Random, UnicodeWordChar + "{" + minLength + "," + maxLength + "}"));
 }