我正在使用 Autopoco 为项目生成测试/种子数据。
每个会议对象都会在一年的时间跨度内分配一个随机日期(DefaultRandomDateSource),我还希望从预定义的列表(MeetingTitleSource)中为会议对象分配一个随机标题。
我遇到的问题是会议标题没有按随机时间顺序应用。即:前两周都是“绩效会议”,接下来的两周都是“设计会议”等等。我希望会议标题完全随机分配。
任何人都可以帮忙吗?
这是我创建种子数据的代码
//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();
这是默认日期源
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;
}
}
这是 MeetingTitle 源
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"
};
}