Skip to content

Instantly share code, notes, and snippets.

@jeroenheijmans
Last active March 20, 2016 14:34
Show Gist options
  • Save jeroenheijmans/96ce142f211c0b103f03 to your computer and use it in GitHub Desktop.
Save jeroenheijmans/96ce142f211c0b103f03 to your computer and use it in GitHub Desktop.
Minmal Repro for NHibernate issues (SSCCE / MCVE)
/* Gist for minimal repro for NHibernate issues
*
* 1. Create new (e.g. .NET 4.5.1) class library;
* 2. Add NHibernate (e.g. 4.0.3) via NuGet;
* 3. Add FluentNHibernate (e.g. 2.0.1) via NuGet;
* 4. Add NUnit (e.g. 2.6.4) via NuGet;
* 5. Create database "NhTestDb" on Sql Server "localhost" (or adjust for your specific situation);
* 6. Compile;
* 7. Run tests (should be green).
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Mapping;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;
namespace MyTestLibrary
{
public class Item
{
public virtual int Id { get; set; }
}
public class ItemMap : ClassMap<Item>
{
public ItemMap()
{
Id(i => i.Id);
}
}
[TestFixture]
public class MyTestFixture
{
const string connectionString = @"data source=localhost; Integrated Security=SSPI; Initial Catalog=NhTestDb";
private ISessionFactory sessionFactory;
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString))
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true))
.BuildSessionFactory();
}
[Test]
public void MyTest001()
{
var session = sessionFactory.OpenSession();
var item = new Item();
using (var transaction = session.BeginTransaction())
{
session.Save(item);
transaction.Commit();
}
Assert.That(item.Id, Is.Not.EqualTo(default(int)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment