Jeff,
Silly possibilities is my middle name. Billy McCafferty's Sharp Architecture ( <http://code.google.com/p/sharp-architecture/> http://code.google.com/p/sharp-architecture/) uses NUnit. I built the DLLs not even looking at that. I am more used to MbUnit than NUnit. So in the programs I was writing, and which refer to the Sharp Architecture, I changed to MbUnit. I am very sorry to have bothered you with this. After rebuilding that DLL containing RepositoryUnitTestsBase.Setup() pointing to MbUnit, the tests went perfectly. Thanks again, Lars From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Brown Sent: Tuesday, November 25, 2008 9:04 PM To: [email protected] Subject: MbUnit Re: Error in MbUnit testing? Hmm. That's some nice code BTW. I particularly like that you are checking assumptions along the way. This is often neglected in test harnesses and makes it more difficult to find problems. Can you find out whether the SetUp method is actually running? One simple way to do that would be to add a TestLog.WriteLine("Hello!") in there. We do have some tests using abstract base classes with setup methods on them but there might still be a bug in there... So I guess the objective would be to figure out why the Storage property does not seem to be initialized as it should given the code. Here's a very silly possibility. Could it be that the abstract base class is using the NUnit [SetUp] attribute instead of the MbUnit one? (Might happen if you are incrementally transitioning to MbUnit.) Jeff. On Tue, Nov 25, 2008 at 3:01 PM, Lars Zeb <[EMAIL PROTECTED]> wrote: Sorry, I was trying to keep code to the minimum. The test fixture is derived from RepositoryUnitTestsBase, which calls the Init method on NHibernateSession object. [TestFixture] public class FlierRepositoryTest : RepositoryUnitTestsBase { private readonly IRepository<Flier> _flierRepository = new Repository<Flier>(); [Test] public void TestCanLoadFlier() { Flier flierFromDb = _flierRepository.Get(1); Assert.AreEqual("101", flierFromDb.StockKeepingUnit.TrimEnd()); Assert.AreEqual("Lighting", flierFromDb.Description); Assert.AreEqual(50000, flierFromDb.QuantityOnHand); } } public static class NHibernateSession { public static Configuration Init(ISessionStorage storage, string[] mappingAssemblies) { return Init(storage, mappingAssemblies, null, null); } public static Configuration Init(ISessionStorage storage, string[] mappingAssemblies, string cfgFile) { return Init(storage, mappingAssemblies, cfgFile, null); } public static Configuration Init(ISessionStorage storage, string[] mappingAssemblies, string cfgFile, string validatorCfgFile) { Check.Require(storage != null, "storage mechanism was null but must be provided"); Configuration cfg = ConfigureNHibernate(cfgFile); ConfigureNHibernateValidator(cfg, validatorCfgFile); AddMappingAssembliesTo(cfg, mappingAssemblies); SessionFactory = cfg.BuildSessionFactory(); Storage = storage; return cfg; }. public abstract class RepositoryUnitTestsBase { [SetUp] public void SetUp() { string nhibernateConfig = ConfigurationSettings.AppSettings["nhibernate.config.path"]; string mappingAssemblies = ConfigurationSettings.AppSettings["nhibernate.mapping.assembly"]; Check.Require(!string.IsNullOrEmpty(nhibernateConfig), "Please add an AppSetting to your app.config for 'nhibernate.config.path.' This setting " + "should be a relative path to the location of the configuration file containing NHibernate config options."); Check.Require(!string.IsNullOrEmpty(mappingAssemblies), "Please add an AppSetting to your app.config for 'nhibernate.mapping.assembly.' This setting " + "takes a comma delimited list of assemblies containing NHibernate mapping files. Including '.dll' " + "at the end of each is optional."); NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies.Split(','), nhibernateConfig); NHibernateSession.Current.BeginTransaction(); } } From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Brown Sent: Tuesday, November 25, 2008 1:46 PM To: [email protected] Subject: MbUnit Re: Error in MbUnit testing? 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 <BR --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
