Exemple #1
0
        private object GetValue(DataDefinition definition)
        {
            if (definition.IsKey)
            {
                return(KeyValue++);
            }

            if (definition.Type == typeof(int))
            {
                return((int)GetNumeric(definition));
            }

            if (definition.Type == typeof(DateTime))
            {
                return(GetDate(definition));
            }

            if (definition.Type == typeof(string))
            {
                return(GetString(definition));
            }
            if (definition.Type == typeof(Guid))
            {
                return(GetGuid(definition));
            }
            //Numeric catch all
            return(Convert.ChangeType(GetNumeric(definition), definition.Type));
        }
Exemple #2
0
        private DataDefinition GetDataDefinition(PropertyInfo property)
        {
            var decorations        = new DataDefinition();
            var keyAttribute       = property.GetCustomAttribute <KeyAttribute>(true);
            var rangeAttribute     = property.GetCustomAttribute <RangeAttribute>(true);
            var minLengthAttribute = property.GetCustomAttribute <MinLengthAttribute>(true);
            var maxLengthAttribute = property.GetCustomAttribute <MaxLengthAttribute>(true);

            decorations.Type = property.PropertyType;
            if (keyAttribute != null)
            {
                decorations.IsKey = true;
            }
            if (rangeAttribute != null)
            {
                decorations.MinValue = double.Parse(rangeAttribute.Minimum.ToString());
                decorations.MaxValue = double.Parse(rangeAttribute.Maximum.ToString());
            }
            if (minLengthAttribute != null)
            {
                decorations.MinLength = minLengthAttribute.Length;
            }
            if (maxLengthAttribute != null)
            {
                decorations.MaxLength = maxLengthAttribute.Length;
            }
            return(decorations);
        }
Exemple #3
0
        private string GetString(DataDefinition definition)
        {
            var          totalCharacters = random.Next(definition.MinLength.Value, definition.MaxLength.Value);
            const string chars           = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            return(new string(Enumerable.Repeat(chars, totalCharacters)
                              .Select(s => s[random.Next(s.Length)]).ToArray()));
        }
Exemple #4
0
        private double GetNumeric(DataDefinition definition)
        {
            double minVal = int.MinValue;
            double maxVal = int.MaxValue;

            if (definition.MinValue.HasValue)
            {
                minVal = Math.Max(definition.MinValue.Value, int.MinValue);
            }
            if (definition.MaxValue.HasValue)
            {
                maxVal = Math.Min(definition.MaxValue.Value, int.MaxValue);
            }
            int generatedNumber = random.Next((int)minVal, (int)maxVal);
            int randomPrecision = random.Next(0, 100);

            return(generatedNumber + (randomPrecision / 100.00));
        }
Exemple #5
0
 private Guid GetGuid(DataDefinition definition)
 {
     return(Guid.NewGuid());
 }
Exemple #6
0
 private DateTime GetDate(DataDefinition definition)
 {
     return(DateTime.MinValue.AddDays(random.Next(10, 1000000)));
 }