Instantly share code, notes, and snippets.

Embed
What would you like to do?
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