TimeRules


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 midnight at today's date

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

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

UseFutureDateTime

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).UseFutureDateTime(TimeSpan.FromHours(5))
                           .Generate();

// sampleData.FirstValue = between one second and 5 hours in the future

UseHistoricDateTime

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

var sampleData = Fabricator.Setup<SampleData>()
                           .For(x => x.FirstValue).UseHistoricDateTime(TimeSpan.FromHours(5))
                           .Generate();

// sampleData.FirstValue = between 5 hours in the past and one second ago

UseRange

Randomly chooses a time between the specified range in the past and the specified range in the future.

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

// sampleData.FirstValue = between 2 minutes in the past and 2 minutes in the future

Last edited Nov 19, 2010 at 9:20 PM by JRoughan, version 1

Comments

No comments yet.