FakeUp 0.0.1.1

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

// Install FakeUp as a Cake Tool
#tool nuget:?package=FakeUp&version=0.0.1.1

Overview

FakeUp is small project that allows to generate fake data objects with complex structure for tests. The goal is to create API that is concise and modular, so creating fixtures for nested and/or dependent structures is painless or at least a lot less painful. It is just worse version of AutoFixture but some tasks that I was needed can be done more easily with FakeUp since it have to narrower scope and more specialized features.

Features highlight

Filling values based on relative paths

For use when you have reoccurring structures with some special cases.

class Foo {
   Bar Bar { get; }    
   Baz Baz { get; }
   string Value { get; }
}
class Bar {
   Baz Baz { get; }
}
class Baz {
   string Value { get; }
}

When creating fixture with following code

var result = FakeUp.NewObject<Foo>(o => o
   .FillAll<string>().With("default")
   .Fill((Bar bar) => bar.Baz.Value).With("bar baz")
)

You will receive the following:

Foo
   Bar.Baz.Value: "bar baz"
   Baz.Value: "default"
   Value: "default"

Sharing state

When you have values that are dependent on one another, you can use State to manage shared values. For example we have following structure:

class ReceiptBook {
    public List<Ingredient> Ingredients { get; set; }
    public List<FoodReceipt> Receipts { get; set; }
}
class FoodReceipt {
    public string Name { get; set; }
    public List<Ingredient> Ingredients { get; set; }
}
class Ingredient {
    public string Name { get; set; }
}

We want ReceiptBook.Ingredients to contain all ingredients used in all FoodReceipts. We can achieve this using object that will track all added ingredients:

class FoodReceiptState
{    
    public List<Ingredient> AllIngredients { get; } = new List<Ingredient>();

    public Ingredient GetIngredient()
    {
        if (!this.AllIngredients.Any() || new Random().NextDouble() > 0.5)
        {
            var ingredient = NewIngredient();
            this.AllIngredients.Add(ingredient);
            return ingredient;
        }

        return this.AllIngredients[this.Random.Next(0, this.AllIngredients.Count)];
    }

    private Ingredient NewIngredient() => FakeUp.NewObject<Ingredient>(o => o.FillAll<string>().WithGuid());
}

The idea is, that every time FakeUp will require FoodReceipt.Ingredient we will return either new Ingredient and add it to list or return excising one. So AllIngredients will always contain all generated ingredients.

Now following declaration will create object with required structure:

FakeUp.NewObject<ReceiptBook>(o => o
    .WithCollectionsSize(3)
    .AddState(() => new FoodReceiptState())
    
    .FillAll<string>().WithGuid()

    .FillAll<Ingredient>()
    .With(ctx => ctx.GetState<FoodReceiptState>().GetIngredient())

    .Fill(book => book.Ingredients)
    .With(ctx => ctx.GetState<FoodReceiptState>().AllIngredients)
);
Product Compatible and additional computed target framework versions.
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.0.1.1 591 7/3/2019

Initial release