private static object CreateRandomIncorrectLength <T>(T value, PropertyInfo property) { var descriptor = DescriptorUtils.GetDescriptorFromPropertyName <T>(property.Name); // If property doesn't have a DescriptorAttribute give back a random string and log this. if (null == descriptor) { Debug.WriteLine("Generation for invalid value for property {0} with no DescriptorAttribute.", property); return(StringCreation.CreateRandomCfString(DefaultStringLength, false, CharacterType.Letters)); } // Detect if the property is a List if (property.GetValue(value) is IList && property.PropertyType.IsGenericType) { // Set the list to an empty new list var propertyConstructor = property.PropertyType.GetConstructor(Type.EmptyTypes); if (propertyConstructor != null) { return(propertyConstructor.Invoke(null)); } throw new ArgumentException("Property is a List but has no default constructor", "property"); } // If the descriptorAttribute is an enum what do I give back as invalid? if (null != descriptor.EnumType) { // TODO: This length doesn't necessarily reflect the invalidation length in the db for all uses of enums. return(StringCreation.CreateRandomCfString(11, false, CharacterType.DigitsOrLetters)); } // Return random string that isn't in the array if the array is defined. if (null != descriptor.Array) { var randomString = string.Empty; var isInArray = true; while (isInArray) { randomString = StringCreation.CreateRandomCfString(11, false, CharacterType.DigitsOrLetters); if (!descriptor.Array.Contains(randomString)) { isInArray = false; } } return(randomString); } // Return value longer than maxLength is a regex is used. if (null != descriptor.Regex) { return(CreateInvalidLengthCfString(descriptor)); } // Return value generated from PropertyType switch (descriptor.PropertyType) { case PropertyType.String: return(CreateInvalidLengthCfString(descriptor)); case PropertyType.Int: return(StringCreation.CreateRandomCfString(DefaultStringLength, false, CharacterType.Letters)); case PropertyType.Decimal: return(StringCreation.CreateRandomCfString(DefaultStringLength, false, CharacterType.Letters)); case PropertyType.Bool: return(StringCreation.CreateRandomCfString(DefaultStringLength, false, CharacterType.Letters)); case PropertyType.Date: return(StringCreation.CreateRandomCfString(DefaultStringLength, false, CharacterType.DigitsOrLetters)); case PropertyType.Email: return(StringCreation.CreateRandomCfString(DefaultStringLength, false)); default: throw new ArgumentOutOfRangeException(); } }