What's the best way to fill POCOs with dummy data?

I have a group of POCOs that are all linked to each other in a large 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 looks something like Incident -> Sites -> Assessments -> Subsites -> Images

. POCO doesn't have any logic, just a bunch of properties. What I want to do is just populate each property with random dummy data so that I can write the search code. What's the best way to do this if I want to create a large amount of dummy data?

+2


source to share


1 answer


I would like to use NBuilder . This allows you to do just that - generate random data for your objects using a fairly simple 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));

      

+7


source







All Articles