public object GenerateField(ref FieldGeneratorOptions opts) { var NameGen = new PersonNameGenerator(GeneratorsStatic.Random); switch ((opts.Variant ?? "").ToLower()) { case "first": case "f": return(NameGen.GenerateRandomFirstName()); case "middle": case "m": return($"{(char)GeneratorsStatic.Random.Next('A', 'Z' + 1)}"); case "last": case "l": return(NameGen.GenerateRandomLastName()); case "suffix": case "s": return(Suffixes[GeneratorsStatic.Random.Next(Suffixes.Count)]); default: return(NameGen.GenerateRandomFirstAndLastName()); } }
public static FieldGeneratorOptions ParseGeneratorOptionPairs(PropertyInfo prop) { IDictionary optsInterDict = new FieldGeneratorOptionsDict(); prop.GetCustomAttributes(false).ToList().ForEach(cAttr => { if (cAttr.GetType() == typeof(GeneratorOptionPairAttribute)) { var gop = (GeneratorOptionPairAttribute)cAttr; optsInterDict[gop.Key] = gop.Value; } }); var retVal = new FieldGeneratorOptions(); for (int i = (int)FieldGeneratorOptionType.NoOpt_FirstValue + 1; i < (int)FieldGeneratorOptionType.NoOpt_LastValue; i++) { if (optsInterDict.Contains((FieldGeneratorOptionType)i)) { var asType = (FieldGeneratorOptionType)i; retVal.GetType().GetField(asType.ToString()).SetValue(retVal, optsInterDict[asType]); } } return(retVal); }
public override object GenerateField(ref FieldGeneratorOptions opts) { var genDt = (DateTime?)base.GenerateField(ref opts); var frmtStr = opts.FormatString ?? DefaultFormatString; return(genDt == null ? "" : genDt.Value.ToString(frmtStr)); }
public IGeneratedRecord Next(Type type, uint seqNo) { if (new Random().Next((int)(1.0 / Frequency)) == 0) { var target = ConcretePropertySelector(); var curVal = target.GetValue(_current); var fieldGen = new List <Type>() { ((GeneratorTypeAttribute)target.GetCustomAttributes(true) .FirstOrDefault(ca => ca.GetType() == typeof(GeneratorTypeAttribute)))?.Type, GeneratorsStatic.DefaultFieldGeneratorTypes[target.PropertyType], target.PropertyType } .Where(lt => lt != null && GeneratorsStatic.GeneratorCache.ContainsKey(lt)) .Select(lt => GeneratorsStatic.GeneratorCache[lt]) .FirstOrDefault(); if (fieldGen == null) { throw new InvalidProgramException($"No generator available for {target}"); } var fakeConfig = new FieldGeneratorOptions(); var newVal = fieldGen.GenerateField(ref fakeConfig); #if DEBUG Console.WriteLine($"{GetType().Name} altering #{seqNo}'s field '{target.Name}' from '{curVal}' to '{newVal}'!"); #endif target.SetValue(_current, newVal); } return(_current); }
public object LinkField(object linkedDateStr, ref FieldGeneratorOptions opts) { if (DateTime.TryParse((string)linkedDateStr, out var outDate)) { return((int)(DateTime.UtcNow - outDate).TotalDays / 365); } throw new InvalidProgramException("Bad specification!"); }
public object GenerateField(ref FieldGeneratorOptions opts) { var randType = _types[GeneratorsStatic.Random.Next(_types.Count)]; var randChar = GeneratorsStatic.Random.Next(2) == 0 ? "" : ((char)GeneratorsStatic.Random.Next('A', 'Z' + 1)).ToString(); // if randChar is empty, always generate a randNum; otherwise, give it a 50/50 chance var randNum = string.IsNullOrEmpty(randChar) || GeneratorsStatic.Random.Next(2) == 0 ? GeneratorsStatic.Random.Next(1000).ToString() : ""; return($"{randType} {randNum}{randChar}"); }
public object LinkField(object linkedFieldValue, ref FieldGeneratorOptions opts) { if (opts.FormatString == null) { throw new ArgumentException("GmailStylePlusAddressedEmailUsingNameLinker: Must specify base email address as format string"); } var atIndex = opts.FormatString.IndexOf('@'); if (atIndex == -1) { throw new ArgumentException($"GmailStylePlusAddressedEmailUsingNameLinker: Format string ('{opts.FormatString}') is not an email address"); } return(opts.FormatString.Insert(atIndex, $"+{linkedFieldValue.ToString().Replace("+", "")}")); }
public object GenerateField(ref FieldGeneratorOptions opts) { var returnValue = GeneratorsStatic.Random.GenerateRandomPlaceName(); if (opts.LengthLimit > 0) { // first, try for something shorter rather than just truncating a long name // but don't try forever var tries = 1 << 10; while (returnValue.Length > opts.LengthLimit && tries-- > 0) { returnValue = GeneratorsStatic.Random.GenerateRandomPlaceName(); } } // last resort: truncate whatever we have if it's still too long return(returnValue.Substring(0, opts.LengthLimit > 0 && returnValue.Length > opts.LengthLimit ? opts.LengthLimit : returnValue.Length)); }
public object GenerateField(ref FieldGeneratorOptions opts) { int length = opts.LengthLimit == FieldGeneratorOptions.DefaultLength ? DefaultZipCodeLength : opts.LengthLimit; return($"{GeneratorsStatic.Random.Next((int)Math.Pow(10, length - 1), (int)Math.Pow(10, length))}"); }
public virtual object LinkField(object linked, ref FieldGeneratorOptions opts) { return((bool)linked ? new Random().Next((int)opts.MaxValue) : 0); }
public object GenerateField(ref FieldGeneratorOptions opts) { return(Words.RandomWord().FirstCharToUpper().Replace("'", "") + " " + _suffixes[GeneratorsStatic.Random.Next(_suffixes.Count)]); }
public object GenerateField(ref FieldGeneratorOptions fo) { return(true); }
public object GenerateField(ref FieldGeneratorOptions opts) { return($"{GeneratorsStatic.Random.Next(10000)} {Words.RandomWord().FirstCharToUpper()}" + $"{(GeneratorsStatic.Random.Next(5) == 0 ? "" : " " + Words.RandomWord().FirstCharToUpper())} " + $"{_streetTypes[GeneratorsStatic.Random.Next(_streetTypes.Count)]}"); }
public object GenerateField(ref FieldGeneratorOptions opts) { return(_genders[GeneratorsStatic.Random.Next(_genders.Count)]); }
public override object LinkField(object linkedBool, ref FieldGeneratorOptions opts) { return(new decimal((int)base.LinkField(linkedBool, ref opts))); }
public object GenerateField(ref FieldGeneratorOptions opts) { return($"{Words.RandomSafeCharsWord().ToLower()}" + $"{(GeneratorsStatic.Random.Next(2) == 0 ? "" : GeneratorsStatic.Random.Next(100).ToString())}@" + $"{Words.RandomSafeCharsWord().ToLower()}.{_tlds[GeneratorsStatic.Random.Next(_tlds.Count)]}"); }
public object GenerateField(ref FieldGeneratorOptions opts) { return($"{GeneratorsStatic.Random.Next(100, 1000)}{GeneratorsStatic.Random.Next(10, 100)}{GeneratorsStatic.Random.Next(1000, 10000)}"); }
public object LinkField(object linkedEmployer, ref FieldGeneratorOptions opts) { return(string.IsNullOrEmpty((string)linkedEmployer) ? 0 : new Random().Next(Math.Min((int)opts.MaxValue, 40))); }
public object LinkField(object linkedFieldValue, ref FieldGeneratorOptions opts) { return(linkedFieldValue); }
public object GenerateField(ref FieldGeneratorOptions opts) { return(StateTwoLetterCodes[GeneratorsStatic.Random.Next(StateTwoLetterCodes.Count)]); }