/// <summary> /// Override model nullable integer property. /// </summary> /// <param name="expression">The expression.</param> /// <param name="max">The maximum.</param> /// <returns>Returns this.</returns> public IAutoBuilderOverrides <TModel> With( Expression <Func <TModel, int?> > expression, int max) { this.Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(max), expression)); return(this); }
private byte GetByteValue(string propertyName) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(byte))) { return((byte)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(byte), AutoBuilderConfiguration)); } return((byte)NAuto.GetRandomInteger(1, 1000)); }
private short GetValue(string propertyName) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(short))) { return((short)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(short), AutoBuilderConfiguration)); } return((short)NAuto.GetRandomInteger(AutoBuilderConfiguration.ShortMinimum, AutoBuilderConfiguration.ShortMaximum)); }
private long?GetValue(string propertyName) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(long?))) { return((long)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(long?), AutoBuilderConfiguration)); } return(NAuto.GetRandomInteger(AutoBuilderConfiguration.IntMinimum, AutoBuilderConfiguration.IntMaximum)); }
public void Should_Return_A_Random_Integer_Which_Is_Less_Than_Or_Equal_To_Max() { // Arrange var max = random.Next(123456); // Act var result1 = NAuto.GetRandomInteger(max); var result2 = NAuto.GetRandomInteger(max); // Assert result1.ShouldNotEqual(result2); result1.ShouldBeLessThanOrEqualTo(max); result2.ShouldBeLessThanOrEqualTo(max); }
private static int GenerateRandomIntFromDataAnnotations(PropertyInfo propertyInfo, AutoBuilderConfiguration autoBuilderConfiguration) { var min = autoBuilderConfiguration.IntMinimum; var max = autoBuilderConfiguration.IntMaximum; var rangeAttribute = propertyInfo.GetCustomAttributes(typeof(RangeAttribute), false).FirstOrDefault(); if (rangeAttribute != null) { min = (int)((RangeAttribute)rangeAttribute).Minimum; max = (int)((RangeAttribute)rangeAttribute).Maximum; } return(NAuto.GetRandomInteger(min, max)); }
private int?GetIntValue(string propertyName, PropertyInfo propertyInfo) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(int?))) { return((int)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(int?), AutoBuilderConfiguration)); } var annotatedType = dataAnnotationConventionMapper.TryGetValue(typeof(int), propertyInfo, AutoBuilderConfiguration); if (annotatedType != null) { return((int)annotatedType); } return(NAuto.GetRandomInteger(AutoBuilderConfiguration.IntMinimum, AutoBuilderConfiguration.IntMaximum)); }
public void Should_Return_A_Random_Integer_Which_Is_Between_Min_And_Max() { // Arrange var min = random.Next(100); var max = random.Next(101, 123456); // Act var result1 = NAuto.GetRandomInteger(min, max); var result2 = NAuto.GetRandomInteger(min, max); // Assert result1.ShouldNotEqual(result2); result1.ShouldBeGreaterThanOrEqualTo(min); result1.ShouldBeLessThanOrEqualTo(max); result2.ShouldBeGreaterThanOrEqualTo(min); result2.ShouldBeLessThanOrEqualTo(max); }
public Enum Populate(string propertyName, Type enumType, object currentValue) { var values = Enum.GetValues(enumType); if (currentValue != null && values.GetValue(0) != currentValue) { return((Enum)currentValue); } if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, enumType)) { return((Enum)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, enumType, AutoBuilderConfiguration)); } if (values.Length <= 1) { return(null); } var randomValue = NAuto.GetRandomInteger(0, values.Length - 1); return((Enum)values.GetValue(randomValue)); }
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))); }