-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [Resolved] NHibernate with NUnit, noob Q
PostPosted: Tue May 23, 2006 9:36 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 12:53 am
Posts: 34
I am having a hard time with NHibernate and NUnit these days. I need help on what thing(s) I missed. Here's what I did... I've got 2 projects with VS.NET 2003. webarti and webartiData where webartiData contains the data classes. One of my classes is Section class to be mapped to Sections table on MSSQL, here's the code.

Code:
using System;

namespace Agta.ManilaBulletin.Data
{
   /// <summary>
   ///
   /// </summary>
   public class Section
   {
      private int id;
      private string title;
      private string description;
      private bool isInactive;
      private Category category;

      /// <summary>
      ///
      /// </summary>
      /// <param name="id"></param>
      /// <param name="title"></param>
      /// <param name="description"></param>
      /// <param name="isInactive"></param>
      /// <param name="category"></param>
      public Section(int id, string title, string description,
         bool isInactive, Category category)
      {
         this.Id = id;
         this.Title = title;
         this.Description = description;
         this.IsInactive = isInactive;
         this.Category = category;
      }

      /// <summary>
      /// Creates a new instance of Section.
      /// </summary>
      public Section() : this (0, "", "", false, Category.NewsAndFeatures) {}

      /// <summary>
      ///
      /// </summary>
      public int Id
      {
         get { return id; }
         set { id = value; }
      }

      /// <summary>
      ///
      /// </summary>
      public string Title
      {
         get { return title; }
         set { title = value; }
      }

      /// <summary>
      ///
      /// </summary>
      public string Description
      {
         get { return description; }
         set { description = value; }
      }

      /// <summary>
      ///
      /// </summary>
      public bool IsInactive
      {
         get { return isInactive; }
         set { isInactive = value; }
      }

      /// <summary>
      ///
      /// </summary>
      public Category Category
      {
         get { return category; }
         set { category = value; }
      }
   }
}

and the hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
   namespace="Agta.ManilaBulletin.Data" assembly="webartiData">
   <class name="Section" table="Sections">
      <id name="Id" column="SectionId" type="Integer">
         <generator class="assigned"/>
      </id>
      <property name="Title" column="Title"/>
      <property name="Description" column="Description"/>
      <property name="IsInactive" column="IsInactive" type="Boolean"/>
   </class>
</hibernate-mapping>

On my unit test, I did this...
Code:
using System;
using Agta.ManilaBulletin.Data;
using NUnit.Framework;
using NHibernate;
using NHibernate.Cfg;

namespace Agta.ManilaBulletin.Test.Data
{
   /// <summary>
   ///
   /// </summary>
   [TestFixture] public class SectionTest
   {
      private Configuration cfg;
      private ISessionFactory factory;

      /// <summary>
      /// Creates a new instance of SectionTest.
      /// </summary>
      public SectionTest() {}

      [TestFixtureSetUp] public void OneTimeSetup()
      {
         cfg = new Configuration();
         cfg.AddAssembly("Agta.ManilaBulletin.Data");
         factory = cfg.BuildSessionFactory();
      }

      [Test] public void TestSave()
      {
         Section s = new Section(0, "Test1", "", false, Category.NewsAndFeatures);         
         ISession session = factory.OpenSession();
         ITransaction transaction = session.BeginTransaction();
         session.Save(s);
         transaction.Commit();
         session.Close();
      }
   }
}

I always get,
Code:
TestCase 'Agta.ManilaBulletin.Test.Data.SectionTest.TestSave' failed: TestFixtureSetUp Failed
TestFixture failed: The dialect was not set. Set the property hibernate.dialect.
   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)
   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   at Agta.ManilaBulletin.Test.Data.SectionTest.OneTimeSetup()

Any help? Millions of thanks in advance!

EDIT: Btw, here's my App.config

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
      <section name="nhibernate"
         type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
   </configSections>
   
   <nhibernate>
      <add key="hibernate.connection.provider"         
         value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="hibernate.dialect"                     
         value="NHibernate.Dialect.MsSql2000Dialect" />
      <add key="hibernate.connection.driver_class"         
         value="NHibernate.Driver.SqlClientDriver" />
      <add key="hibernate.connection.connection_string"
         value="user id=user;password=password;initial catalog=webarti;data source=pcname" />
   </nhibernate>
</configuration>


Last edited by nebulom on Wed May 24, 2006 9:59 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 2:06 am 
Newbie

Joined: Tue Mar 07, 2006 4:56 am
Posts: 17
Hi Nebulom,

simply put a file called "hibernate.cfg.xml" into your project which contains the unittests and use it with the following code to create your session factory:

Configuration cfg = new Configuration();
cfg.Configure( );
cfg.AddAssembly("*AssemblyNameWithHBMDefinitionsGoesHere*");
ISessionFactory DBSessionFactory = m_cfg.BuildSessionFactory();

The hibernate.cfg.xml should look like similar to this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<session-factory name="BS.SCP">
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=W10291\MSSQLW10291;initial catalog=BonusShop;Integrated Security=SSPI</property>
<!--<property name="show_sql">false</property>-->
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<!--<property name="use_outer_join">true</property>
<property name="query.substitutions">0</property>-->
<property name="hibernate.connection.isolation">ReadCommitted</property>
<!-- mapping files -->
<mapping assembly="BS.SCP.BASE" />
</session-factory>

</hibernate-configuration>

Hope that helps...

Kind regards, Marco...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 10:15 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Are these unit tests in a "Class Library" project? Are you copying the app.config file to the bin\Debug folder under the name "$(TargetName).config" where $(TargetName) is the full file name of the project output assembly?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 9:58 pm 
Beginner
Beginner

Joined: Tue May 23, 2006 12:53 am
Posts: 34
Yes, this is a Class library... so thanks k-dub. That works now. And you too cariarer, thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.