NBuilderNBuilder is one of those tools that just fills a certain need, but it fills it very well indeed. It auto-populates semi-random data into your objects, or lists of objects. Why would you ever need that? I can think of three reasons right off the top of my head. I'm sure you can come up with more:
- To generate "fake" data to drive your UI without connecting to the database. Extremely useful for quick prototyping.
- To generate "test" data for your unit/integration tests.
- To generate "sample" data for driving demos about completely unrelated things :)
Here is one of my typical usages: Say I'm working on a page that lists my customers. I'd certainly be using the "repository pattern" for my data access. You would too, right? Right? That would mean I have an interface that looks something like this:
Which is working with Customer objects, which look like this:
Now, my "real" repository perhaps isn't ready yet. Maybe the DBA's haven't gotten around to creating the database that I designed yet. Maybe I want to demo the site without any real database connectivity. If I had a real repository, it would likely look something like this:
Of course, substitute LINQ-to-SQL, NHibernate, Entity Framework, Subsonic, etc. I'm implementing an Interface, so I can do whatever I want, right? That's a good thing. Have you seen my article about Interfaces Everywhere? Here's the trick: Create an implementation of that Interface that gets "fake" data from NBuilder. Like this:
Which, as you can see in the following screenshot of a debugging session, creates a nice predictable list of customers for me:
Now, of course, using the magic of IoC, I can easily tell my site to use the "fake" repository when I want to, like during debugging or design time, and use the "real" repository when needed.
There are tons of other cool options and fun things you can do, like:
Here are some useful links to help get you started: