I’m currently in the process of moving Suteki Shop from Linq-to-SQL to NHibernate. It turns out to be a bigger job than I anticipated, and I’ll be writing a post about my experiences soon. I’m using FNH (Fluent NHibernate) to build my mapping files rather than use the tedious built-in XML mapping. One of the big jobs I have is to write unit tests for all the mapping files. For each entity, I want to have a test that creates an instance of it, saves it to the database, and retrieves it. As you can imagine, it would be a tedious task to write all these. With that in mind I’ve created a simple NUnit test that can be reused for any mapped entity using System;
using System.Reflection;
using NUnit.Framework;
using Suteki.Common.Extensions;
using Suteki.Shop.Tests.Models.Builders;namespace Suteki.Shop.Tests.Maps
{
/// <summary>
/// Runs a simple test for each entity listed. That it can be saved to the database and retrieved.
/// </summary>
[TestFixture]
public class SimpleMapTests : MapTestBase
{
[TestCase(typeof (PostZone))]
[TestCase(typeof (Postage))]
[TestCase(typeof (Country))]
public void SimpleMapTest(Type entityType)
{
var runSimpleMapTest = GetType().GetMethod("RunSimpleMapTest");
var runSimpleMapTestForType = runSimpleMapTest.MakeGenericMethod(entityType);
runSimpleMapTestForType.Invoke(this, new object[0]);
} public void RunSimpleMapTest<TEntity>() where TEntity : class, new()
{
var id = 0;
Read more: DZone
using System.Reflection;
using NUnit.Framework;
using Suteki.Common.Extensions;
using Suteki.Shop.Tests.Models.Builders;namespace Suteki.Shop.Tests.Maps
{
/// <summary>
/// Runs a simple test for each entity listed. That it can be saved to the database and retrieved.
/// </summary>
[TestFixture]
public class SimpleMapTests : MapTestBase
{
[TestCase(typeof (PostZone))]
[TestCase(typeof (Postage))]
[TestCase(typeof (Country))]
public void SimpleMapTest(Type entityType)
{
var runSimpleMapTest = GetType().GetMethod("RunSimpleMapTest");
var runSimpleMapTestForType = runSimpleMapTest.MakeGenericMethod(entityType);
runSimpleMapTestForType.Invoke(this, new object[0]);
} public void RunSimpleMapTest<TEntity>() where TEntity : class, new()
{
var id = 0;
Read more: DZone
0 comments:
Post a Comment