Created
August 24, 2011 20:07
-
-
Save damianh/1169056 to your computer and use it in GitHub Desktop.
NHibernateTransactionTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NHibernateTransactionTest | |
{ | |
[Fact] | |
public void NHibernateSave_ShouldNotThrow() | |
{ | |
var sessionFactory = Fluently.Configure() | |
.Database(MsSqlConfiguration | |
.MsSql2008 | |
.ConnectionString(c => c | |
.Server("localhost") | |
.Database("ConcurrencyTest") | |
.TrustedConnection())) | |
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateTransactionTest>()) | |
.BuildSessionFactory(); | |
DoStore(sessionFactory); | |
DoStore(sessionFactory); | |
sessionFactory.Dispose(); | |
} | |
private static void DoStore(ISessionFactory sessionFactory) | |
{ | |
using (new TransactionScope()) | |
using (var session = sessionFactory.OpenSession()) | |
{ | |
var entity = new Entity { Id = "Test" }; | |
session.Save(entity); | |
} | |
} | |
public class Entity | |
{ | |
public virtual string Id { get; set; } | |
} | |
public class EntityMap : ClassMap<Entity> | |
{ | |
public EntityMap() | |
{ | |
Table("Entities"); | |
Id(x => x.Id).Length(50); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment