I’m generating test/seed data for a project using Autopoco.
Each meeting abject gets assigned a random date over a years time span(DefaultRandomDateSource), and i also want the meeting object to be assigned a random title from a predefined list(MeetingTitleSource).
The problem i’m getting is that the meeting title are not being applied in a random time order. Ie: the first two weeks are all “Perfromance Meeting”, then the next two weeks are all “Design Meeting” etc etc. I want the meeting titles to be assigned totally at random.
Can anyone help?
Here’s my code that creates the seed data
//Configure the default properties
var meetings = AutoPocoContainer.Configure(x =>
{
x.Conventions(c => { c.UseDefaultConventions(); });
x.Include<Meeting>()
.Setup(c => c.StartDate).Use<DefaultRandomDateSource>
(DateTime.Parse("21/Mar/2013"),
DateTime.Parse("21/Mar/2012"))
.Setup(c => c.EndDate).Use<MeetingEndDateSource>(0, 8)
.Setup(c => c.Title).Use<MeetingTitleSource>()
});
_meetings = meetings.CreateSession().List<Meeting>(MeetingRecords).Get();
Here’s the defaultdate source
public class DefaultRandomDateSource : DatasourceBase<DateTime>
{
private DateTime _MaxDate { get; set; }
private DateTime _MinDate { get; set; }
private Random _random = new Random(1337);
public DefaultRandomDateSource(DateTime MaxDate, DateTime MinDate)
{
_MaxDate = MaxDate;
_MinDate = MinDate;
}
public override DateTime Next(IGenerationContext context)
{
var tspan = _MaxDate - _MinDate;
var rndSpan = new TimeSpan(0, _random.Next(0, (int)tspan.TotalMinutes), 0);
return _MinDate + rndSpan;
}
}
Here’s the MeetingTitle Source
public class MeetingTitleSource : DatasourceBase<string>
{
private Random mRandom = new Random(1337);
public override string Next(IGenerationContext context)
{
return MeetingNames[mRandom.Next(0, MeetingNames.Length)];
}
private static string[] MeetingNames = new String[]{
"Design meeting",
"Strategy Meeting",
"Performance review",
"Appraisal",
"Disciplinary",
"Project review",
"Client Meetings",
"Budget Meeting",
"Financial Update",
"CompStat",
"Project Update"
};
}
You are using the same seed so the same sequence of values will be generated every time.
The nanosecond value from the system clock is often used as seed, you might want to try that.