Exemple #1
0
 /// <summary>
 /// Override model string property.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="propertyType">Type of the property.</param>
 /// <returns>Returns this.</returns>
 public IAutoBuilderOverrides <TModel> With(
     Expression <Func <TModel, string> > expression,
     PropertyType propertyType)
 {
     this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomPropertyType(propertyType), expression));
     return(this);
 }
            public void Should_Return_A_Random_Telephone_Number()
            {
                // Act
                var telephoneNumber = NAuto.GetRandomPropertyType(PropertyType.TelephoneNumber);

                // Assert
                telephoneNumber.ShouldNotBeNull();
            }
            public void Should_Return_A_Random_Email()
            {
                // Act
                var email = NAuto.GetRandomPropertyType(PropertyType.Email);

                // Assert
                email.ShouldNotBeNull();
            }
Exemple #4
0
        private Uri GetUriValue(string propertyName)
        {
            if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(Uri)))
            {
                return((Uri)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(Uri), AutoBuilderConfiguration));
            }

            return(new Uri(NAuto.GetRandomPropertyType(PropertyType.Url, AutoBuilderConfiguration.DefaultLanguage)));
        }
Exemple #5
0
        public object TryGetValue(Type type, PropertyInfo propertyInfo, AutoBuilderConfiguration autoBuilderConfiguration)
        {
            if (propertyInfo != null)
            {
                var dataTypeAttribute = propertyInfo.GetCustomAttributes(typeof(DataTypeAttribute), true).FirstOrDefault();
                if (dataTypeAttribute != null)
                {
                    var dataType = ((DataTypeAttribute)dataTypeAttribute).DataType;
                    if (type == typeof(string))
                    {
                        if (dataType == DataType.EmailAddress)
                        {
                            return(NAuto.GetRandomPropertyType(PropertyType.Email));
                        }

                        if (dataType == DataType.PhoneNumber)
                        {
                            return(NAuto.GetRandomPropertyType(PropertyType.TelephoneNumber));
                        }

                        if (dataType == DataType.Url)
                        {
                            return(NAuto.GetRandomPropertyType(PropertyType.Url));
                        }
                    }
                }

                if (type == typeof(string))
                {
                    return(GenerateRandomStringFromDataAnnotations(propertyInfo, autoBuilderConfiguration));
                }

                if (type == typeof(int))
                {
                    return(GenerateRandomIntFromDataAnnotations(propertyInfo, autoBuilderConfiguration));
                }

                if (type == typeof(double))
                {
                    return(GenerateRandomDoubleFromDataAnnotations(propertyInfo, autoBuilderConfiguration));
                }
            }

            return(null);
        }
Exemple #6
0
 public Conventions()
 {
     Add(new ConventionMap(ConventionFilterType.Contains, "email", typeof(string), configuration => NAuto.GetRandomPropertyType(PropertyType.Email, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "postcode", typeof(string), configuration => NAuto.GetRandomPropertyType(PropertyType.PostalCode, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.EndsWith, "url", typeof(string), configuration => NAuto.GetRandomPropertyType(PropertyType.Url, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.EndsWith, "uri", typeof(string), configuration => NAuto.GetRandomPropertyType(PropertyType.Url, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "website", typeof(string), configuration => NAuto.GetRandomPropertyType(PropertyType.Url, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "username", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.AlphaNumeric, Spaces.None, Casing.Lowered, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "firstname", typeof(string), configuration => NAuto.GetRandomString(3, 10, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "lastname", typeof(string), configuration => NAuto.GetRandomString(3, 10, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "forename", typeof(string), configuration => NAuto.GetRandomString(3, 10, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "surname", typeof(string), configuration => NAuto.GetRandomString(3, 10, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "dateofbirth", typeof(DateTime), configuration => DateTime.Now.AddYears(-20)));
     Add(new ConventionMap(ConventionFilterType.Contains, "dateofbirth", typeof(DateTime?), configuration => DateTime.Now.AddYears(-20)));
     Add(new ConventionMap(ConventionFilterType.Contains, "age", typeof(int), configuration => NAuto.GetRandomInteger(10, 70)));
     Add(new ConventionMap(ConventionFilterType.Contains, "age", typeof(int?), configuration => NAuto.GetRandomInteger(10, 70)));
     Add(new ConventionMap(ConventionFilterType.Contains, "housename", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.AlphaNumeric, Spaces.Middle, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "houseno", typeof(string), configuration => NAuto.GetRandomString(1, 5, CharacterSetType.AlphaNumeric, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "addressline", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.Middle, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "street", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "town", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "city", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "county", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
     Add(new ConventionMap(ConventionFilterType.Contains, "country", typeof(string), configuration => NAuto.GetRandomString(3, 15, CharacterSetType.Alpha, Spaces.None, Casing.ProperCase, configuration.DefaultLanguage)));
 }