/// <summary> /// Generates user names. /// </summary> /// <param name="firstName">Always used.</param> /// <param name="lastName">Sometimes used depending on randomness.</param> public string UserName(string firstName = null, string lastName = null) { firstName = firstName ?? Name.FirstName(); lastName = lastName ?? Name.LastName(); var val = Random.Number(2); string result; if (val == 0) { result = firstName + Random.Number(99); } else if (val == 1) { result = firstName + Random.ArrayElement(new[] { ".", "_" }) + lastName; } else { result = firstName + Random.ArrayElement(new[] { ".", "_" }) + lastName + Random.Number(99); } result = result.Replace("'", "") .Replace(" ", ""); return(result); }
/// <summary> /// Recursive parse the tokens in the string . /// </summary> /// <param name="value">The value.</param> /// <returns>System.String.</returns> private string ParseTokens(string value) { var regex = new Regex("\\#{(.*?)\\}"); var cityResult = regex.Replace(value, x => { JArray result; var groupValue = x.Groups[1].Value.ToLower().Split('.'); if (groupValue.Length == 1) { result = (JArray)Database.Get(Category, groupValue[0], Locale); } else { result = (JArray)Database.Get(groupValue[0], groupValue[1], Locale); } var randomElement = Random.ArrayElement(result); //replace values return(ParseTokens(randomElement)); } ); return(cityResult); }
/// <summary> /// Get a random currency. /// </summary> /// <returns></returns> public Currency Currency(bool includeFundCodes = false) { var obj = GetObject("currency"); var keys = obj.Properties().ToArray(); var prop = Random.ArrayElement(keys) as JProperty; var cur = prop.First.ToObject <Currency>(); cur.Description = prop.Name; // GitHub Issue #80: // Make sure we exclude currency fund codes by default unless // the user wants them. See: //https://github.com/bchavez/Bogus/issues/80 if (cur.Code.Contains(" ")) { // We selecgted a currency fund code. Check if the user wants it. if (includeFundCodes) { cur.Code = cur.Code.Split(' ')[1]; return(cur); } //If they don't want fund codes, send back a default USD. //instead of selecting again (and possibly looping over and over). return(DataSets.Currency.Default); } return(cur); }
/// <summary> /// Get a random currency. /// </summary> /// <returns></returns> public Currency Currency(bool includeFundCodes = false) { var arr = GetArray("currency"); var obj = Random.ArrayElement(arr) as BObject; var cur = new Currency { Description = obj["name"], Code = obj["code"], Symbol = obj["symbol"], }; // GitHub Issue #80: // Make sure we exclude currency fund codes by default unless // the user wants them. See: //https://github.com/bchavez/Bogus/issues/80 if (cur.Code.Contains(" ")) { // We selected a currency fund code. Check if the user wants it. if (includeFundCodes) { cur.Code = cur.Code.Split(' ')[1]; return(cur); } //If they don't want fund codes, send back a default USD. //instead of selecting again (and possibly looping over and over). return(DataSets.Currency.Default); } return(cur); }
/// <summary> /// Get a secondary address like 'Apt. 2' or 'Suite 321'. /// </summary> /// <returns></returns> public string SecondaryAddress() { var formats = new[] { "Apt. ###", "Suite ###" }; var format = Random.ArrayElement(formats); return(Random.Replace(format)); }
/// <summary> /// Gets a random image. /// </summary> public string Image(int width = 640, int height = 480, bool randomize = false, bool https = false) { var categories = new[] { "abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport" }; var picked = Random.ArrayElement(categories); return(ImageUrl(picked, width, height, randomize, https)); }
protected override void Populate() { base.Populate(); Address = new LeadCardAddress { CountryCode = Random.ArrayElement(new string[] { "US", DsAddress.CountryCode() }) }; Email = DsInternet.Email(FirstName, LastName, DsInternet.DomainWord() + ".test"); }
/// <summary> /// Get a random currency. /// </summary> /// <returns></returns> public Currency Currency() { var obj = GetObject("currency"); var keys = obj.Properties().ToArray(); var prop = Random.ArrayElement(keys) as JProperty; var cur = prop.First.ToObject <Currency>(); cur.Description = prop.Name; return(cur); }
/// <summary> /// Get a character letter. /// </summary> /// <param name="num">Number of characters to return.</param> /// <returns></returns> public string Letter(int num = 1) { if (num <= 0) { return(string.Empty); } var w = Words(1)[0]; var c = Random.ArrayElement(w.ToArray()); return(c + Letter(num - 1)); }
/// <summary> /// Get a character letter. /// </summary> /// <param name="num">The number of characters to return.</param> public string Letter(int num = 1) { if (num <= 0) { return(string.Empty); } var words = Words(1)[0]; var characters = Random.ArrayElement(words.ToArray()); return(characters + Letter(num - 1)); }
//We could do better at generating these I suppose. /// <summary> /// Returns a credit card number that should pass validation. See [here](https://developers.braintreepayments.com/ios+ruby/reference/general/testing). /// </summary> /// <returns></returns> public string CreditCardNumber() { var cards = new[] { "378282246310005", "371449635398431", "6011111111111117", "3530111333300000", "6304000000000000", "5555555555554444", "4111111111111111", "4005519200000004", "4009348888881881", "4012000033330026", "4012000077777777", "4012888888881881", "4217651111111119", "4500600000000061" }; return(Random.ArrayElement(cards)); }
/// <summary> /// Returns a phrase. /// </summary> /// <returns></returns> public string Phrase() { var phrases = new[] { "If we {{verb}} the {{noun}}, we can get to the {{abbreviation}} {{noun}} through the {{adjective}} {{abbreviation}} {{noun}}!", "We need to {{verb}} the {{adjective}} {{abbreviation}} {{noun}}!", "Try to {{verb}} the {{abbreviation}} {{noun}}, maybe it will {{verb}} the {{adjective}} {{noun}}!", "You can't {{verb}} the {{noun}} without {{ingverb}} the {{adjective}} {{abbreviation}} {{noun}}!", "Use the {{adjective}} {{abbreviation}} {{noun}}, then you can {{verb}} the {{adjective}} {{noun}}!", "The {{abbreviation}} {{noun}} is down, {{verb}} the {{adjective}} {{noun}} so we can {{verb}} the {{abbreviation}} {{noun}}!", "{{ingverb}} the {{noun}} won't do anything, we need to {{verb}} the {{adjective}} {{abbreviation}} {{noun}}!", "I'll {{verb}} the {{adjective}} {{abbreviation}} {{noun}}, that should {{noun}} the {{abbreviation}} {{noun}}!" }; var phrase = Random.ArrayElement(phrases); return(phrase.Replace("{{abbreviation}}", Abbreviation()) .Replace("{{adjective}}", Adjective()) .Replace("{{ingverb}}", IngVerb()) .Replace("{{noun}}", Noun()) .Replace("{{verb}}", Verb())); }
/// <summary> /// Returns a random protocol. HTTP or HTTPS. /// </summary> public string Protocol() { var protocols = new[] { "http", "https" }; return(Random.ArrayElement(protocols)); }
/// <summary> /// Get a company suffix. "Inc" and "LLC" etc. /// </summary> /// <returns></returns> public string CompanySuffix() { return(Random.ArrayElement(Suffexes())); }
/// <summary> /// Helper method to access LOCALE.CATEGORY.KEY of a locale data set and returns a random element. /// It assumes LOCALE.CATEGORY.KEY is a JArray. /// </summary> /// <param name="keyOrSubPath">key int the category</param> /// <returns></returns> public string GetRandomArrayItem(string keyOrSubPath) { return(Random.ArrayElement(GetArray(keyOrSubPath))); }
/// <summary> /// Gets a first name /// </summary> public string FirstName() { var get = (JArray)Get("first_name"); return(Random.ArrayElement(get)); }