Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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!");
        }
Ejemplo n.º 6
0
        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}");
        }
Ejemplo n.º 7
0
        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("+", "")}"));
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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))}");
        }
Ejemplo n.º 10
0
 public virtual object LinkField(object linked, ref FieldGeneratorOptions opts)
 {
     return((bool)linked ? new Random().Next((int)opts.MaxValue) : 0);
 }
Ejemplo n.º 11
0
 public object GenerateField(ref FieldGeneratorOptions opts)
 {
     return(Words.RandomWord().FirstCharToUpper().Replace("'", "") + " " +
            _suffixes[GeneratorsStatic.Random.Next(_suffixes.Count)]);
 }
Ejemplo n.º 12
0
 public object GenerateField(ref FieldGeneratorOptions fo)
 {
     return(true);
 }
Ejemplo n.º 13
0
 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)]}");
 }
Ejemplo n.º 14
0
 public object GenerateField(ref FieldGeneratorOptions opts)
 {
     return(_genders[GeneratorsStatic.Random.Next(_genders.Count)]);
 }
Ejemplo n.º 15
0
 public override object LinkField(object linkedBool, ref FieldGeneratorOptions opts)
 {
     return(new decimal((int)base.LinkField(linkedBool, ref opts)));
 }
Ejemplo n.º 16
0
 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)]}");
 }
Ejemplo n.º 17
0
 public object GenerateField(ref FieldGeneratorOptions opts)
 {
     return($"{GeneratorsStatic.Random.Next(100, 1000)}{GeneratorsStatic.Random.Next(10, 100)}{GeneratorsStatic.Random.Next(1000, 10000)}");
 }
Ejemplo n.º 18
0
 public object LinkField(object linkedEmployer, ref FieldGeneratorOptions opts)
 {
     return(string.IsNullOrEmpty((string)linkedEmployer) ? 0 :
            new Random().Next(Math.Min((int)opts.MaxValue, 40)));
 }
Ejemplo n.º 19
0
 public object LinkField(object linkedFieldValue, ref FieldGeneratorOptions opts)
 {
     return(linkedFieldValue);
 }
Ejemplo n.º 20
0
 public object GenerateField(ref FieldGeneratorOptions opts)
 {
     return(StateTwoLetterCodes[GeneratorsStatic.Random.Next(StateTwoLetterCodes.Count)]);
 }