Bogus 20.0.1

A simple and sane data generator for populating objects that supports different locales. A delightful port of the famed faker.js and inspired by FluentValidation. Use it to create and load databases and UIs with mock up data. Get started by using Faker class or a DataSet directly.

There is a newer version of this package available.
See the version list below for details.
Install-Package Bogus -Version 20.0.1
dotnet add package Bogus --version 20.0.1
<PackageReference Include="Bogus" Version="20.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bogus --version 20.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

The Great C# Example

public enum Gender
{
    Male,
    Female
}

//Set the randomzier seed if you wish to generate repeatable data sets.
Randomizer.Seed = new Random(8675309);

var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" };

var orderIds = 0;
var testOrders = new Faker<Order>()
    //Ensure all properties have rules. By default, StrictMode is false
    //Set a global policy by using Faker.DefaultStrictMode
    .StrictMode(true)
    //OrderId is deterministic
    .RuleFor(o => o.OrderId, f => orderIds++)
    //Pick some fruit from a basket
    .RuleFor(o => o.Item, f => f.PickRandom(fruit))
    //A random quantity from 1 to 10
    .RuleFor(o => o.Quantity, f => f.Random.Number(1, 10));


var userIds = 0;
var testUsers = new Faker<User>()
    //Optional: Call for objects that have complex initialization
    .CustomInstantiator(f => new User(userIds++, f.Random.Replace("###-##-####")))

    //Basic rules using built-in generators
    .RuleFor(u => u.FirstName, f => f.Name.FirstName())
    .RuleFor(u => u.LastName, f => f.Name.LastName())
    .RuleFor(u => u.Avatar, f => f.Internet.Avatar())
    .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName))
    .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName))
    .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}")
    .RuleFor(u => u.SomeGuid, Guid.NewGuid)

    //Use an enum outside scope.
    .RuleFor(u => u.Gender, f => f.PickRandom<Gender>())
    //Use a method outside scope.
    .RuleFor(u => u.CartId, f => Guid.NewGuid())
    //Compound property with context, use the first/last name properties
    .RuleFor(u => u.FullName, (f, u) => u.FirstName + " " + u.LastName)
    //And composability of a complex collection.
    .RuleFor(u => u.Orders, f => testOrders.Generate(3).ToList())
    //Optional: After all rules are applied finish with the following action
    .FinishWith((f, u) =>
        {
            Console.WriteLine("User Created! Id={0}", u.Id);
        });

var user = testUsers.Generate();
Console.WriteLine(user.DumpAsJson());

/* OUTPUT:
User Created! Id=0
 *
{
  "Id": 0,
  "FirstName": "Audrey",
  "LastName": "Spencer",
  "FullName": "Audrey Spencer",
  "UserName": "Audrey_Spencer72",
  "Email": "Audrey82@gmail.com",
  "Avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/itstotallyamy/128.jpg",
  "CartId": "863f9462-5b88-471f-b833-991d68db8c93",
  "SSN": "923-88-4231",
  "Gender": 0,
  "Orders": [
    {
      "OrderId": 0,
      "Item": "orange",
      "Quantity": 8
    },
    {
      "OrderId": 1,
      "Item": "banana",
      "Quantity": 2
    },
    {
      "OrderId": 2,
      "Item": "kiwi",
      "Quantity": 9
    }
  ]
} */
Click here for F# and VB.NET examples!

The Great C# Example

public enum Gender
{
    Male,
    Female
}

//Set the randomzier seed if you wish to generate repeatable data sets.
Randomizer.Seed = new Random(8675309);

var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" };

var orderIds = 0;
var testOrders = new Faker<Order>()
    //Ensure all properties have rules. By default, StrictMode is false
    //Set a global policy by using Faker.DefaultStrictMode
    .StrictMode(true)
    //OrderId is deterministic
    .RuleFor(o => o.OrderId, f => orderIds++)
    //Pick some fruit from a basket
    .RuleFor(o => o.Item, f => f.PickRandom(fruit))
    //A random quantity from 1 to 10
    .RuleFor(o => o.Quantity, f => f.Random.Number(1, 10));


var userIds = 0;
var testUsers = new Faker<User>()
    //Optional: Call for objects that have complex initialization
    .CustomInstantiator(f => new User(userIds++, f.Random.Replace("###-##-####")))

    //Basic rules using built-in generators
    .RuleFor(u => u.FirstName, f => f.Name.FirstName())
    .RuleFor(u => u.LastName, f => f.Name.LastName())
    .RuleFor(u => u.Avatar, f => f.Internet.Avatar())
    .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName))
    .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName))
    .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}")
    .RuleFor(u => u.SomeGuid, Guid.NewGuid)

    //Use an enum outside scope.
    .RuleFor(u => u.Gender, f => f.PickRandom<Gender>())
    //Use a method outside scope.
    .RuleFor(u => u.CartId, f => Guid.NewGuid())
    //Compound property with context, use the first/last name properties
    .RuleFor(u => u.FullName, (f, u) => u.FirstName + " " + u.LastName)
    //And composability of a complex collection.
    .RuleFor(u => u.Orders, f => testOrders.Generate(3).ToList())
    //Optional: After all rules are applied finish with the following action
    .FinishWith((f, u) =>
        {
            Console.WriteLine("User Created! Id={0}", u.Id);
        });

