Thursday, November 20, 2008

S#arp Arch & MSTest

I have just started a new project, and as such I took this chance to further my exploration into alternative models then standard ASP.Net Webforms. I have been curious to learn more about ASP.Net MVC, and I wanted to continue exploring nHibernate.

When I first implemented nHibermate I used a model which was basically based upon Billy McCafferty's work; however, during this I found severe limitations one of which I blogged about here. Billy has been hard at work at developing a new set of patterns which are encapsulated in an architecure called S#arp.

One small glitch I ran into related to my use of MSTest. Billy has created a base class that all Respository test classes can inherit from. This class will setup and tear down nHibernate session and roll back any transactions which should help keep your database at a known state.

However, this class assumes the use of nUnit. Which when you try and use this from within MSTest it causes a null reference exception when you try and access the repository. If your like me and want to ue MSTest a real simple solution is this:

  1. Inherit from the RepositoryUnitTestsBase class.
  2. Explitly call the Setup and Tear down methods

So your class should basically look like:

    public class ProductRepositoryTest : RepositoryUnitTestsBase
        public void MyTestInitialize()
        public void MyTestCleanup()

I'd love to see these methods moved out into a seperate utility type class.


No comments: