Name generator for unit tests.
It allows to generate any pseudo natural string values for your unit tests/specs. Especially it'll be extremely useful for load tests when you need to fill your database with data looks like real one. See examples to get an idea of the library.
It's a great companion to AutoFixture.
Let's say we want enormous number of full person names in form of <title> <firstname>12 <lastname>034
.
var ladyName = Name.From("Jill", "Janette", "Jane", "Jinny");
var ladyTitle = Name.Mix("mrs", "ms", "dr");
var gentelmanName = Name.From("John", "Jack", "Jamey", "Joshua");
var gentelmanTitle = Name.Mix("mr", "dr", "sir", "colonel");
var lady = ladyTitle
.Then(" ")
.Then(ladyName)
.Then(Name.From(Index.Forward(50)));
var gentelman = gentelmanTitle
.Then(" ")
.Then(gentelmanName)
.Then(Name.From(Index.Forward(50)));
var firstName = lady.Or(gentelman);
var lastName = Name.Mix("Nixon", "Obama", "Bush")
.Then(Name.From(Index.Forward(100)).WithPadding(3));
var personName = firstName.Then(" ", lastName);
var names = Enumerable.Range(0, 1000)
.Select(_ => personName.Next())
.ToList();
var phoneNumber = BuiltinNames.PhoneNumber("+7 926 ", 7);
var sample = phoneNumber.Next();
Console.WriteLine(sample); // +7 926 0012345
It has pretty simple implementation
public static class BuiltinNames
{
public static INameSource PhoneNumber(string prefix, int digits)
{
if ((digits <= 0) || (digits > 20))
throw new ArgumentOutOfRangeException(nameof(digits), "should be less then or equal to 20");
int till = (int)Math.Pow(10, digits);
return Name.From(prefix)
.Then(Name.From(Index.Forward(till)).WithPadding(digits));
}
}
var email = Name.Mix("Jake", "John", "Lisa")
.Then(Name.From(Index.Forward(1000)).WithPadding(4))
.Then("@")
.Then(Name.Mix("hotmail.com", "google.com", "yahoo.com"));
var sample = email.Next();
All contents of this package are licensed under the MIT license.