Value Rules


These rules can be applied to properties of any type.


class SampleData
{
    public string Value { get; set; }
}

Use

Use Value

Set a specific value to be used for all generated items.

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.Value).Use("MyValue")
                           .Generate();

// sampleData.Value = "MyValue"

Use Lambda

Set an anonymous method to generate a value for each item.

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.Value).Use(x => "MyValue")
                           .Generate();

// sampleData.Value = "MyValue"

Use Method

Set a method to generate a value for each item.


static string MakeValue(SampleData item)
{
    return "MyValue";
}

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.Value).Use(MakeValue)
                           .Generate();

// sampleData.Value = "MyValue"

Last edited Nov 13, 2010 at 5:27 AM by JRoughan, version 7

Comments

No comments yet.