Boolean Rules


class SampleData
{
    public bool FirstValue { get; set; }
    public bool SecondValue { get; set; }
}

Default

The default value for Boolean properties is false.

var sampleData = Fabricator.Generate<SampleData>();

// sampleData.FirstValue = false

Randomize

Randomly chooses between true and false.

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.FirstValue).Randomize()
                           .Generate();

// sampleData.FirstValue = true | false

Negate

Negates the value of another boolean property (true => false, false => true).

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.SecondValue).Negate(x => x.FirstValue)
                           .Generate();

// sampleData.FirstValue = false && sampleData.SecondValue = true 

Notes
  • Properties cannot negate themselves
  • Properties cannot negate each other directly or indirectly

Last edited Nov 13, 2010 at 12:04 AM by JRoughan, version 3

Comments

No comments yet.