views:

82

answers:

1

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 properties. 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?

+7  A: 

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));
womp
Thanks for mentioning this tool, I'm going to have to give it a shot. I hate creating test data, hopefully this will make it a little less painful.
Matthew Vines
Neat stuff. Thanks, womp!
Arnis L.
Thanks, I'm trying it out now. Having some trouble getting it to work but it's more promising than writing a whole bunch of for loops.
Daniel T.