var user = testUsers.Generate();
Console.WriteLine(user.DumpAsJson());

/* OUTPUT:
User Created! Id=0
 *
{
  "Id": 0,
  "FirstName": "Audrey",
  "LastName": "Spencer",
  "FullName": "Audrey Spencer",
  "UserName": "Audrey_Spencer72",
  "Email": "Audrey82@gmail.com",
  "Avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/itstotallyamy/128.jpg",
  "CartId": "863f9462-5b88-471f-b833-991d68db8c93",
  "SSN": "923-88-4231",
  "Gender": 0,
  "Orders": [
    {
      "OrderId": 0,
      "Item": "orange",
      "Quantity": 8
    },
    {
      "OrderId": 1,
      "Item": "banana",
      "Quantity": 2
    },
    {
      "OrderId": 2,
      "Item": "kiwi",
      "Quantity": 9
    }
  ]
} */
Click here for F# and VB.NET examples!

Release Notes

## v20.0.1
* Added `Faker<T>.Clone()`: Clones internal state of a `Faker<T>` and allows for complex faking scenarios and rule combinations.
* Added `Faker<T>.UseSeed(n)`: Allows you to specify a localized seed value on a `Faker<T>` instead of a global static `Randomizer.Seed`.
* Stronger `Seed` determinism for multi-threaded scenarios.

## v19.0.2
* Fixed #99: Possible threading issue that can cause `System.ArgumentException`.

## v19.0.1
* Using new BSON binary data format for locales.
* Removed dependency on Newtonsoft.Json!
* Locale Updates -
* `fr`: new street address prefixes.
* `fa`: new street addresses.
* `pl`: removed 2008 value from city.
* `en`: new gender first names
* New Dutch (Belgium) `nl_BE` locale.
* New Romanian `ro` locale.
* Added `f.Finance.RoutingNumber` - Generates an ABA routing number with valid check digit.
* Added `Faker.GenerateForever` that returns `IEnumerable<T>` with unlimited generated items when iterated over.
* Added United Kingdom extension method to generate bank ShortCodes on `f.Finance.ShortCode()`.
* Re-ordered adjective and buzz in the `f.Company.Bs` for a correct gramatics.
* Added `f.Address.Direction`. Generates cardinal or ordinal directions.
* Added `f.Address.CardinalDirection`. Generates "North", "South", etc.
* Added `f.Address.OrdinalDirection`. Generates "Northeast", "Southwest", etc.

## v18.0.2
* Issue 86: Removed diacritic mark/accents (á, í, ó, ú, etc) from generated email addresses and user names.
* Added `string.RemoveDiacritics` helper method.

## v18.0.1
* Fixed bug in Finland's `f.Person.Henkilötunnus` personal identity code generator that sometimes produced 11 characters.
* Added `f.Finance.Ethereum`. Generate an Ethereum address.
* Added `f.Finance.CreditCardCvv`. Generate a random credit card CVV number.
* Improved `f.Finance.CreditCardNumber`. Generate a random credit card number.
* Added `f.Random.Hexadecimal`. Generates a random hexadecimal string.
* Added `f.System.DirectoryPath`. Generates a random directory path.
* Added `f.System.FilePath`. Generates a random file path.
* Added `f.Date.Soon`. Generates a date and time that will happen soon.
* Added `f.Random.ArrayElements`. Gets a random subset of an array.
* Added `f.Random.ListItems`. Gets a random subset of a list.
* Added `f.Company.Cnpj` extension method for Brazil. Generates Brazilian company document.
* Improved `f.PhoneNumbers`. More realistic US phone numbers.
* Improved `f.Address.Latitude/Longitude` with min and max parameters.
* Minimum for `f.Commerce.Price` is now $1.00 (not zero).
* Reduced assembly size by removing redundant locale data.
* Locale updates:
* `en_AU` - Update Australian postcode ranges.
* `en_IND` - Indian postcodes are always numeric.
* `ru` - Word corrections.


Full History Here: https://github.com/bchavez/Bogus/blob/master/HISTORY.md

  • .NETFramework 4.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

Showing the top 10 GitHub repositories that depend on Bogus:

Repository Stars
graphql-dotnet/graphql-dotnet
GraphQL for .NET
umbraco/Umbraco-CMS
The simple, flexible and friendly ASP.NET CMS used by more than 500.000 websites
elastic/elasticsearch-net
Elasticsearch.Net & NEST
skoruba/IdentityServer4.Admin
The administration for the IdentityServer4 and Asp.Net Core Identity
Windows-XAML/Template10
Making Windows 10 apps great again
OfficeDev/TrainingContent
Training Content used for developer.microsoft.com/office
riganti/dotvvm
Open source MVVM framework for Web Apps
json-api-dotnet/JsonApiDotNetCore
JSONAPI Framework for ASP.Net Core
AArnott/CodeGeneration.Roslyn
Assists in performing Roslyn-based code generation during a build.
bchavez/RethinkDb.Driver
:headphones: A NoSQL C#/.NET RethinkDB database driver with 100% ReQL API coverage.

