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>