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
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="4.0.939" />
<PackageVersion Include="Soenneker.Utils.AutoBogus" Version="4.0.939" />
<PackageReference Include="Soenneker.Utils.AutoBogus" />
paket add Soenneker.Utils.AutoBogus --version 4.0.939
#r "nuget: Soenneker.Utils.AutoBogus, 4.0.939"
#:package Soenneker.Utils.AutoBogus@4.0.939
#addin nuget:?package=Soenneker.Utils.AutoBogus&version=4.0.939
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=4.0.939
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:
- soenneker.utils.autobogus.moq
- soenneker.utils.autobogus.nsubstitute
- soenneker.utils.autobogus.fakeiteasy
Generation boundaries
- Set
TreeDepth,RecursiveDepth,SkipTypes, orSkipPathswhen 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 retainedAutoFakerfor 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 | Versions 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. |
-
net10.0
- Bogus (>= 35.6.5)
- Soenneker.Extensions.FieldInfo (>= 4.0.80)
- Soenneker.Extensions.MemberInfo (>= 4.0.75)
- Soenneker.Reflection.Cache (>= 4.0.672)
-
net9.0
- Bogus (>= 35.6.5)
- Soenneker.Extensions.FieldInfo (>= 4.0.80)
- Soenneker.Extensions.MemberInfo (>= 4.0.75)
- Soenneker.Reflection.Cache (>= 4.0.672)
- System.Collections.Immutable (>= 10.0.11)
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 |
Updated NuGet packages