FixtureBuilder.Bogus 1.2.0

dotnet add package FixtureBuilder.Bogus --version 1.2.0
                    
NuGet\Install-Package FixtureBuilder.Bogus -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FixtureBuilder.Bogus" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FixtureBuilder.Bogus" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="FixtureBuilder.Bogus" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FixtureBuilder.Bogus --version 1.2.0
                    
#r "nuget: FixtureBuilder.Bogus, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FixtureBuilder.Bogus@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FixtureBuilder.Bogus&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=FixtureBuilder.Bogus&version=1.2.0
                    
Install as a Cake Tool

FixtureBuilder.Bogus

FixtureBuilder.Bogus is a Bogus integration for FixtureBuilder. It adds realistic fake data generation to fixture configuration, letting you use Func<Faker, T> lambdas anywhere you would normally pass a flat value.

Each call to Build() produces a fresh instance with independently generated values. Call Build(int count) to produce multiple instances in one go — each with its own unique data.

Quick Example

using FixtureBuilder;
using FixtureBuilder.Bogus;

var users = Fixture.WithBogus<User>()
    .UseCustomInstantiator(f => new User(f.Name.FirstName()))
    .WithField("_age", f => f.Random.Int(18, 65))
    .Build(3);

This produces three User instances, each with a different random name and age.

Getting Started

FixtureBuilder.Bogus is available as a NuGet package:

dotnet add package FixtureBuilder.Bogus

The entry point is the Fixture.WithBogus<T>() extension method, which returns an IBogusFixtureConstructor<T>. From there, the API mirrors FixtureBuilder's fluent interface — every configuration method has a Faker-accepting overload alongside the standard passthrough.

Construction

All of FixtureBuilder's construction methods are available, plus Faker-integrated variants:

// Standard construction (passthrough to FixtureBuilder)
Fixture.WithBogus<User>().UseAutoConstructor()
Fixture.WithBogus<User>().UseConstructor("Alice", 30)
Fixture.WithBogus<User>().CreateUninitialized()

// Faker-integrated construction
Fixture.WithBogus<User>().UseConstructor(f => [f.Name.FirstName(), f.Random.Int(18, 65)])
Fixture.WithBogus<User>().UseCustomInstantiator(f => new User(f.Name.FirstName()))

UseCustomInstantiator gives you full control over construction with access to the Faker for data generation.

Configuration

Every value-taking configuration method has a Faker overload. You can mix and match flat values with Faker lambdas freely:

var user = Fixture.WithBogus<User>()
    .UseAutoConstructor()
    .With(u => u.Email, f => f.Internet.Email())     // Faker lambda
    .With(u => u.IsActive, true)                      // Flat value
    .WithSetter(u => u.Role, f => f.PickRandom<Role>())
    .WithField("_score", f => f.Random.Double(0, 100))
    .Build();

Available Faker Overloads

  • With(expr, Func<Faker, TProp>)
  • WithSetter(expr, Func<Faker, TProp>)
  • WithField(fieldName, Func<Faker, TValue>)
  • WithField(expr, fieldName, Func<Faker, TValue>)
  • WithBackingField(expr, Func<Faker, TProp>)
  • WithBackingFieldUntyped(expr, Func<Faker, object?>)
  • Invoke(Func<Faker, Expression<Action<T>>>)
  • InvokePrivate(methodName, Func<Faker, object[]>)
  • Instantiate(expr, Func<IBogusConstructor<TProp>, TProp>)

All standard FixtureBuilder configuration methods are also available as passthroughs for values that don't need generation.

Member Instantiation

The Instantiate overload provides an IBogusConstructor<TProp> that combines FixtureBuilder's construction methods with Faker support:

var order = Fixture.WithBogus<Order>()
    .Instantiate(o => o.Customer, c => c.UseConstructor(f => [f.Name.FullName()]))
    .Instantiate(o => o.Product, c => c.UseCustomInstantiator(f => new Product(f.Commerce.ProductName(), f.Random.Decimal(1, 500))))
    .Build();

Building Multiple Instances

Build(int count) produces the specified number of instances, each with freshly generated values:

var users = Fixture.WithBogus<User>()
    .With(u => u.Name, f => f.Name.FullName())
    .With(u => u.Email, f => f.Internet.Email())
    .Build(10);

The returned collection is stable — re-enumerating it returns the same instances.

Locale and Seed

Set the locale via the WithBogus overload, and the seed via the Random property. These are available on both IBogusFixtureConstructor<T> and BogusFixtureFactory.

// German locale — single fixture
var bogus = Fixture.WithBogus<User>("de");

// German locale — factory
var factory = FixtureFactory.WithBogus("de");

// Deterministic seed for repeatable test data
bogus.Random = new Randomizer(42);

BogusFixtureFactory

BogusFixtureFactory is the Bogus-integrated counterpart to FixtureFactory. It wraps an inner FixtureFactory, adding Faker-accepting overloads to the registration methods. Create one via the FixtureFactory.WithBogus() extension method.

Basic Usage

var factory = FixtureFactory.WithBogus();
var user = factory.New<User>().UseAutoConstructor().Build();

Pre-Configured Values

All With, WithParameter, and WithPropertyOrField methods have Faker overloads alongside the standard value and func overloads:

var factory = FixtureFactory.WithBogus()
    .With<string>(f => f.Name.FirstName())
    .With<string>(f => f.Name.FirstName(), "name")
    .WithParameter<int>(f => f.Random.Int(18, 65))
    .WithPropertyOrField<string>(f => f.Internet.Email(), "Email");

var user = factory.New<User>().UseAutoConstructor().Build();

Scoped Configuration

Use WhenBuilding to scope registrations to a specific type, with full access to Faker overloads inside the builder:

var factory = FixtureFactory.WithBogus()
    .WhenBuilding<User>(b => b
        .With<string>(f => f.Name.FirstName(), "name")
        .WithParameter<int>(f => f.Random.Int(18, 65), "age"))
    .WhenBuilding<Company>(b => b
        .With<string>(f => f.Company.CompanyName(), "name"));

var user = factory.New<User>().UseAutoConstructor().Build();
var company = factory.New<Company>().UseAutoConstructor().Build();

Options

Configure options the same way as FixtureFactory:

factory.Options = new FixtureOptions { AllowPrivateConstructors = true };
factory.SetOptions(o => o.AllowPrivateConstructors = true);

Extensibility

In addition to the standard AddProvider, AddConverter, and AddTypeLink methods, BogusFixtureFactory adds AddBogusProvider for registering providers that receive a Faker instance:

factory.AddBogusProvider(myBogusProvider);

Custom Bogus providers implement IBogusCustomProvider. Standard ICustomProvider, ICustomConverter, and ICustomTypeLink registrations are also available.

MemberLens

The WithField and InvokePrivate methods support the Visual Studio extension MemberLens, providing autocomplete for field and method names.

Feedback & Issues

For bug reports, feature requests, or usage questions, please submit an issue on the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 94 5/29/2026
1.1.0 108 5/8/2026
1.0.0 91 5/1/2026