Soenneker.Utils.AutoBogus 11.0.992

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Utils.AutoBogus --version 11.0.992
                    
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 11.0.992
                    
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="Soenneker.Utils.AutoBogus" Version="11.0.992" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.AutoBogus" Version="11.0.992" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.AutoBogus" />
                    
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 Soenneker.Utils.AutoBogus --version 11.0.992
                    
#r "nuget: Soenneker.Utils.AutoBogus, 11.0.992"
                    
#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 Soenneker.Utils.AutoBogus@11.0.992
                    
#: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=Soenneker.Utils.AutoBogus&version=11.0.992
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=11.0.992
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Utils.AutoBogus

Automatic object creation and population backed by Bogus.

It generates primitives, collections, dictionaries, and populated object graphs without requiring a rule for every member. Use AutoFaker<T> when you also need normal Bogus rules for a particular model.

Installation

dotnet add package Soenneker.Utils.AutoBogus

Usage

var faker = new AutoFaker(new AutoFakerConfig
{
    RepeatCount = 3,
    RecursiveDepth = 1
});

string randomWord = faker.Generate<string>();
Dictionary<int, string> dictionary = faker.Generate<Dictionary<int, string>>();
Order order = faker.Generate<Order>();
List<Order> orders = faker.Generate<Order>(10);

Reuse an AutoFaker where practical. Its reflection metadata and Bogus state are initialized lazily and then retained. To make generated values repeatable, seed that instance before generating:

faker.UseSeed(12345);

For a runtime Type, use the non-generic overload:

object value = faker.Generate(modelType);

AutoFakerOverride

Use an override when every generated instance of a type needs custom population:

public class OrderOverride : AutoFakerOverride<Order>
{
    public override void Generate(AutoFakerOverrideContext context)
    {
        var target = (Order) context.Instance!;
        target.Id = 123;
        
        // Faker is available
        target.Name = context.Faker.Random.Word();

        // AutoFaker is also available
        target.Customer = context.AutoFaker.Generate<Customer>();
     }
}

Register the override in the configuration before generating:

var config = new AutoFakerConfig
{
    Overrides = [new OrderOverride()]
};

var faker = new AutoFaker(config);

AutoFaker<T>

AutoFaker<T> inherits from Bogus.Faker<T>, so explicit Bogus rules and automatic population can be combined. Members covered by a rule are not overwritten by automatic population.

var orderFaker = new AutoFaker<Order>();
orderFaker.RuleFor(x => x.Id, f => f.Random.Int(1, 10_000));

Order order = orderFaker.Generate();

Interfaces/Abstracts

The base library does not generate interfaces or abstract objects, but these enable you to generate mocks of them:

Generation boundaries

  • Set TreeDepth, RecursiveDepth, SkipTypes, or SkipPaths when models contain cycles or members that should not be populated.
  • Interfaces and abstract classes require one of the mock-framework adapters listed above.
  • GenerateStatic<T>() creates a new faker on every call. Prefer a retained AutoFaker for repeated generation.

Benchmarks

Soenneker.Utils.AutoBogus - AutoFaker

Method Mean Error StdDev
Generate_int 79.40 ns 0.635 ns 0.563 ns
Generate_string 241.35 ns 3.553 ns 3.324 ns
Generate_complex 6,782.34 ns 43.811 ns 38.837 ns

Soenneker.Utils.AutoBogus - AutoFaker<T>

Method Mean Error StdDev
Generate_string 283.6 ns 3.28 ns 3.07 ns
Generate_complex 8,504.0 ns 76.58 ns 67.89 ns

AutoBogus

Method Mean Error StdDev
Generate_int 1.17 ms 0.033 ms 0.026 ms
Generate_complex 10.91 ms 0.181 ms 0.236 ms

Bogus

Method Mean Error StdDev
Bogus_int 19.70 ns 0.176 ns 0.165 ns
Bogus_string 171.75 ns 2.763 ns 2.585 ns
Bogus_ctor 730,669.06 ns 8,246.622 ns 7,310.416 ns
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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (24)

Showing the top 5 NuGet packages that depend on Soenneker.Utils.AutoBogus:

Package Downloads
Soenneker.Tests.Unit

A base test providing faker and autofaker capabilities

Soenneker.Fixtures.Unit

A base xUnit fixture providing injectable log output, DI mechanisms like IServiceCollection and ServiceProvider, and AutoFaker/Faker for generating test data.

Soenneker.TestHosts.Unit

A lightweight host for dependency-driven unit tests.

Soenneker.AutoFaker.Overrides.IdNamePair

An AutoFaker (AutoBogus) override for the DTO IdNamePair

Soenneker.AutoFaker.Overrides.Documents.Document

An AutoFaker (AutoBogus) override for the base Document object

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.1033 0 12/3/2026
11.0.1032 0 12/3/2026
11.0.1031 179 12/3/2026
11.0.1028 4,240 12/2/2026
11.0.1027 2,449 12/2/2026
11.0.1026 1,918 12/2/2026
11.0.1025 95 12/2/2026
11.0.1023 269 12/2/2026
11.0.1022 13,185 12/1/2026
11.0.1021 801 12/1/2026
11.0.1020 7,241 12/1/2026
11.0.1019 6,812 12/1/2026
11.0.1018 292 11/30/2026
11.0.1017 2,300 11/30/2026
11.0.1016 16,970 11/29/2026
11.0.1014 30,083 11/18/2026
11.0.1013 1,822 11/18/2026
11.0.1012 163 11/18/2026
11.0.1011 33,313 11/11/2026
11.0.992 361 10/26/2026
Loading failed

Migrate to .NET 11 and version 11