Date Rules


These rules can be applied to properties of type DateTime.

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

Default

By default date properties are set to today's date

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

// sampleItem .FirstValue = DateTime.Today
// sampleItem.SecondValue = DateTime.Today

UseFutureDate

Randomly chooses a date between tomorrow and within the specified number of days in the future.

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

// sampleData.FirstValue = between tomorrow and 10 days in the future

UseHistoricDate

Randomly chooses a date between the specified number of days in the past and yesterday.

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

// sampleData.FirstValue = between 10 days in the past and yesterday

UseRange

Days


Randomly chooses a date between the specified number of days in the past and the specified number of days in the future.

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

// sampleData.FirstValue = between 10 days in the past and 10 days in the future

Dates


Randomly chooses a date between two specified dates.

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.FirstValue).UseRange(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(120))
                           .Generate();

// sampleData.FirstValue = between 1 day in the past and 120 days in the future

Last edited Nov 19, 2010 at 10:14 PM by JRoughan, version 2

Comments

No comments yet.