Soenneker.Utils.AutoBogus 11.0.996

Prefix Reserved
dotnet add package Soenneker.Utils.AutoBogus --version 11.0.996
                    
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 11.0.996
                    
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.996" />
                    
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.996" />
                    
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.996
                    
#r "nuget: Soenneker.Utils.AutoBogus, 11.0.996"
                    
#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.996
                    
#: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.996
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=11.0.996
                    
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.996 21,654 10/26/2026
11.0.995 211 10/26/2026
11.0.994 2,858 10/26/2026
11.0.993 150 10/26/2026
11.0.992 337 10/26/2026
4.0.991 7,740 10/26/2026
4.0.990 284 10/25/2026
4.0.989 44,778 10/15/2026
4.0.988 148 10/15/2026
4.0.987 2,465 10/14/2026
4.0.986 2,570 10/14/2026
4.0.985 5,223 10/14/2026
4.0.984 5,476 10/14/2026
4.0.982 1,162 10/14/2026
4.0.975 4,476 10/13/2026
4.0.974 1,097 10/13/2026
4.0.971 36,149 10/11/2026
4.0.970 373 10/11/2026
4.0.969 1,109 10/11/2026
4.0.968 61,914 10/6/2026
Loading failed

Updated Soenneker.Reflection.Cache to 11.0.745