Last Updated: 22 November 2021
This package contains various fluent style data generators and extension methods for constrained non-determinism in your unit tests, integration tests, general automation projects and mock-ups. These are great for generating values within certain boundaries, or for creating real-world dummy data that will pass validation algorithms.
Bank account number generated by this will pass LUHN checksum and conform to UK bank account standards.
var accountNumber = AccountNumberGenerator.AnyValidAccountNumber();
Console.WriteLine(accountNumber);
Card numbers will pass the LUHN checksum, and can specifically generate debit or credit card numbers, or ones that meet the validation checks for Visa or Mastercard.
Console.WriteLine(CreditCardGenerator.AnyCardNumber());
Console.WriteLine(CreditCardGenerator.AnyCreditCardNumber());
Console.WriteLine(CreditCardGenerator.AnyDebitCardNumber());
Console.WriteLine(CreditCardGenerator.AnyMastercardCreditCardNumber());
Console.WriteLine(CreditCardGenerator.AnyMastercardDebitCardNumber());
Console.WriteLine(CreditCardGenerator.AnyVisaCreditCardNumber());
Console.WriteLine(CreditCardGenerator.AnyVisaDebitCardNumber());
This generates a valid UK six-digit sort code, with or without formatting.
Console.WriteLine(SortCodeGenerator.AnyValidSortCode());
Console.WriteLine(SortCodeGenerator.AnyValidSortCodeWithDashes());
var testArry = new[] {"One", "Two", "Three"};
var randomItem = testArry.AnyElement();
Console.WriteLine(randomItem);
Console.WriteLine(BooleanGenerator.IsCoinTossHeads());
Console.WriteLine(ByteGenerator.AnyByte());
foreach (var b in ByteGenerator.AnyByteArrayOfSize(10))
{
Console.WriteLine(b);
}
Console.WriteLine(DoubleGenerator.AnyDouble());
Console.WriteLine(DoubleGenerator.AnyPositiveDouble());
Console.WriteLine(DoubleGenerator.AnyNegativeDouble());
Console.WriteLine(CharGenerator.RandomAlpha());
Console.WriteLine(CharGenerator.RandomAlphaNumeric());
Console.WriteLine(CharGenerator.RandomChar());
Console.WriteLine(CharGenerator.RandomDigit());
Console.WriteLine(DateTime.Now.AnyTime());
Console.WriteLine(DateTime.Now.AnyDifferentTime());
Console.WriteLine(DateTime.Now.AnyTimeOtherThan(new TimeSpan(1, 2, 3, 4)));
Console.WriteLine(DateTimeGenerator.FirstDayOfThisMonth());
Console.WriteLine(DateTimeGenerator.FirstDayOfMonth(DateTime.Now));
Console.WriteLine(DateTimeGenerator.LastDayOfThisMonth());
Console.WriteLine(DateTimeGenerator.LastDayOfMonth(DateTime.Now));
Console.WriteLine(DateTimeGenerator.Today());
Console.WriteLine(DateTimeGenerator.Tomorrow());
Methods ending in 'Date' will have midnight (00:00:00) as the time portion, ones ending in 'DateTime' will have a random time.
Console.WriteLine(DateTimeGenerator.AnyDate());
Console.WriteLine(DateTimeGenerator.AnyTime());
Console.WriteLine(DateTimeGenerator.AnyDateAfter(DateTime.Now));
Console.WriteLine(DateTimeGenerator.AnyDateBefore(DateTime.Now));
Console.WriteLine(DateTimeGenerator.AnyDateBetween(DateTime.Now, new DateTime(2099, 1, 1)));
Console.WriteLine(DateTimeGenerator.AnyDateExcept(DateTime.Now));
Console.WriteLine(DateTimeGenerator.AnyDateTime());
Console.WriteLine(DateTimeGenerator.AnyDateTimeAfter(DateTime.Now));
Console.WriteLine(DateTimeGenerator.AnyDateTimeExcept(DateTime.Now));
These can be useful when you need a time period with a set start and end date.
var pair1 = DateTimeGenerator.AnyPairOfDateTimes();
Console.WriteLine(pair1.Min + ", " + pair1.Max);
var pair2 = DateTimeGenerator.AnyPairOfDates();
Console.WriteLine(pair2.Min + ", " + pair2.Max);
var relative1 = DateTimeGenerator.AnyRelativeDateTimes();
Console.WriteLine("Now: " + relative1.Now + " Past: " + relative1.InThePast + " Future: " + relative1.InTheFuture);
var d1 = 1.23M;
Console.WriteLine(d1.LimitedBy(1, 2));
Console.WriteLine(d1.ReverseSign());
Console.WriteLine(d1.Absolute());
Console.WriteLine(DecimalGenerator.AnyCurrencyAmount());
Console.WriteLine(DecimalGenerator.AnyCurrencyAmountGreaterThan(100));
Console.WriteLine(DecimalGenerator.AnyDecimalInHalfOpenRange(10, 100));
Console.WriteLine(DecimalGenerator.AnyPositiveCurrencyAmount());
This will generate e-mail addresses that will pass most e-mail validation algorithms.
Console.WriteLine(EmailAddressGenerator.AnyEmailAddress());
var e1 = new[] {"one", "two", "three", "four", "five"};
var e2 = e1.Shuffle();
foreach (var e in e2) Console.WriteLine(e);
Console.WriteLine(e1.AnyItem());
e1.ForEach(Console.WriteLine);
var e3 = EnumerableGenerator.BoundedSequence(10, CreateNewThing);
e3.ForEach(Console.WriteLine);
var e4 = EnumerableGenerator.UniqueBoundedSequence(10, CreateNewThing);
e4.ForEach(Console.WriteLine);
Console.WriteLine(EnumGenerator.AnyEnumValue<ThingEnumeration>());
Console.WriteLine(EnumGenerator.AnyEnumValueExcept(ThingEnumeration.Hello));
Console.WriteLine(EnumGenerator.AnyEnumValueIn(ThingEnumeration.Hello, ThingEnumeration.World));
Console.WriteLine(IntegerGenerator.AnyInteger());
Console.WriteLine(IntegerGenerator.AnyIntegerInHalfOpenRange(100, 1000));
var i1 = IntegerGenerator.AnyIntegerListOfSize(10);
i1.ForEach(Console.WriteLine);
var i2 = IntegerGenerator.UniquePositiveIntegerListOfSize(10);
i2.ForEach(Console.WriteLine);
This will generate valid IP v4 addresses.
Console.WriteLine(IpAddressGenerator.AnyIpAddress());
IpAddressGenerator.GenerateRandomNonRepeatingIpAddresses(10).ForEach(Console.WriteLine);
This will generate a number of the required length, where the last digit is a valid Luhn check digit. This is the algorithm commonly used by bank accounts and credit card numbers, so if the standard UK lengths are not suitable, then use this instead.
Console.WriteLine(LuhnGenerator.AnyValidNumber(10));
Console.WriteLine(LuhnGenerator.CalculateCheckDigit("12345"));
These generators will create random names and titles, with the ability to have specific male or female forenames if required.
Console.WriteLine(NameGenerator.AnyName());
Console.WriteLine(NameGenerator.AnyAdultTitle());
Console.WriteLine(NameGenerator.AnyChildTitle());
Console.WriteLine(NameGenerator.AnyFemaleForename());
Console.WriteLine(NameGenerator.AnyMaleForename());
Console.WriteLine(NameGenerator.AnyForename());
Console.WriteLine(NameGenerator.AnyMaleName());
Console.WriteLine(NameGenerator.AnyFemaleName());
Console.WriteLine(NameGenerator.AnySurname());
Console.WriteLine(NameGenerator.AnyTitle());
This will generate a valid UK National Insurance number, with or without formatting.
Console.WriteLine(NationalInsuranceNumberGenerator.Any());
Console.WriteLine(NationalInsuranceNumberGenerator.AnyFormatted());
This will generate a valid UK postcode that is either a genuine postcode somewhere in the country, or one that may not necessarily be real but which passes most standard validation algorithms.
Console.WriteLine(PostcodeGenerator.AnyPostcode());
Console.WriteLine(PostcodeGenerator.AnyValidPostcode());
Console.WriteLine(ShortGenerator.AnyShort());
Console.WriteLine(ShortGenerator.AnyShortInHalfOpenRange(10, 100));
Console.WriteLine(StringGenerator.AnyNonNullString());
Console.WriteLine(StringGenerator.AnyEmptyOrWhitespaceString());
Console.WriteLine(StringGenerator.AnyStringOfSizeAndCase(100, CaseType.TitleCase));
Console.WriteLine(StringGenerator.SequenceOfAlphaNumerics(10));
Console.WriteLine(StringGenerator.SequenceOfAlphas(10));
Console.WriteLine(StringGenerator.SequenceOfDigits(10));
This can generate a landline or mobile telephone number that will pass validation checks.
Console.WriteLine(TelephoneNumberGenerator.AnyLandlineNumber());
Console.WriteLine(TelephoneNumberGenerator.AnyMobileNumber());
Console.WriteLine(TelephoneNumberGenerator.AnyTelephoneNumber());
This will generate a user agent string.
Console.WriteLine(UserAgentGenerator.AnyUserAgent());
Console.WriteLine(UserAgentGenerator.GoogleBotUserAgent());