UPDATE: I am using the Castle MonoRail project trunk code, NOT RC2
I’ve had a few friends ask me what is MonoRail and how do I set it up? I decided to go from the ground up here. There is nothing here that you can’t get from the Castle website documentation. I just want to grok this stuff and like Mr. Torvalds says, “Talk is cheap, show me the code“. I also want to learn how to unit test in this environment. I’ve heard the great things about Ruby on Rails (RoR from now on), but want to make that migration slowly.
Please don’t laugh if this is too beginning for you. I will eventually get to some advanced topics like:
and much more after the scar tissue starts to gather (one mentioned below).Please be patient with me and if you are using MonoRail in production, please make sure I stay on the correct path (JoeyDotNet, Scott Bellware and the Dovetail team, and Billy McCafferty are a few that I know of).
Now we begin.
My current main folder structure in my source control (Subversion) is like so:
I also use Ankh for my Subversion plug-in in Visual Studio 2005 (hence the green checkmarks in the image above and future images.)
I keep all my dependent libraries in the lib folder (yes, Jason, we’re not morons…I know)
Once the default structure is setup, you need to setup your folders so that MonoRail will work properly:
Notice the folder structure:
+ViewComponents (future post)
—–(matching controller named folders containing vm files)
—–layouts (next post)
—–rescues (next post)
This is all provided on the Castle website documentation.
I am currently using shared hosting (WebHost4Life) and it has served it’s purpose. I recently posted about how they added the .rails extension to the server so that I can feel more legitimate about using rails than having to use a different extension, explained here and in my previous post. The installation instructions on the Castle website documentation are very user friendly. I personally took the sample solution and started from there. It worked great. Just build it locally and upload your web project to your web host. I personally check into a subversion repository and use CruiseControl.NET for my automated continuous integration and during that process my NAnt script handles deployment.
I’M NOT A DESIGNER:
No matter how hard I try to design sites, I can’t make them appealing to the human eye. I LOVE Open Source Web Designs. It has over 2000 designs and gives me a place to start. The site I’m using, JasonMeridth.com, for this example is create by Node Thirty Three (I firmly believe in giving the designers their dues) and know it will do it’s job.
NOTES TO PAY ATTENTION TO:
If, sorry, when you setup your Test projects make sure to reference the correct assemblies needed for unit testing with MonoRail. They are Castle.MonoRail.Framework, Castle.MonoRail.TestSupport, and my unit testing framework of choice is NUnit, so I reference nunit.Framework. Also don’t forget to reference the project you are unit testing. In this case it is my JasonMeridth project.
I’m still trying out the abstract base test class that the Castle group has created, AbstractMRTestCase.
TIP: Currently I’ve learned that if you do the following (This is only a serious rough draft, please no comments on test names or formatting):
you will get a NullReferenceException:
All I had to do was change the SetUp attribute to a test attribute. I will pursue this further, and I imagine it has something to do with the fact that the controller is instantiated before the view, but that is just a guess. [Stupid moment being recorded in my blog, future update coming here when someone comments and educates me :)]
FIRST ATTEMPT AT OUTPUT:
The helloworld.vm file:
The header of my site is a picture of my 2 year old son standing in the underwater view of the Dolphins at the Texas State Aquarium in Corpus Christi, Texas.
The side photo is me beginning Meridth 2.0 training. He loves Tux Racer. :)
Next Post is on Layouts & Rescues (Exception handling pages).