How does NHibernateSession.Storage get initialized? _____
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Lars Zeb Sent: Tuesday, November 25, 2008 1:05 PM To: [email protected] Subject: MbUnit Error in MbUnit testing? I am just beginning to use the Sharp Architecture. I wrote a test to exercise a repository. The actual test method is: public void TestCanLoadFlier() { Flier flierFromDb = _flierRepository.Get(1); Assert.AreEqual("101", flierFromDb.StockKeepingUnit.TrimEnd()); Assert.AreEqual("Lighting", flierFromDb.Description); Assert.AreEqual(50000, flierFromDb.QuantityOnHand); } The test blows on a null object reference trying to get a Session object from NHibernate. However, if I swap out MbUnit and use NUnit instead, the test succeeds. What could I possibly be doing wrong? The code below is from Sharp, to which I've referenced in the above code. Thanks, Lars public class Repository<T> : RepositoryWithTypedId<T, int>, INHibernateRepository<T> { } public class RepositoryWithTypedId<T, IdT> : INHibernateRepositoryWithTypedId<T, IdT> { protected ISession Session { get { return NHibernateSession.Current; } } public T Get(IdT id) { return Session.Get<T>(id); } } public static class NHibernateSession { ... public static ISessionStorage Storage { get; set; } public static ISession Current { get { ISession session = Storage.Session; // ****This is NHibernateSession.cs:line 88**** if (session == null) { session = SessionFactory.OpenSession(); Storage.Session = session; } return session; } } Type:System.NullReferenceException Message:Object reference not set to an instance of an object. Source:SharpArch.Data TargetSite:NHibernate.ISession get_Current() HelpLink:null StackTrace: at SharpArch.Data.NHibernate.NHibernateSession.get_Current() in C:\MyStuff\Dev\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data\NHibe rnate\NHibernateSession.cs:line 88 at SharpArch.Data.NHibernate.RepositoryWithTypedId`2.Get(IdT id) in C:\MyStuff\Dev\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data\NHibe rnate\Repository.cs:line 39 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MbUnit.User" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/MbUnitUser?hl=en -~----------~----~----~----~------~----~------~--~---
