Hi there,
I'm creating test cases for a iOS/Android app with account registration. Currently I'm stuck at the point where I want to use random username and email addresses. Since we are using a staging backend, it's not necessary to have a valid username or email because the created accounts will not be used furthermore.
Can someone please give me (rather less coding skills) a hint, how to add some random characters to the key input.
Thanks in advance.
Lars
How to use random data for account registration
Re: How to use random data for account registration
You could do something like the following. It will take the min and max lengths you want for the string, randomly generating the actual length and then randomly getting each character from the alphabet array. Finally it will capitalize the first letter, if you tell it to.
You could use it to make first and last names, email addresses, etc.
Code: Select all
public static string getRandomString(int minLength, int maxLength, bool initialCaps) {
Random r = new Random();
int length = r.Next(minLength, maxLength);
char[] characters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
sb.Append(characters[r.Next(26)]);
}
if (initialCaps) return sb.ToString().Substring(0,1).ToUpper() + sb.ToString().Substring(1);
return sb.ToString();
}
Code: Select all
string firstName = getRandomString(6,8,true);
string lastName = getRandomString(6,10,true);
string emailAddress = getRandomString(6,10,false) + "@" + getRandomString(6,10,false) + ".com";
Shortcuts usually aren't...
Re: How to use random data for account registration
Thanks for your feedback and help. Got it! 
