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:
- Inherit from the RepositoryUnitTestsBase class.
- Explitly call the Setup and Tear down methods
So your class should basically look like:
[TestClass]
public class ProductRepositoryTest : RepositoryUnitTestsBase{[TestInitialize()]
public void MyTestInitialize(){this.SetUp();
}[TestCleanup()]
public void MyTestCleanup(){this.TearDown();
}}
I'd love to see these methods moved out into a seperate utility type class.
Enjoy
-Josh
No comments:
Post a Comment