Some.TestDataGeneration 0.3.2

dotnet add package Some.TestDataGeneration --version 0.3.2
NuGet\Install-Package Some.TestDataGeneration -Version 0.3.2
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="Some.TestDataGeneration" Version="0.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Some.TestDataGeneration --version 0.3.2
#r "nuget: Some.TestDataGeneration, 0.3.2"
#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 Some.TestDataGeneration as a Cake Addin
#addin nuget:?package=Some.TestDataGeneration&version=0.3.2

// Install Some.TestDataGeneration as a Cake Tool
#tool nuget:?package=Some.TestDataGeneration&version=0.3.2

TestDataGeneration

A C# library, wrapping the AutoBogus generator, providing reusable configuration and a more developer-friendly syntax.

Usage

Generate using provided default configuration

var x = Some.Generated<int>();
var y = Some.Generated<Article>();

Define rules to be used when generating data

Create a binder that inherits from Some.DefaultBinder. This should contain rules that will be applied by default when generating data.

public class DemoBinder : Some.DefaultBinder
{
    public DemoBinder()
    {
        TypeRules[typeof(Article)] = ArticleRules;
        TypeRules[typeof(Order)] = OrderRules;
        TypeRules[typeof(Customer)] = CustomerRules;
    }

    private static readonly Func<Faker<Article>, Faker<Article>> ArticleRules =
        f => f.RuleFor(x=>x.Price, Some.Int(0)); //Price is positive

    private static readonly Func<Faker<Order>, Faker<Order>> OrderRules =
        f => f.FinishWith((_, x) =>
        {
            x.CustomerId = x.Customer.Id; //FK-property matches nav-prop.Id
        });

    private static readonly Func<Faker<Customer>, Faker<Customer>> CustomerRules = f => f
        .RuleFor(x=>x.FavoriteArticle, Some.Generated<Article>()) //Use "ArticleRules"
        .FinishWith((_, x) =>
        {
            x.FavoriteArticleId = x.FavoriteArticle?.Id;
        });
}

Configure data-generation to use the defined rules

Add a initializer to your test project(s) to configure the data-generation with the defined rules.

internal class TestProjectInitializer
{
    [ModuleInitializer]
    internal static void ConfigureTestDataGeneration()
    {
        Some.CustomConfigApplied(new DemoBinder());
    }
}

Override default rules for a single generation

var x = Some.InstanceOf<Article>()
            .RuleFor(x => x.Price, Some.Int(int.MinValue, 0))
            .Generate();
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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.2 8,974 6/1/2023
0.3.1 118 6/1/2023
0.3.0 125 5/26/2023
0.2.0 169 5/25/2023
0.1.0 580 4/21/2023