NHibernate Forge
The official new home for the NHibernate community

Data base schema util service with NHibernate.Burrow

Article
Comments (1)
History (11)
100% of people found this useful

Data base schema util service with NHibernate.Burrow

I want to share with you the way I prepare my unit tests to work against a data base.

The goal is that the data base scheme is created before and is dropped after each test.

I use NHibernate.Burrow for this purpose, you can find util classes to do this in NHibernate.Burrow.Util namespace in NHibernate.Burrow.dll

First I made this service class:

using System;
using System.Text;
using NHibernate.Burrow.Util;
 
namespace Tests.Services
{
    /// <summary>
    /// DBSchema services
    /// </summary>
    public static class DBSchemaService
    {
        /// <summary>
        /// DB Schema creation using configuration and 
        /// mapping files (app.config and embeded resources *.hbm.xml)
        /// </summary>
        public static void CreateDBSchema()
        {
            SchemaUtil util = new SchemaUtil();
            util.CreateSchemas(false, true);
        }
        /// <summary>
        /// DB Schema update using configuration and 
        /// mapping files (app.config and embeded resources *.hbm.xml)
        /// </summary>
        public static void UpdateDBSchema()
        {
            SchemaUtil util = new SchemaUtil();
            util.UpdateSchemas(false, true);
        }
        /// <summary>
        /// Drop DB Schema
        /// </summary>
        public static void DropDBSchema()
        {
            SchemaUtil util = new SchemaUtil();
            util.DropSchemas(false, true);
        }
    }
}

Then you can use this in SetUp and TearDown methods:

using System;
using NUnit.Framework;
using NHibernate.Burrow;
using Tests.Services;
 
namespace Tests.Base
{
    public class TestCase
    {
        [SetUp]
        public void Setup()
        {
            DBSchemaService.CreateDBSchema();
            new BurrowFramework().InitWorkSpace();
        }
    
        [TearDown]
        public void Dispose()
        {
            new BurrowFramework().CloseWorkSpace();
            DBSchemaService.DropDBSchema();
        }
    }
}

I hope that you find it useful.

Recent Comments

By: kailuowang Posted on 09-13-2008 11:07

<p>Thank you, Sergio!</p>

View All
Powered by Community Server (Commercial Edition), by Telligent Systems