I’m using the great .NET library AutoPoco for creating test and Seed Data.
In my model I have 2 date properties, StartDate and EndDate.
I want the EndDate to be 3 hours after the start Date.
I’ve created a custom Data source for autopoco below that returns a random Datetime between a min and max 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 AutoPoco’s configuration how can i get my EndDate to be say, 3 hours after the autogenerated start Date?
Here’s the autopoco config
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"));
});
If I am correctly understanding the problem you need: to set
EndDatefromStartDate. I had to create a newDataSourceand get current item which we are constructing and read value from it. I haven’t thoroughly checked but it might fail ifStartDateis set afterEndDate(though I think the properties are set in the order they are setup, read source code for AutoPoco). Also I am using latest version from CodePlex as of today (20 Feb 2012).