Skip to content

Commit 18af8fb

Browse files
Merge branch 'master' into NH-3987
2 parents a15363d + f5ceb03 commit 18af8fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+975
-477
lines changed

src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,24 @@ public void SuppliedConnection()
176176
{
177177
Prepare();
178178

179-
DbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
180-
ISession session = sessions.OpenSession(originalConnection);
181-
182-
Silly silly = new Silly("silly");
183-
session.Save(silly);
179+
using (var originalConnection = sessions.ConnectionProvider.GetConnection())
180+
using (var session = sessions.WithOptions().Connection(originalConnection).OpenSession())
181+
{
182+
var silly = new Silly("silly");
183+
session.Save(silly);
184184

185-
// this will cause the connection manager to cycle through the aggressive Release logic;
186-
// it should not Release the connection since we explicitly suplied it ourselves.
187-
session.Flush();
185+
// this will cause the connection manager to cycle through the aggressive Release logic;
186+
// it should not Release the connection since we explicitly supplied it ourselves.
187+
session.Flush();
188188

189-
Assert.IsTrue(originalConnection == session.Connection, "Different connections");
189+
Assert.IsTrue(originalConnection == session.Connection, "Different connections");
190190

191-
session.Delete(silly);
192-
session.Flush();
191+
session.Delete(silly);
192+
session.Flush();
193193

194-
Release(session);
195-
originalConnection.Close();
194+
Release(session);
195+
originalConnection.Close();
196+
}
196197
Done();
197198
}
198199

src/NHibernate.Test/Legacy/FooBarTest.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void WierdSession()
204204

205205
using (ISession s = OpenSession())
206206
{
207-
s.FlushMode = FlushMode.Never;
207+
s.FlushMode = FlushMode.Manual;
208208
using (ITransaction t = s.BeginTransaction())
209209
{
210210
Foo foo = (Foo) s.Get(typeof(Foo), id);
@@ -4977,21 +4977,27 @@ public void AutoFlushCollections()
49774977
[Test]
49784978
public void UserProvidedConnection()
49794979
{
4980-
IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties);
4981-
ISession s = sessions.OpenSession(prov.GetConnection());
4982-
ITransaction tx = s.BeginTransaction();
4983-
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
4984-
tx.Commit();
4985-
4986-
var c = s.Disconnect();
4987-
Assert.IsNotNull(c);
4980+
using (var prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties))
4981+
using (var connection = prov.GetConnection())
4982+
using (var s = sessions.WithOptions().Connection(connection).OpenSession())
4983+
{
4984+
using (var tx = s.BeginTransaction())
4985+
{
4986+
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
4987+
tx.Commit();
4988+
}
4989+
var c = s.Disconnect();
4990+
Assert.IsNotNull(c);
49884991

4989-
s.Reconnect(c);
4990-
tx = s.BeginTransaction();
4991-
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
4992-
tx.Commit();
4993-
Assert.AreSame(c, s.Close());
4994-
c.Close();
4992+
s.Reconnect(c);
4993+
using (var tx = s.BeginTransaction())
4994+
{
4995+
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
4996+
tx.Commit();
4997+
}
4998+
Assert.AreSame(c, s.Close());
4999+
c.Close();
5000+
}
49955001
}
49965002

49975003
[Test]
@@ -5181,7 +5187,7 @@ public void EmbeddedCompositeID()
51815187
s.Close();
51825188

51835189
s = OpenSession();
5184-
s.FlushMode = FlushMode.Never;
5190+
s.FlushMode = FlushMode.Manual;
51855191
l =
51865192
(Location)
51875193
s.CreateQuery("from l in class Location where l.CountryCode = 'AU' and l.Description='foo bar'").List()[0];

