I use the large .NET AutoPoco library to create test and seed data.
In my model, I have 2 date properties, StartDate and EndDate.
I want EndDate to be 3 hours after the start date.
I created my own data source for autopoco below, which returns a random Datetime time between the minimum and maximum date
class DefaultRandomDateSource : DatasourceBase<DateTime>
{
private DateTime _MaxDate { get; set; }
private DateTime _MinDate { get; set; }
private Random _random { get; set; }
public DefaultRandomDateSource(DateTime MaxDate, DateTime MinDate)
{
_MaxDate = MaxDate;
_MinDate = MinDate;
}
public override DateTime Next(IGenerationSession session)
{
var tspan = _MaxDate - _MinDate;
var rndSpan = new TimeSpan(0, _random.Next(0, (int) tspan.TotalMinutes), 0);
return _MinDate + rndSpan;
}
}
But in the AutoPoco configuration, how can I get EndDate to say 3 hours after the auto-generated start date?
Here is the autopoco configuration
IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
{
x.Conventions(c => { c.UseDefaultConventions(); });
x.AddFromAssemblyContainingType<Meeting>();
x.Include<Meeting>()
.Setup((c => c.CreatedBy)).Use<FirstNameSource>()
.Setup(c => c.StartDate).Use<DefaultRandomDateSource>(DateTime.Parse("21/05/2011"), DateTime.Parse("21/05/2012"));
});
source
share