Skip to content

Commit 3f7dedb

Browse files
hazzikfredericDelaporte
authored andcommitted
Add test for #2750
1 parent 6dba65d commit 3f7dedb

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.GH2750
4+
{
5+
public class TestEntity
6+
{
7+
public virtual Guid Id { get; set; }
8+
}
9+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Transactions;
4+
using NHibernate.Cfg;
5+
using NHibernate.Cfg.MappingSchema;
6+
using NHibernate.Mapping.ByCode;
7+
using NUnit.Framework;
8+
9+
namespace NHibernate.Test.NHSpecificTest.GH2750
10+
{
11+
[TestFixture]
12+
public class ByCodeFixture : TestCaseMappingByCode
13+
{
14+
protected override HbmMapping GetMappings()
15+
{
16+
var mapper = new ModelMapper();
17+
mapper.Class<TestEntity>(rc =>
18+
{
19+
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned));
20+
});
21+
22+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
23+
}
24+
25+
protected override void Configure(Configuration configuration)
26+
{
27+
configuration.SetProperty(Cfg.Environment.BatchSize, 10.ToString());
28+
configuration.SetProperty(Cfg.Environment.UseConnectionOnSystemTransactionPrepare, true.ToString());
29+
}
30+
31+
protected override void OnTearDown()
32+
{
33+
using (var session = OpenSession())
34+
using (var transaction = session.BeginTransaction())
35+
{
36+
session.CreateQuery("delete from System.Object").ExecuteUpdate();
37+
38+
transaction.Commit();
39+
}
40+
}
41+
42+
[Test]
43+
public void ShouldWorkWithSystemTransaction()
44+
{
45+
const int count = 3;
46+
var entities = new List<TestEntity>(count);
47+
for (var i = 0; i < count; i++)
48+
{
49+
entities.Add(new TestEntity { Id = Guid.NewGuid() });
50+
}
51+
52+
using (var transaction = new TransactionScope())
53+
{
54+
using (var session = Sfi.OpenStatelessSession())
55+
{
56+
foreach (var entity in entities)
57+
{
58+
session.Insert(entity);
59+
}
60+
}
61+
62+
transaction.Complete();
63+
}
64+
65+
using (var session = OpenSession())
66+
{
67+
var results = session.QueryOver<TestEntity>().List<TestEntity>();
68+
69+
Assert.That(results.Count, Is.EqualTo(count));
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)