Using Factory Girl from C# with IronRuby for building .NET objects

Recently at work, I've been using TDD to drive out the design for some WPF View Models. Part of what I'm doing is filtering a collection based on various properties of the elements in the collection. Of course, I've needed to build up that collection first. I'd come up with a very limited method using Action<T> to set properties when the builder method was called. While this worked for my needs, I got to thinking about a library I've used a couple of times on Rails projects: Factory Girl.

On numerous occasions working with C# on .NET, I've thought to myself man, I really wish I had something like Factory Girl here!. So, last night/this morning, I set out to create a spike solution to determine the feasibility of hosting IronRuby within my C# library, thus allowing me to use Factory Girl to build POCOs for me. The result:


Well, at least for the method, but that's all I was interested in for this spike.

I’ve put my code up on github for your perusal. For this particular solution I don't think you'll need Visual Studio 2010, but you will certainly need .NET 4 installed, as well as IronRuby. Also note that IronRuby needs to be installed into C:\IronRuby unless you want to edit the app.config and fix up some references.

I'm excited now about the possibilities of utilizing other Ruby libraries in my .NET projects!


comments powered by Disqus