Soenneker.Utils.AutoBogus
2.1.204
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Utils.AutoBogus --version 2.1.204
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 2.1.204
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="2.1.204" />
paket add Soenneker.Utils.AutoBogus --version 2.1.204
#r "nuget: Soenneker.Utils.AutoBogus, 2.1.204"
// Install Soenneker.Utils.AutoBogus as a Cake Addin
#addin nuget:?package=Soenneker.Utils.AutoBogus&version=2.1.204
// Install Soenneker.Utils.AutoBogus as a Cake Tool
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=2.1.204
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 6+ is supported.
Installation
dotnet add package Soenneker.Utils.AutoBogus
Usage
- Create an
AutoFaker
instance:
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();
Tips
- ⚠️ Instantiating an
AutoFaker
takes a non-trivial amount of time because of BogusFaker
initialization (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
/Faker
on 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 | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- Bogus (>= 35.5.1)
- Soenneker.Extensions.FieldInfo (>= 2.1.9)
- Soenneker.Extensions.MemberInfo (>= 2.1.9)
- Soenneker.Reflection.Cache (>= 2.1.115)
- System.Collections.Immutable (>= 8.0.0)
-
net7.0
- Bogus (>= 35.5.1)
- Soenneker.Extensions.FieldInfo (>= 2.1.9)
- Soenneker.Extensions.MemberInfo (>= 2.1.9)
- Soenneker.Reflection.Cache (>= 2.1.115)
- System.Collections.Immutable (>= 8.0.0)
-
net8.0
- Bogus (>= 35.5.1)
- Soenneker.Extensions.FieldInfo (>= 2.1.9)
- Soenneker.Extensions.MemberInfo (>= 2.1.9)
- Soenneker.Reflection.Cache (>= 2.1.115)
- System.Collections.Immutable (>= 8.0.0)
NuGet packages (3)
Showing the top 3 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 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.236 | 1,539 | 6/15/2024 |
2.1.235 | 1,482 | 6/15/2024 |
2.1.234 | 6,272 | 6/1/2024 |
2.1.233 | 286 | 6/1/2024 |
2.1.232 | 69 | 6/1/2024 |
2.1.231 | 2,501 | 6/1/2024 |
2.1.230 | 2,914 | 5/31/2024 |
2.1.229 | 2,425 | 5/29/2024 |
2.1.228 | 68 | 5/29/2024 |
2.1.227 | 2,717 | 5/28/2024 |
2.1.226 | 57 | 5/28/2024 |
2.1.225 | 1,955 | 5/27/2024 |
2.1.224 | 67 | 5/27/2024 |
2.1.223 | 3,832 | 5/26/2024 |
2.1.221 | 2,508 | 5/26/2024 |
2.1.220 | 65 | 5/26/2024 |
2.1.219 | 1,722 | 5/25/2024 |
2.1.218 | 61 | 5/25/2024 |
2.1.215 | 846 | 5/25/2024 |
2.1.214 | 68 | 5/25/2024 |
2.1.213 | 2,657 | 5/25/2024 |
2.1.212 | 64 | 5/25/2024 |
2.1.211 | 64 | 5/25/2024 |
2.1.210 | 92 | 5/25/2024 |
2.1.208 | 6,965 | 5/23/2024 |
2.1.207 | 132 | 5/23/2024 |
2.1.206 | 69 | 5/23/2024 |
2.1.205 | 1,246 | 5/23/2024 |
2.1.204 | 71 | 5/23/2024 |
2.1.203 | 1,289 | 5/22/2024 |
2.1.202 | 77 | 5/22/2024 |
2.1.201 | 69 | 5/22/2024 |
2.1.200 | 68 | 5/22/2024 |
2.1.199 | 2,357 | 5/22/2024 |
2.1.197 | 563 | 5/22/2024 |
2.1.196 | 4,527 | 5/17/2024 |
2.1.195 | 1,752 | 5/17/2024 |
2.1.194 | 5,453 | 5/14/2024 |
2.1.193 | 78 | 5/14/2024 |
2.1.192 | 3,156 | 5/12/2024 |
2.1.191 | 4,735 | 4/29/2024 |
2.1.190 | 96 | 4/29/2024 |
2.1.189 | 87 | 4/29/2024 |
2.1.188 | 456 | 4/29/2024 |
2.1.187 | 75 | 4/29/2024 |
2.1.186 | 3,062 | 4/28/2024 |
2.1.185 | 88 | 4/28/2024 |
2.1.184 | 2,059 | 4/28/2024 |
2.1.183 | 805 | 4/28/2024 |
2.1.182 | 2,283 | 4/28/2024 |
2.1.181 | 74 | 4/28/2024 |
2.1.180 | 76 | 4/28/2024 |
2.1.179 | 1,537 | 4/28/2024 |
2.1.178 | 89 | 4/27/2024 |
2.1.177 | 74 | 4/27/2024 |
2.1.176 | 5,840 | 4/19/2024 |
2.1.175 | 2,085 | 4/18/2024 |
2.1.174 | 4,042 | 4/12/2024 |
2.1.173 | 1,653 | 4/12/2024 |
2.1.172 | 530 | 4/12/2024 |
2.1.171 | 394 | 4/12/2024 |
2.1.170 | 73 | 4/12/2024 |
2.1.169 | 67 | 4/12/2024 |
2.1.168 | 1,997 | 4/12/2024 |
2.1.167 | 77 | 4/12/2024 |
2.1.166 | 71 | 4/12/2024 |
2.1.165 | 72 | 4/12/2024 |
2.1.164 | 71 | 4/12/2024 |
2.1.163 | 5,780 | 4/9/2024 |
2.1.162 | 3,172 | 4/1/2024 |
2.1.161 | 83 | 4/1/2024 |
2.1.160 | 5,599 | 3/25/2024 |
2.1.159 | 72 | 3/25/2024 |
2.1.158 | 2,260 | 3/20/2024 |
2.1.157 | 2,071 | 3/19/2024 |
2.1.156 | 1,177 | 3/19/2024 |
2.1.155 | 3,281 | 3/15/2024 |
2.1.154 | 2,063 | 3/13/2024 |
2.1.153 | 842 | 3/13/2024 |
2.1.152 | 341 | 3/13/2024 |
2.1.151 | 90 | 3/13/2024 |
2.1.150 | 81 | 3/13/2024 |
2.1.149 | 89 | 3/13/2024 |
2.1.148 | 100 | 3/13/2024 |
2.1.147 | 2,655 | 3/12/2024 |
2.1.146 | 3,383 | 3/11/2024 |
2.1.145 | 85 | 3/11/2024 |
2.1.144 | 1,210 | 3/11/2024 |
2.1.143 | 1,693 | 3/9/2024 |
2.1.142 | 1,903 | 3/8/2024 |
2.1.141 | 1,241 | 3/8/2024 |
2.1.140 | 2,787 | 3/6/2024 |
2.1.139 | 88 | 3/6/2024 |
2.1.138 | 1,924 | 3/4/2024 |
2.1.137 | 77 | 3/4/2024 |
2.1.136 | 2,651 | 3/2/2024 |
2.1.135 | 1,166 | 3/2/2024 |
2.1.134 | 81 | 3/2/2024 |
2.1.133 | 1,474 | 3/2/2024 |
2.1.132 | 766 | 3/2/2024 |
2.1.131 | 1,733 | 2/29/2024 |
2.1.130 | 1,471 | 2/29/2024 |
2.1.129 | 1,738 | 2/26/2024 |
2.1.128 | 1,542 | 2/25/2024 |
2.1.127 | 77 | 2/25/2024 |
2.1.126 | 2,115 | 2/23/2024 |
2.1.125 | 1,618 | 2/22/2024 |
2.1.124 | 1,063 | 2/21/2024 |
2.1.123 | 1,379 | 2/21/2024 |
2.1.122 | 312 | 2/21/2024 |
2.1.121 | 297 | 2/21/2024 |
2.1.120 | 82 | 2/21/2024 |
2.1.119 | 1,286 | 2/21/2024 |
2.1.118 | 84 | 2/21/2024 |
2.1.117 | 82 | 2/21/2024 |
2.1.116 | 618 | 2/21/2024 |
2.1.115 | 981 | 2/21/2024 |
2.1.114 | 84 | 2/21/2024 |
2.1.113 | 87 | 2/21/2024 |
2.1.112 | 82 | 2/21/2024 |
2.1.111 | 777 | 2/21/2024 |
2.1.110 | 82 | 2/21/2024 |
2.1.109 | 2,587 | 2/20/2024 |
2.1.108 | 79 | 2/20/2024 |
2.1.107 | 2,574 | 2/19/2024 |
2.1.106 | 250 | 2/19/2024 |
2.1.104 | 2,814 | 2/17/2024 |
2.1.103 | 1,381 | 2/16/2024 |
2.1.102 | 72 | 2/16/2024 |
2.1.101 | 697 | 2/16/2024 |
2.1.100 | 1,148 | 2/16/2024 |
2.1.99 | 76 | 2/16/2024 |
2.1.98 | 71 | 2/16/2024 |
2.1.97 | 684 | 2/16/2024 |
2.1.96 | 71 | 2/16/2024 |
2.1.95 | 70 | 2/16/2024 |
2.1.94 | 1,394 | 2/16/2024 |
2.1.93 | 73 | 2/16/2024 |
2.1.92 | 2,059 | 2/13/2024 |
2.1.91 | 2,051 | 2/13/2024 |
2.1.90 | 774 | 2/13/2024 |
2.1.89 | 80 | 2/13/2024 |
2.1.88 | 643 | 2/13/2024 |
2.1.87 | 2,045 | 2/11/2024 |
2.1.86 | 782 | 2/11/2024 |
2.1.85 | 92 | 2/11/2024 |
2.1.84 | 1,470 | 2/11/2024 |
2.1.83 | 85 | 2/11/2024 |
2.1.82 | 1,087 | 2/11/2024 |
2.1.81 | 86 | 2/11/2024 |
2.1.80 | 89 | 2/11/2024 |
2.1.79 | 87 | 2/11/2024 |
2.1.78 | 84 | 2/11/2024 |
2.1.76 | 2,379 | 2/9/2024 |
2.1.75 | 84 | 2/9/2024 |
2.1.74 | 1,466 | 2/9/2024 |
2.1.73 | 88 | 2/9/2024 |
2.1.72 | 945 | 2/8/2024 |
2.1.71 | 84 | 2/8/2024 |
2.1.70 | 82 | 2/8/2024 |
2.1.69 | 442 | 2/8/2024 |
2.1.68 | 1,102 | 2/8/2024 |
2.1.67 | 88 | 2/8/2024 |
2.1.66 | 83 | 2/8/2024 |
2.1.65 | 1,100 | 2/8/2024 |
2.1.64 | 82 | 2/8/2024 |
2.1.63 | 771 | 2/8/2024 |
2.1.62 | 2,078 | 2/7/2024 |
2.1.61 | 1,054 | 2/6/2024 |
2.1.60 | 90 | 2/6/2024 |
2.1.59 | 1,351 | 2/6/2024 |
2.1.58 | 93 | 2/6/2024 |
2.1.57 | 851 | 2/6/2024 |
2.1.54 | 87 | 2/5/2024 |
2.1.53 | 85 | 2/5/2024 |
2.1.52 | 2,821 | 2/4/2024 |
2.1.51 | 1,258 | 2/2/2024 |
2.1.49 | 77 | 2/1/2024 |
2.1.48 | 1,662 | 1/31/2024 |
2.1.47 | 1,334 | 1/29/2024 |
2.1.46 | 1,329 | 1/29/2024 |
2.1.45 | 620 | 1/29/2024 |
2.1.44 | 827 | 1/28/2024 |
2.1.43 | 77 | 1/28/2024 |
2.1.42 | 854 | 1/28/2024 |
2.1.41 | 75 | 1/28/2024 |
2.1.40 | 79 | 1/28/2024 |
2.1.39 | 701 | 1/28/2024 |
2.1.38 | 909 | 1/28/2024 |
2.1.37 | 683 | 1/28/2024 |
2.1.36 | 79 | 1/28/2024 |
2.1.35 | 75 | 1/28/2024 |
2.1.34 | 78 | 1/28/2024 |
2.1.33 | 900 | 1/27/2024 |
2.1.31 | 294 | 1/27/2024 |
2.1.30 | 1,021 | 1/27/2024 |
2.1.29 | 938 | 1/27/2024 |
2.1.27 | 505 | 1/27/2024 |
2.1.26 | 995 | 1/27/2024 |
2.1.25 | 688 | 1/26/2024 |
2.1.24 | 73 | 1/26/2024 |
2.1.23 | 76 | 1/26/2024 |
2.1.22 | 77 | 1/26/2024 |
2.1.21 | 661 | 1/26/2024 |
2.1.20 | 648 | 1/26/2024 |
2.1.19 | 699 | 1/26/2024 |
2.1.18 | 695 | 1/26/2024 |
2.1.17 | 778 | 1/26/2024 |
2.1.16 | 782 | 1/26/2024 |
2.1.15 | 296 | 1/25/2024 |
2.1.14 | 845 | 1/25/2024 |
2.1.13 | 843 | 1/25/2024 |
2.1.12 | 79 | 1/25/2024 |
2.1.11 | 757 | 1/25/2024 |
2.1.10 | 713 | 1/25/2024 |
2.1.9 | 772 | 1/25/2024 |
2.1.7 | 5,138 | 1/15/2024 |
2.1.6 | 1,142 | 1/14/2024 |
2.1.5 | 1,418 | 1/14/2024 |
2.1.4 | 1,342 | 1/13/2024 |
2.1.3 | 1,367 | 1/5/2024 |
2.1.2 | 112 | 1/2/2024 |
2.1.1 | 119 | 12/29/2023 |