FoodCandy!

Unit Tests

Introduction

This page will guide you through the SnCore unit testing.

Prerequisites

  • NUnit 2.2, checked-in under nunit.

Running Unit Tests

  1. Run nunit/bin/nunit-gui.exe.
  2. Open the SnCore.nunit project.
  3. Run.

Writing Unit Tests

SnCore unit tests live in the following assemblies:
  • SnCore.Data.Tests: straightforward N-Hibernate mappings.
  • SnCore.Services.Tests: business logic tests.
To write a new set of unit tests, create a class that inherits SnCore::Data::Tests::NHibernateTest. This gives you access to an NHibernate Session object to run database operations. Use [TestFixure] and [Test] attributes to mark test classes and unit tests.

using System;
using NUnit.Framework;
using SnCore.Data;
using NHibernate;
using SnCore.Data.Tests;
using System.Collections;
using NHibernate.Expression;

namespace SnCore.Services.Tests
{
    [TestFixture]
    public class ManagedMyClassTest : NHibernateTest
    {
        public ManagedMyClassTest()
        {

        }

        [Test]
        public void CreateMyClass()
        {
            MyClass class = new MyClass(Session);
            try
            {
                class.CreateOrUpdate();
            }
            finally
            {
                if (class.Id > 0)
                {
                    class.Delete();
                }
            }
        }
    }
}
© FoodCandy, 2006-2007, All Rights Reserved | FoodCandy | Sun Oct 7 10:48:50 2007 | Doxygen 1.4.6-NO