Soenneker.Utils.AutoBogus
4.0.885
Prefix Reserved
dotnet add package Soenneker.Utils.AutoBogus --version 4.0.885
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 4.0.885
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="4.0.885" />
<PackageVersion Include="Soenneker.Utils.AutoBogus" Version="4.0.885" />
<PackageReference Include="Soenneker.Utils.AutoBogus" />
paket add Soenneker.Utils.AutoBogus --version 4.0.885
#r "nuget: Soenneker.Utils.AutoBogus, 4.0.885"
#:package Soenneker.Utils.AutoBogus@4.0.885
#addin nuget:?package=Soenneker.Utils.AutoBogus&version=4.0.885
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=4.0.885
Soenneker.Utils.AutoBogus
The .NET Autogenerator
This project is an automatic creator and populator for the fake data generator Bogus. It's a replacement for the abandoned AutoBogus library.
The goals:
- Be fast
- Support the latest types in .NET
It uses the fastest .NET Reflection cache: soenneker.reflection.cache. Bogus updates are automatically integrated.
.NET 8+ is supported.
Installation
dotnet add package Soenneker.Utils.AutoBogus
Usage
- Create an
AutoFakerinstance:
var optionalConfig = new AutoFakerConfig();
var autoFaker = new AutoFaker(optionalConfig);
- Call
Generate<>()on any type you want:
var randomWord = autoFaker.Generate<string>();
var dictionary = autoFaker.Generate<Dictionary<int, string>>();
var order = autoFaker.Generate<Order>();
- It's also possible to generate types via an argument:
var randomWord = autoFaker.Generate(typeof(string));
- Set a faker, configuration, rules, etc:
autoFaker.Config.Faker = new Faker("de");
autoFaker.Config.RepeatCount = 3;
...
AutoFakerOverride
This is the recommended way for controlling type customization:
public class OrderOverride : AutoFakerOverride<Order>
{
public override void Generate(AutoFakerOverrideContext context)
{
var target = (context.Instance as Order)!;
target.Id = 123;
// Faker is available
target.Name = context.Faker.Random.Word();
// AutoFaker is also available
target.Customer = context.AutoFaker.Generate<Customer>();
}
}
Then just add AutoFakerOverride to the AutoFaker.Config instance:
autoFaker.Config.Overrides = new List<AutoFakerGeneratorOverride>();
autoFaker.Config.Overrides.Add(new OrderOverride());
AutoFaker<T>
This inherits from Bogus.Faker, and can be used to designate rules specific to the AutoFaker instance.
var autoFaker = new AutoFaker<Order>();
autoFaker.RuleFor(x => x.Id, f => f.Random.Number());
var order = autoFaker.Generate();
Interfaces/Abstracts
The base library does not generate interfaces or abstract objects, but these enable you to generate mocks of them:
- soenneker.utils.autobogus.moq
- soenneker.utils.autobogus.nsubstitute
- soenneker.utils.autobogus.fakeiteasy
Tips
- ?? Instantiating an
AutoFakertakes a non-trivial amount of time because of BogusFakerinitialization (almost 1ms). It's recommended that a single instance be used if possible. AutoFaker.GenerateStatic<T>()is also available, but should be avoided (as it creates a newAutoFaker/Fakeron each call).
Notes
- Some patterns that existed in AutoBogus have been removed due to the complexity and performance impact.
- This is a work in progress. Contribution is welcomed.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. |
-
net10.0
- Bogus (>= 35.6.5)
- Soenneker.Extensions.FieldInfo (>= 4.0.72)
- Soenneker.Extensions.MemberInfo (>= 4.0.68)
- Soenneker.Reflection.Cache (>= 4.0.619)
-
net8.0
- Bogus (>= 35.6.5)
- Soenneker.Extensions.FieldInfo (>= 4.0.72)
- Soenneker.Extensions.MemberInfo (>= 4.0.68)
- Soenneker.Reflection.Cache (>= 4.0.619)
- System.Collections.Immutable (>= 10.0.5)
-
net9.0
- Bogus (>= 35.6.5)
- Soenneker.Extensions.FieldInfo (>= 4.0.72)
- Soenneker.Extensions.MemberInfo (>= 4.0.68)
- Soenneker.Reflection.Cache (>= 4.0.619)
- System.Collections.Immutable (>= 10.0.5)
NuGet packages (21)
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.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 |
|
|
Soenneker.AutoFaker.Overrides.MinMax
An AutoFaker (AutoBogus) override for the DTO MinMax |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.885 | 4,005 | 3/15/2026 |
| 4.0.884 | 2,871 | 3/15/2026 |
| 4.0.883 | 1,244 | 3/14/2026 |
| 4.0.882 | 99 | 3/14/2026 |
| 4.0.881 | 146 | 3/14/2026 |
| 4.0.880 | 97 | 3/14/2026 |
| 4.0.879 | 120 | 3/14/2026 |
| 4.0.874 | 42,677 | 3/11/2026 |
| 4.0.873 | 713 | 3/11/2026 |
| 4.0.872 | 3,696 | 3/11/2026 |
| 4.0.870 | 4,603 | 3/10/2026 |
| 4.0.869 | 650 | 3/10/2026 |
| 4.0.868 | 388 | 3/10/2026 |
| 4.0.867 | 17,330 | 3/10/2026 |
| 4.0.866 | 866 | 3/10/2026 |
| 4.0.865 | 220 | 3/10/2026 |
| 4.0.859 | 5,232 | 3/9/2026 |
| 4.0.858 | 8,388 | 3/9/2026 |
| 4.0.857 | 34,545 | 3/5/2026 |
| 4.0.856 | 5,140 | 3/4/2026 |
Update dependency Soenneker.Reflection.Cache to 4.0.619 (#1010)