src/NHibernate.Test/Legacy/FumTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public void UnflushedSessionSerialization()
617617
// instead of just the usual openSession()
618618
using (ISession s = sessions.OpenSession())
619619
{
620-
s.FlushMode = FlushMode.Never;
620+
s.FlushMode = FlushMode.Manual;
621621

622622
Simple simple = new Simple();
623623
simple.Address = "123 Main St. Anytown USA";
@@ -656,7 +656,7 @@ public void UnflushedSessionSerialization()
656656

657657
using (ISession s = sessions.OpenSession())
658658
{
659-
s.FlushMode = FlushMode.Never;
659+
s.FlushMode = FlushMode.Manual;
660660
Simple simple = (Simple) s.Get(typeof(Simple), 10L);
661661
Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
662662
Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");
@@ -679,7 +679,7 @@ public void UnflushedSessionSerialization()
679679
// Test deletions across serializations
680680
using (ISession s = sessions.OpenSession())
681681
{
682-
s.FlushMode = FlushMode.Never;
682+
s.FlushMode = FlushMode.Manual;
683683
Simple simple = (Simple) s.Get(typeof(Simple), 10L);
684684
Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
685685
Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");

src/NHibernate.Test/NHSpecificTest/EmptyMappingsFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void InvalidQuery()
6161
public void NullInterceptor()
6262
{
6363
IInterceptor nullInterceptor = null;
64-
Assert.Throws<ArgumentNullException>(() => sessions.OpenSession(nullInterceptor).Close());
64+
Assert.Throws<ArgumentNullException>(() => sessions.WithOptions().Interceptor(nullInterceptor).OpenSession().Close());
6565
}
6666

6767
[Test]

src/NHibernate.Test/NHSpecificTest/NH1082/Fixture.cs

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ public override string BugNumber
1616
[Test]
1717
public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
1818
{
19-
#pragma warning disable 618
20-
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
21-
#pragma warning restore 618
22-
2319
var c = new C {ID = 1, Value = "value"};
2420

2521
var sessionInterceptor = new SessionInterceptorThatThrowsExceptionAtBeforeTransactionCompletion();
26-
using (ISession s = sessions.OpenSession(sessionInterceptor))
27-
using (ITransaction t = s.BeginTransaction())
22+
using (var s = sessions.WithOptions().Interceptor(sessionInterceptor).OpenSession())
23+
using (var t = s.BeginTransaction())
2824
{
2925
s.Save(c);
3026

@@ -42,10 +38,6 @@ public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
4238
[Test]
4339
public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransaction()
4440
{
45-
#pragma warning disable 618
46-
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
47-
#pragma warning restore 618
48-
4941
var c = new C { ID = 1, Value = "value" };
5042

5143
var synchronization = new SynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();
@@ -66,78 +58,4 @@ public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransacti
6658
}
6759
}
6860
}
69-
70-
71-
[TestFixture]
72-
[Obsolete("Can be removed when Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions is removed.")]
73-
public class OldBehaviorEnabledFixture : BugTestCase
74-
{
75-
public override string BugNumber
76-
{
77-
get { return "NH1082"; }
78-
}
79-
80-
protected override void Configure(Configuration configuration)
81-
{
82-
configuration.SetProperty(Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions, "true");
83-
base.Configure(configuration);
84-
}
85-
86-
[Test]
87-
public void ExceptionsInBeforeTransactionCompletionAreIgnored()
88-
{
89-
Assert.IsTrue(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
90-
91-
var c = new C {ID = 1, Value = "value"};
92-
93-
var sessionInterceptor = new SessionInterceptorThatThrowsExceptionAtBeforeTransactionCompletion();
94-
using (ISession s = sessions.OpenSession(sessionInterceptor))
95-
using (ITransaction t = s.BeginTransaction())
96-
{
97-
s.Save(c);
98-
99-
Assert.DoesNotThrow(t.Commit);
100-
}
101-
102-
using (ISession s = sessions.OpenSession())
103-
{
104-
var objectInDb = s.Get<C>(1);
105-
106-
Assert.IsNotNull(objectInDb);
107-
108-
s.Delete(objectInDb);
109-
s.Flush();
110-
}
111-
}
112-
113-
114-
[Test]
115-
public void ExceptionsInSynchronizationBeforeTransactionCompletionAreIgnored()
116-
{
117-
Assert.IsTrue(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
118-
119-
var c = new C { ID = 1, Value = "value" };
120-
121-
var synchronization = new SynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();
122-
using (ISession s = sessions.OpenSession())
123-
using (ITransaction t = s.BeginTransaction())
124-
{
125-
t.RegisterSynchronization(synchronization);
126-
127-
s.Save(c);
128-
129-
Assert.DoesNotThrow(t.Commit);
130-
}
131-
132-
using (ISession s = sessions.OpenSession())
133-
{
134-
var objectInDb = s.Get<C>(1);
135-
136-
Assert.IsNotNull(objectInDb);
137-
138-
s.Delete(objectInDb);
139-
s.Flush();
140-
}
141-
}
142-
}
14361
}

src/NHibernate.Test/NHSpecificTest/NH1159/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void DoesNotFlushWithCriteriaWithNever()
6969
using (ISession session = OpenSession(new HibernateInterceptor()))
7070
using (ITransaction tran = session.BeginTransaction())
7171
{
72-
session.FlushMode = FlushMode.Never;
72+
session.FlushMode = FlushMode.Manual;
7373
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(0));
7474
Contact contact = session.Get<Contact>((Int64)1);
7575
contact.PreferredName = "Updated preferred name";

src/NHibernate.Test/NHSpecificTest/NH1632/Fixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void When_commiting_items_in_DTC_transaction_will_add_items_to_2nd_level_
106106

107107
using (var tx = new TransactionScope())
108108
{
109-
using (var s = sessions.OpenSession(connection))
109+
using (var s = sessions.WithOptions().Connection(connection).OpenSession())
110110
{
111111
var nums = s.Load<Nums>(29);
112112
Assert.AreEqual(1, nums.NumA);
@@ -156,7 +156,7 @@ public void Will_not_save_when_flush_mode_is_never()
156156
{
157157
using (ISession s = sessions.OpenSession())
158158
{
159-
s.FlushMode = FlushMode.Never;
159+
s.FlushMode = FlushMode.Manual;
160160
id = s.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
161161
}
162162
tx.Complete();

src/NHibernate.Test/NHSpecificTest/NH1714/SimpleReproductionFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void DbCommandsFromEventListenerShouldBeEnlistedInRunningTransaction()
2222
var entity = new DomainClass();
2323
session.Save(entity);
2424

25-
using (var otherSession = session.GetChildSession())
25+
using (var otherSession = session.SessionWithOptions().Connection().OpenSession())
2626
{
2727
otherSession.Save(new DomainClass());
2828
otherSession.Flush();

src/NHibernate.Test/NHSpecificTest/NH1714/UseCaseDemonstrationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public bool OnPreInsert(PreInsertEvent e)
6060
return false;
6161

6262
// this will join into the parent's transaction
63-
using (var session = e.Session.GetChildSession())
63+
using (var session = e.Session.SessionWithOptions().Connection().OpenSession())
6464
{
6565
//should insert log record here
6666
session.Save(new LogClass());

src/NHibernate.Test/NHSpecificTest/NH2374/NH2374Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void OneToOne_with_EntityMode_Map()
1313

1414
using (ISession sroot = OpenSession())
1515
{
16-
using (ISession s = sroot.GetChildSession())
16+
using (ISession s = sroot.SessionWithOptions().Connection().OpenSession())
1717
{
1818
using (ITransaction t = s.BeginTransaction())
1919
{

src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void ShouldBeAbleToReleaseSuppliedConnectionAfterDistributedTransaction()
7373
using (connection)
7474
{
7575
connection.Open();
76-
using (s = Sfi.OpenSession(connection))
76+
using (s = Sfi.WithOptions().Connection(connection).OpenSession())
7777
{
7878
s.Save(new MyTable { String = "hello!" });
7979
}

src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public void GetChildSession_ShouldReturnNonDisposedInstance()
1414
{
1515
using (var rootSession = OpenSession())
1616
{
17-
using (var childSession1 = rootSession.GetChildSession())
17+
using (var childSession1 = rootSession.SessionWithOptions().Connection().OpenSession())
1818
{
1919
}
2020

21-
using (var childSession2 = rootSession.GetChildSession())
21+
using (var childSession2 = rootSession.SessionWithOptions().Connection().OpenSession())
2222
{
2323
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
2424
}
@@ -30,10 +30,10 @@ public void GetChildSession_ShouldReturnNonClosedInstance()
3030
{
3131
using (var rootSession = OpenSession())
3232
{
33-
var childSession1 = rootSession.GetChildSession();
33+
var childSession1 = rootSession.SessionWithOptions().Connection().OpenSession();
3434
childSession1.Close();
3535

36-
using (var childSession2 = rootSession.GetChildSession())
36+
using (var childSession2 = rootSession.SessionWithOptions().Connection().OpenSession())
3737
{
3838
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
3939
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,8 @@
14201420
<Compile Include="ReadOnly\StudentDto.cs" />
14211421
<Compile Include="ReadOnly\TextHolder.cs" />
14221422
<Compile Include="ReadOnly\VersionedNode.cs" />
1423+
<Compile Include="SessionBuilder\Entity.cs" />
1424+
<Compile Include="SessionBuilder\Fixture.cs" />
14231425
<Compile Include="SqlCommandTest\SqlTokenizerFixture.cs" />
14241426
<Compile Include="RecordingInterceptor.cs" />
14251427
<Compile Include="Stateless\Contact.cs" />
@@ -3269,6 +3271,7 @@
32693271
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
32703272
</ItemGroup>
32713273
<ItemGroup>
3274+
<EmbeddedResource Include="SessionBuilder\Mappings.hbm.xml" />
32723275
<EmbeddedResource Include="NHSpecificTest\NH1904\StructMappings.hbm.xml" />
32733276
<EmbeddedResource Include="Insertordering\FamilyModel\Mappings.hbm.xml" />
32743277
<EmbeddedResource Include="Insertordering\AnimalModel\Mappings.hbm.xml" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.SessionBuilder
4+
{
5+
class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)