What's the best way to fill POCOs with dummy data?
I have a bunch of POCOs that all relate to each other in a big tree. For example, this is the top-level element:
public class Incident : Entity<Incident>
{
public virtual string Name { get; set; }
public virtual DateTime Date { get; set; }
public virtual IEnumerable<Site> Sites { get; set; }
public Incident()
{
Sites = new HashSet<Site>();
}
}
The tree goes something like Incident -> Sites -> Assessments -> Subsites -> Images
. The POCO's don't have any logic, just a bunch of properti开发者_开发问答es. What I want to do is just fill every property with random dummy data so I can write some search code. What's the best way of doing this if I want to create a large number of dummy data?
I would consider using NBuilder. It lets you do just that - create random data for your objects, using a pretty straightforward syntax. For example:
var products = Builder<Product>.CreateListOfSize(100)
.WhereTheFirst(5)
.Have(x=>x.Title = "something")
.AndTheNext(95)
.Have(x => x.Price = generator.Next(0, 10));
精彩评论