Soenneker.Utils.AutoBogus 2.1.160

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Utils.AutoBogus --version 2.1.160
NuGet\Install-Package Soenneker.Utils.AutoBogus -Version 2.1.160
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="2.1.160" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Soenneker.Utils.AutoBogus --version 2.1.160
#r "nuget: Soenneker.Utils.AutoBogus, 2.1.160"
#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.
// Install Soenneker.Utils.AutoBogus as a Cake Addin
#addin nuget:?package=Soenneker.Utils.AutoBogus&version=2.1.160

// Install Soenneker.Utils.AutoBogus as a Cake Tool
#tool nuget:?package=Soenneker.Utils.AutoBogus&version=2.1.160

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

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 are to be fast, and support the latest types in .NET. It uses the fastest .NET Reflection cache: soenneker.reflection.cache.

.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 Bogus Faker 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 new AutoFaker/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

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

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.58 ns 0.150 ns 0.133 ns
Bogus_string 172.25 ns 2.510 ns 2.347 ns
Bogus_ctor 717,799.56 ns 10,086.875 ns 9,435.269 ns
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Soenneker.Utils.AutoBogus:

Package Downloads
Soenneker.Tests.Unit The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A base test providing faker and autofaker capabilities

Soenneker.Fixtures.Unit The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A base xUnit fixture providing injectable log output, DI mechanisms like IServiceCollection and ServiceProvider, and AutoFaker/Faker for generating test data.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.186 0 4/28/2024
2.1.185 0 4/28/2024
2.1.184 3 4/28/2024
2.1.183 164 4/28/2024
2.1.182 796 4/28/2024
2.1.181 21 4/28/2024
2.1.180 22 4/28/2024
2.1.179 568 4/28/2024
2.1.178 37 4/27/2024
2.1.177 27 4/27/2024
2.1.176 5,539 4/19/2024
2.1.175 2,079 4/18/2024
2.1.174 3,868 4/12/2024
2.1.173 1,643 4/12/2024
2.1.172 526 4/12/2024
2.1.171 189 4/12/2024
2.1.170 69 4/12/2024
2.1.169 63 4/12/2024
2.1.168 1,993 4/12/2024
2.1.167 73 4/12/2024
2.1.166 67 4/12/2024
2.1.165 68 4/12/2024
2.1.164 67 4/12/2024
2.1.163 5,525 4/9/2024
2.1.162 3,134 4/1/2024
2.1.161 79 4/1/2024
2.1.160 5,443 3/25/2024
2.1.159 68 3/25/2024
2.1.158 2,252 3/20/2024
2.1.157 2,062 3/19/2024
2.1.156 1,173 3/19/2024
2.1.155 3,277 3/15/2024
2.1.154 2,059 3/13/2024
2.1.153 838 3/13/2024
2.1.152 337 3/13/2024
2.1.151 86 3/13/2024
2.1.150 77 3/13/2024
2.1.149 85 3/13/2024
2.1.148 96 3/13/2024
2.1.147 2,651 3/12/2024
2.1.146 3,379 3/11/2024
2.1.145 81 3/11/2024
2.1.144 1,206 3/11/2024
2.1.143 1,689 3/9/2024
2.1.142 1,899 3/8/2024
2.1.141 1,237 3/8/2024
2.1.140 2,783 3/6/2024
2.1.139 84 3/6/2024
2.1.138 1,920 3/4/2024
2.1.137 73 3/4/2024
2.1.136 2,647 3/2/2024
2.1.135 1,162 3/2/2024
2.1.134 77 3/2/2024
2.1.133 1,470 3/2/2024
2.1.132 762 3/2/2024
2.1.131 1,729 2/29/2024
2.1.130 1,467 2/29/2024
2.1.129 1,733 2/26/2024
2.1.128 1,538 2/25/2024
2.1.127 73 2/25/2024
2.1.126 2,112 2/23/2024
2.1.125 1,566 2/22/2024
2.1.124 1,060 2/21/2024
2.1.123 1,376 2/21/2024
2.1.122 309 2/21/2024
2.1.121 294 2/21/2024
2.1.120 79 2/21/2024
2.1.119 1,283 2/21/2024
2.1.118 81 2/21/2024
2.1.117 79 2/21/2024
2.1.116 615 2/21/2024
2.1.115 978 2/21/2024
2.1.114 81 2/21/2024
2.1.113 84 2/21/2024
2.1.112 79 2/21/2024
2.1.111 774 2/21/2024
2.1.110 79 2/21/2024
2.1.109 2,584 2/20/2024
2.1.108 76 2/20/2024
2.1.107 2,571 2/19/2024
2.1.106 247 2/19/2024
2.1.104 2,811 2/17/2024
2.1.103 1,378 2/16/2024
2.1.102 69 2/16/2024
2.1.101 694 2/16/2024
2.1.100 1,145 2/16/2024
2.1.99 73 2/16/2024
2.1.98 68 2/16/2024
2.1.97 681 2/16/2024
2.1.96 68 2/16/2024
2.1.95 67 2/16/2024
2.1.94 1,391 2/16/2024
2.1.93 68 2/16/2024
2.1.92 2,054 2/13/2024
2.1.91 2,036 2/13/2024
2.1.90 769 2/13/2024
2.1.89 75 2/13/2024
2.1.88 638 2/13/2024
2.1.87 2,040 2/11/2024
2.1.86 779 2/11/2024
2.1.85 90 2/11/2024
2.1.84 1,467 2/11/2024
2.1.83 82 2/11/2024
2.1.82 1,084 2/11/2024
2.1.81 83 2/11/2024
2.1.80 86 2/11/2024
2.1.79 84 2/11/2024
2.1.78 81 2/11/2024
2.1.76 2,376 2/9/2024
2.1.75 81 2/9/2024
2.1.74 1,463 2/9/2024
2.1.73 85 2/9/2024
2.1.72 940 2/8/2024
2.1.71 81 2/8/2024
2.1.70 78 2/8/2024
2.1.69 439 2/8/2024
2.1.68 1,098 2/8/2024
2.1.67 84 2/8/2024
2.1.66 80 2/8/2024
2.1.65 1,096 2/8/2024
2.1.64 78 2/8/2024
2.1.63 766 2/8/2024
2.1.62 2,071 2/7/2024
2.1.61 1,050 2/6/2024
2.1.60 83 2/6/2024
2.1.59 1,347 2/6/2024
2.1.58 84 2/6/2024
2.1.57 847 2/6/2024
2.1.54 83 2/5/2024
2.1.53 81 2/5/2024
2.1.52 2,817 2/4/2024
2.1.51 1,255 2/2/2024
2.1.49 75 2/1/2024
2.1.48 1,658 1/31/2024
2.1.47 1,331 1/29/2024
2.1.46 1,326 1/29/2024
2.1.45 617 1/29/2024
2.1.44 824 1/28/2024
2.1.43 74 1/28/2024
2.1.42 851 1/28/2024
2.1.41 72 1/28/2024
2.1.40 76 1/28/2024
2.1.39 698 1/28/2024
2.1.38 906 1/28/2024
2.1.37 680 1/28/2024
2.1.36 76 1/28/2024
2.1.35 72 1/28/2024
2.1.34 75 1/28/2024
2.1.33 897 1/27/2024
2.1.31 291 1/27/2024
2.1.30 1,018 1/27/2024
2.1.29 935 1/27/2024
2.1.27 502 1/27/2024
2.1.26 992 1/27/2024
2.1.25 685 1/26/2024
2.1.24 70 1/26/2024
2.1.23 73 1/26/2024
2.1.22 74 1/26/2024
2.1.21 658 1/26/2024
2.1.20 645 1/26/2024
2.1.19 696 1/26/2024
2.1.18 692 1/26/2024
2.1.17 775 1/26/2024
2.1.16 779 1/26/2024
2.1.15 287 1/25/2024
2.1.14 842 1/25/2024
2.1.13 840 1/25/2024
2.1.12 76 1/25/2024
2.1.11 754 1/25/2024
2.1.10 710 1/25/2024
2.1.9 769 1/25/2024
2.1.7 5,135 1/15/2024
2.1.6 1,139 1/14/2024
2.1.5 1,415 1/14/2024
2.1.4 1,339 1/13/2024
2.1.3 1,364 1/5/2024
2.1.2 109 1/2/2024
2.1.1 112 12/29/2023