Soenneker.Utils.AutoBogus 4.0.939

Prefix Reserved
dotnet add package Soenneker.Utils.AutoBogus --version 4.0.939
                    
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 4.0.939
                    
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="4.0.939" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.AutoBogus" Version="4.0.939" />
                    
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 4.0.939
                    
#r "nuget: Soenneker.Utils.AutoBogus, 4.0.939"
                    
#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@4.0.939
                    
#: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=4.0.939
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=4.0.939
                    
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (22)

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
4.0.939 7 8/31/2026
4.0.938 3,684 8/31/2026
4.0.937 3,643 8/30/2026
4.0.936 60 8/30/2026
4.0.935 1,405 8/30/2026
4.0.934 1,055 8/30/2026
4.0.933 862 8/30/2026
4.0.932 170 8/29/2026
4.0.931 397 8/29/2026
4.0.930 72 8/29/2026
4.0.929 46,884 8/27/2026
4.0.928 67 8/27/2026
4.0.927 6,276 8/26/2026
4.0.926 46,010 8/13/2026
4.0.925 1,471 8/12/2026
4.0.924 87,256 7/28/2026
4.0.923 663 7/28/2026
4.0.922 15,994 7/28/2026
4.0.921 912 7/28/2026
4.0.920 305 7/28/2026
Loading failed

Updated NuGet packages