Read more about the GitHub Usage information on our documentation.

Version History

Version Downloads Last updated
29.0.1 1,253 2/10/2020
28.4.4 104,576 12/10/2019
28.4.3 24,043 12/4/2019
28.4.2 5,336 11/30/2019
28.4.1 176,202 10/15/2019
28.3.2 34,188 10/4/2019
28.3.1 65,953 9/21/2019
28.2.1 88,694 9/10/2019
28.1.1 1,835 9/10/2019
28.0.3 36,327 8/28/2019
28.0.2 262,727 7/7/2019
28.0.1 15,684 7/2/2019
27.0.1 342,505 5/2/2019
26.0.2 185,848 3/22/2019
26.0.1 186,302 2/26/2019
25.0.4 201,442 1/18/2019
25.0.3 72,823 1/6/2019
25.0.2 119,468 12/11/2018
25.0.1 69,554 11/27/2018
24.3.1 106,685 11/3/2018
24.3.0 259,566 10/2/2018
24.2.0 21,372 9/27/2018
23.0.2 75,434 8/13/2018
22.3.2 104,779 7/18/2018
22.3.1 73,945 7/5/2018
22.2.1 16,543 6/29/2018
22.1.4 10,052 6/26/2018
22.1.3 34,997 6/14/2018
22.1.2 117,740 5/29/2018
22.1.1 10,261 5/21/2018
22.0.9 2,370 5/17/2018
22.0.8 208,601 4/10/2018
22.0.7 28,666 4/1/2018
22.0.6 4,613 3/29/2018
22.0.5 88,403 3/3/2018
22.0.3 11,340 2/27/2018
22.0.2 98,153 1/6/2018
22.0.1 38,183 12/23/2017
21.0.5 5,452 12/16/2017
21.0.4 7,475 12/13/2017
21.0.2 8,077 12/8/2017
20.0.2 40,676 11/6/2017
20.0.1 4,235 11/5/2017
19.0.2 21,208 11/1/2017
18.0.2 89,198 9/14/2017
18.0.1 9,196 9/13/2017
17.0.1 30,643 8/25/2017
16.0.3 10,228 8/24/2017
16.0.2 1,687 8/23/2017
15.0.7 5,013 8/21/2017
15.0.6 14,189 8/3/2017
15.0.5 4,844 7/28/2017
15.0.3 119,401 5/7/2017
15.0.1 29,402 4/11/2017
12.0.1 8,218 3/27/2017
11.0.5 8,157 3/20/2017
11.0.4 21,501 3/15/2017
11.0.3 2,364 3/13/2017
11.0.2 13,646 2/23/2017
11.0.1 1,473 2/21/2017
10.0.1 1,286 2/18/2017
9.0.2 18,616 1/19/2017
9.0.1 900 1/18/2017
8.0.4 1,056 1/17/2017
8.0.3 27,749 12/20/2016
8.0.2 6,541 12/7/2016
8.0.1 8,879 11/25/2016
8.0.1-beta-1 18,899 10/22/2016
7.1.7 44,219 10/11/2016
7.1.6 32,236 8/8/2016
7.1.5 1,171 7/27/2016
7.1.4 4,073 7/7/2016
7.1.3 4,489 6/28/2016
7.1.3-beta-1 679 5/20/2016
7.1.2 7,671 5/16/2016
7.1.2-beta-1 636 5/16/2016
7.1.1 750 5/15/2016
7.1.1-beta-1 667 5/15/2016
6.1.1 5,887 3/30/2016
6.1.1-beta-1 869 3/29/2016
5.1.1-beta-3 683 3/23/2016
5.1.1-beta-2 646 3/22/2016
5.1.1-beta-1 646 3/21/2016
5.0.1 2,558 2/25/2016
5.0.1-beta-2 679 2/25/2016
4.0.1 841 2/16/2016
4.0.1-beta-1 665 2/16/2016
3.0.6 2,510 1/21/2016
3.0.6-beta-1 626 1/21/2016
3.0.5 4,902 1/21/2016
3.0.5-beta-4 653 1/20/2016
3.0.5-beta-3 690 1/18/2016
3.0.5-beta-2 1,759 1/12/2016
3.0.4 1,653 12/10/2015
3.0.3 722 12/9/2015
3.0.2 845 11/24/2015
3.0.1 976 10/22/2015
3.0.0.3 1,423 7/21/2015
3.0.0.2 2,112 7/12/2015
3.0.0.1 6,206 7/12/2015
2.1.5.2 1,096 6/22/2015
2.1.5.1 779 6/11/2015
2.1.4.2 736 6/11/2015
2.1.4.1 783 6/10/2015
2.1.4 1,374 6/9/2015
Show less