public static string GetRandomEmail(Language language = Language.English) { var identifier = NAuto.GetRandomString(5, 25, CharacterSetType.AlphaNumeric, Spaces.None, Casing.Lowered, language); var domain = NAuto.GetRandomString(15, CharacterSetType.AlphaNumeric, Spaces.None, Casing.Lowered, language); return(string.Format("{0}@{1}.com", identifier, domain)); }
/// <summary> /// Override model string property. /// </summary> /// <param name="expression">The expression.</param> /// <param name="length">The length.</param> /// <returns>Returns this.</returns> public IAutoBuilderOverrides <TModel> With( Expression <Func <TModel, string> > expression, int length) { this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length), expression)); return(this); }
private static Document GetMockDocument(string type, IDictionary <string, Fragment> fragments, ISet <string> tags = null) { tags = tags ?? new SortedSet <string>(); var rand = NAuto.GetRandomString(6, 50, CharacterSetType.Anything, Spaces.None, Casing.Any); return(new Document(rand, rand, type, "http://example.com", tags, new List <string>(), fragments)); }
public static string GetRandomUrl(Language language = Language.English) { const string FirstPart = "http://www."; var secondPart = NAuto.GetRandomString(5, 15, CharacterSetType.AlphaNumeric, Spaces.None, Casing.Lowered, language); const string LastPart = ".com"; return(string.Format("{0}{1}{2}", FirstPart, secondPart, LastPart)); }
private static string GenerateRandomStringFromDataAnnotations(PropertyInfo propertyInfo, AutoBuilderConfiguration autoBuilderConfiguration) { var minLength = autoBuilderConfiguration.StringMinLength; var maxLength = autoBuilderConfiguration.StringMaxLength; //var minLengthAttribute = propertyInfo.GetCustomAttributes(typeof(MinLengthAttribute), false).FirstOrDefault(); //if (minLengthAttribute != null) //{ // minLength = ((MinLengthAttribute)minLengthAttribute).Length; //} //var maxLengthAttribute = propertyInfo.GetCustomAttributes(typeof(MaxLengthAttribute), false).FirstOrDefault(); //if (maxLengthAttribute != null) //{ // maxLength = ((MaxLengthAttribute)maxLengthAttribute).Length; //} //if (minLengthAttribute != null || maxLengthAttribute != null) //{ // { // return NAuto.GetRandomString( // minLength, // maxLength, // autoBuilderConfiguration.DefaultStringCharacterSetType, // autoBuilderConfiguration.DefaultStringSpaces, // autoBuilderConfiguration.DefaultStringCasing, // autoBuilderConfiguration.DefaultLanguage); // } //} var stringLengthAttribute = propertyInfo.GetCustomAttributes(typeof(StringLengthAttribute), false).FirstOrDefault(); if (stringLengthAttribute != null) { var minStringLength = ((StringLengthAttribute)stringLengthAttribute).MinimumLength; var maxStringLength = ((StringLengthAttribute)stringLengthAttribute).MaximumLength; if (maxStringLength == 0) { maxStringLength = minStringLength + 50; } if (maxStringLength < minStringLength) { throw new ArgumentException("Property " + propertyInfo.Name + ": the minimum string length cannot be greater than the maximum string length..."); } return(NAuto.GetRandomString( minStringLength, maxStringLength, autoBuilderConfiguration.DefaultStringCharacterSetType, autoBuilderConfiguration.DefaultStringSpaces, autoBuilderConfiguration.DefaultStringCasing, autoBuilderConfiguration.DefaultLanguage)); } return(null); }
private char GetCharValue(string propertyName) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(char))) { return((char)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(char), AutoBuilderConfiguration)); } return(char.Parse(NAuto.GetRandomString(1, AutoBuilderConfiguration.DefaultLanguage))); }
/// <summary> /// Override model string property. /// </summary> /// <param name="expression">The expression.</param> /// <param name="minLength">The minimum length.</param> /// <param name="maxLength">The maximum length.</param> /// <param name="characterSetType">Type of the character set.</param> /// <param name="spaces">The spaces.</param> /// <returns>Returns this.</returns> public IAutoBuilderOverrides <TModel> With( Expression <Func <TModel, string> > expression, int minLength, int maxLength, CharacterSetType characterSetType, Spaces spaces) { this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(minLength, minLength, characterSetType, spaces), expression)); return(this); }
public static string GetRandomPostalCode(Language language = Language.English) { var firstPart = NAuto.GetRandomString(2, CharacterSetType.Alpha, Spaces.None, Casing.Uppered, language); var secondPart = NAuto.GetRandomString(1, 2, CharacterSetType.Numeric, Spaces.None, Casing.Uppered, language); var thirdPart = NAuto.GetRandomString(1, CharacterSetType.Numeric, Spaces.None, Casing.Uppered, language); var lastPart = NAuto.GetRandomString(2, CharacterSetType.Alpha, Spaces.None, Casing.Uppered, language); return(string.Format("{0}{1} {2}{3}", firstPart, secondPart, thirdPart, lastPart)); }
public static string GetRandomTelephoneNumber(Language language = Language.English) { var firstPart = NAuto.GetRandomString(4, CharacterSetType.Numeric, Spaces.None, Casing.Any, language); var secondPart = NAuto.GetRandomString(3, CharacterSetType.Numeric, Spaces.None, Casing.Any, language); var thirdPart = NAuto.GetRandomString(3, CharacterSetType.Numeric, Spaces.None, Casing.Any, language); if (language != Language.Chinese) { return(string.Format("0{0} {1} {2}", firstPart, secondPart, thirdPart)); } return(string.Format("{0} {1} {2}", firstPart, secondPart, thirdPart)); }
public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Include_Any_Characters_And_Casing() { // Arrange var length = random.Next(100, 10000); // Act var result1 = NAuto.GetRandomString(length, CharacterSetType.Anything); var result2 = NAuto.GetRandomString(length, CharacterSetType.Anything); // Assert result1.Length.ShouldEqual(length); result2.Length.ShouldEqual(length); result1.ShouldNotEqual(result2); }
public void Should_Return_A_Random_String_Between_MinLength_And_MaxLength() { // Arrange var minLength = random.Next(5); var maxLength = random.Next(6, 10000); // Act var result1 = NAuto.GetRandomString(minLength, maxLength, CharacterSetType.Anything, Spaces.Any); var result2 = NAuto.GetRandomString(minLength, maxLength, CharacterSetType.Anything, Spaces.Any); // Assert result1.Length.ShouldBeGreaterThanOrEqualTo(minLength); result2.Length.ShouldBeLessThanOrEqualTo(maxLength); result1.ShouldNotEqual(result2); }
public void Should_Return_A_Random_String_Which_Should_End_With_A_Space() { // Arrange var length = random.Next(20, 10000); // Act var result1 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.End, Casing.Any); var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.End, Casing.Any); // Assert result1.Length.ShouldEqual(length); result2.Length.ShouldEqual(length); result1.ShouldNotEqual(result2); result1[length - 1].ShouldEqual(' '); result2[length - 1].ShouldEqual(' '); }
public void Should_Return_A_Random_String_Which_Can_Contain_Spaces() { // Arrange var length = random.Next(20, 10000); var regexForTrue = new Regex("^[a-zA-Z0-9 ]*$"); // Act var result1 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.Any, Casing.Any); var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.Any, Casing.Any); // Assert result1.Length.ShouldEqual(length); result2.Length.ShouldEqual(length); result1.ShouldNotEqual(result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Can contain spaces " + result1); regexForTrue.IsMatch(result2).ShouldBeTrue("Can contain spaces " + result2); }
public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Upper_Case_Only() { // Arrange var length = random.Next(20, 10000); var regexForFalse = new Regex("^[a-z0-9_]*$"); var regexForTrue = new Regex("^[A-Z ]*$"); // Act var result1 = NAuto.GetRandomString(length, CharacterSetType.Alpha, Spaces.Any, Casing.Uppered); var result2 = NAuto.GetRandomString(length, CharacterSetType.Alpha, Spaces.Any, Casing.Uppered); // Assert result1.Length.ShouldEqual(length); result2.Length.ShouldEqual(length); result1.ShouldNotEqual(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain upper case letters " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain upper case letters " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain upper case letters " + result1); regexForTrue.IsMatch(result2).ShouldBeTrue("Should only contain upper case letters " + result2); }
public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Numbers_Only() { // Arrange var length = random.Next(20, 10000); var regexForFalse = new Regex("^[a-zA-Z_]*$"); var regexForTrue = new Regex("^[0-9 ]*$"); // Act var result1 = NAuto.GetRandomString(length, CharacterSetType.Numeric); var result2 = NAuto.GetRandomString(length, CharacterSetType.Numeric); // Assert result1.Length.ShouldEqual(length); result2.Length.ShouldEqual(length); result1.ShouldNotEqual(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain numbers " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain numbers " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain numbers " + result1); regexForTrue.IsMatch(result2).ShouldBeTrue("Should only contain numbers " + result2); }
private string GetStringValue(string propertyName, PropertyInfo propertyInfo) { if (AutoBuilderConfiguration.Conventions.MatchesConvention(propertyName, typeof(string))) { return((string)AutoBuilderConfiguration.Conventions.GetConventionResult(propertyName, typeof(string), AutoBuilderConfiguration)); } var annotatedType = dataAnnotationConventionMapper.TryGetValue(typeof(string), propertyInfo, AutoBuilderConfiguration); if (annotatedType != null) { return((string)annotatedType); } return(NAuto.GetRandomString( AutoBuilderConfiguration.StringMinLength, AutoBuilderConfiguration.StringMaxLength, AutoBuilderConfiguration.DefaultStringCharacterSetType, AutoBuilderConfiguration.DefaultStringSpaces, AutoBuilderConfiguration.DefaultStringCasing, AutoBuilderConfiguration.DefaultLanguage)); }
private static Dictionary <string, Fragment> GenerateMockDocumentFragments() { return(new Dictionary <string, Fragment> { { "test.structured", new StructuredText(new List <StructuredText.Block> { new StructuredText.Paragraph(NAuto.GetRandomString(15), new List <StructuredText.Span>(), "test") }) }, { "test.structured_text_named", new StructuredText(new List <StructuredText.Block> { new StructuredText.Paragraph(NAuto.GetRandomString(15), new List <StructuredText.Span>(), "test") }) }, { "test.datetime", new Date(DateTime.Now) }, { "test.datetime_named", new Date(DateTime.Now) }, { "test.childtext", new prismic.fragments.Text(NAuto.GetRandomString(15)) }, { "test.child_text_named", new prismic.fragments.Text(NAuto.GetRandomString(15)) } }); }
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))); }