Skip to content

NH-4003 - porting ISessionCreationOptions #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,24 @@ public void SuppliedConnection()
{
Prepare();

DbConnection originalConnection = sessions.ConnectionProvider.GetConnection();
ISession session = sessions.OpenSession(originalConnection);

Silly silly = new Silly("silly");
session.Save(silly);
using (var originalConnection = sessions.ConnectionProvider.GetConnection())
using (var session = sessions.WithOptions().Connection(originalConnection).OpenSession())
{
var silly = new Silly("silly");
session.Save(silly);

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

Assert.IsTrue(originalConnection == session.Connection, "Different connections");
Assert.IsTrue(originalConnection == session.Connection, "Different connections");

session.Delete(silly);
session.Flush();
session.Delete(silly);
session.Flush();

Release(session);
originalConnection.Close();
Release(session);
originalConnection.Close();
}
Done();
}

Expand Down
38 changes: 22 additions & 16 deletions src/NHibernate.Test/Legacy/FooBarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void WierdSession()

using (ISession s = OpenSession())
{
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;
using (ITransaction t = s.BeginTransaction())
{
Foo foo = (Foo) s.Get(typeof(Foo), id);
Expand Down Expand Up @@ -4977,21 +4977,27 @@ public void AutoFlushCollections()
[Test]
public void UserProvidedConnection()
{
IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties);
ISession s = sessions.OpenSession(prov.GetConnection());
ITransaction tx = s.BeginTransaction();
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
tx.Commit();

var c = s.Disconnect();
Assert.IsNotNull(c);
using (var prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties))
using (var connection = prov.GetConnection())
using (var s = sessions.WithOptions().Connection(connection).OpenSession())
{
using (var tx = s.BeginTransaction())
{
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
tx.Commit();
}
var c = s.Disconnect();
Assert.IsNotNull(c);

s.Reconnect(c);
tx = s.BeginTransaction();
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
tx.Commit();
Assert.AreSame(c, s.Close());
c.Close();
s.Reconnect(c);
using (var tx = s.BeginTransaction())
{
s.CreateQuery("from foo in class NHibernate.DomainModel.Fo").List();
tx.Commit();
}
Assert.AreSame(c, s.Close());
c.Close();
}
}

[Test]
Expand Down Expand Up @@ -5181,7 +5187,7 @@ public void EmbeddedCompositeID()
s.Close();

s = OpenSession();
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;
l =
(Location)
s.CreateQuery("from l in class Location where l.CountryCode = 'AU' and l.Description='foo bar'").List()[0];
Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate.Test/Legacy/FumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public void UnflushedSessionSerialization()
// instead of just the usual openSession()
using (ISession s = sessions.OpenSession())
{
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;

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

using (ISession s = sessions.OpenSession())
{
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;
Simple simple = (Simple) s.Get(typeof(Simple), 10L);
Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");
Expand All @@ -679,7 +679,7 @@ public void UnflushedSessionSerialization()
// Test deletions across serializations
using (ISession s = sessions.OpenSession())
{
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;
Simple simple = (Simple) s.Get(typeof(Simple), 10L);
Assert.AreEqual(check.Name, simple.Name, "Not same parent instances");
Assert.AreEqual(check.Other.Name, other.Name, "Not same child instances");
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/EmptyMappingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void InvalidQuery()
public void NullInterceptor()
{
IInterceptor nullInterceptor = null;
Assert.Throws<ArgumentNullException>(() => sessions.OpenSession(nullInterceptor).Close());
Assert.Throws<ArgumentNullException>(() => sessions.WithOptions().Interceptor(nullInterceptor).OpenSession().Close());
}

[Test]
Expand Down
86 changes: 2 additions & 84 deletions src/NHibernate.Test/NHSpecificTest/NH1082/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ public override string BugNumber
[Test]
public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
{
#pragma warning disable 618
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
#pragma warning restore 618

var c = new C {ID = 1, Value = "value"};

var sessionInterceptor = new SessionInterceptorThatThrowsExceptionAtBeforeTransactionCompletion();
using (ISession s = sessions.OpenSession(sessionInterceptor))
using (ITransaction t = s.BeginTransaction())
using (var s = sessions.WithOptions().Interceptor(sessionInterceptor).OpenSession())
using (var t = s.BeginTransaction())
{
s.Save(c);

Expand All @@ -42,10 +38,6 @@ public void ExceptionsInBeforeTransactionCompletionAbortTransaction()
[Test]
public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransaction()
{
#pragma warning disable 618
Assert.IsFalse(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);
#pragma warning restore 618

var c = new C { ID = 1, Value = "value" };

var synchronization = new SynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();
Expand All @@ -66,78 +58,4 @@ public void ExceptionsInSynchronizationBeforeTransactionCompletionAbortTransacti
}
}
}


[TestFixture]
[Obsolete("Can be removed when Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions is removed.")]
public class OldBehaviorEnabledFixture : BugTestCase
{
public override string BugNumber
{
get { return "NH1082"; }
}

protected override void Configure(Configuration configuration)
{
configuration.SetProperty(Environment.InterceptorsBeforeTransactionCompletionIgnoreExceptions, "true");
base.Configure(configuration);
}

[Test]
public void ExceptionsInBeforeTransactionCompletionAreIgnored()
{
Assert.IsTrue(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);

var c = new C {ID = 1, Value = "value"};

var sessionInterceptor = new SessionInterceptorThatThrowsExceptionAtBeforeTransactionCompletion();
using (ISession s = sessions.OpenSession(sessionInterceptor))
using (ITransaction t = s.BeginTransaction())
{
s.Save(c);

Assert.DoesNotThrow(t.Commit);
}

using (ISession s = sessions.OpenSession())
{
var objectInDb = s.Get<C>(1);

Assert.IsNotNull(objectInDb);

s.Delete(objectInDb);
s.Flush();
}
}


[Test]
public void ExceptionsInSynchronizationBeforeTransactionCompletionAreIgnored()
{
Assert.IsTrue(sessions.Settings.IsInterceptorsBeforeTransactionCompletionIgnoreExceptionsEnabled);

var c = new C { ID = 1, Value = "value" };

var synchronization = new SynchronizationThatThrowsExceptionAtBeforeTransactionCompletion();
using (ISession s = sessions.OpenSession())
using (ITransaction t = s.BeginTransaction())
{
t.RegisterSynchronization(synchronization);

s.Save(c);

Assert.DoesNotThrow(t.Commit);
}

using (ISession s = sessions.OpenSession())
{
var objectInDb = s.Get<C>(1);

Assert.IsNotNull(objectInDb);

s.Delete(objectInDb);
s.Flush();
}
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/NH1159/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void DoesNotFlushWithCriteriaWithNever()
using (ISession session = OpenSession(new HibernateInterceptor()))
using (ITransaction tran = session.BeginTransaction())
{
session.FlushMode = FlushMode.Never;
session.FlushMode = FlushMode.Manual;
Assert.That(HibernateInterceptor.CallCount, Is.EqualTo(0));
Contact contact = session.Get<Contact>((Int64)1);
contact.PreferredName = "Updated preferred name";
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate.Test/NHSpecificTest/NH1632/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void When_commiting_items_in_DTC_transaction_will_add_items_to_2nd_level_

using (var tx = new TransactionScope())
{
using (var s = sessions.OpenSession(connection))
using (var s = sessions.WithOptions().Connection(connection).OpenSession())
{
var nums = s.Load<Nums>(29);
Assert.AreEqual(1, nums.NumA);
Expand Down Expand Up @@ -156,7 +156,7 @@ public void Will_not_save_when_flush_mode_is_never()
{
using (ISession s = sessions.OpenSession())
{
s.FlushMode = FlushMode.Never;
s.FlushMode = FlushMode.Manual;
id = s.Save(new Nums { NumA = 1, NumB = 2, ID = 5 });
}
tx.Complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void DbCommandsFromEventListenerShouldBeEnlistedInRunningTransaction()
var entity = new DomainClass();
session.Save(entity);

using (var otherSession = session.GetChildSession())
using (var otherSession = session.SessionWithOptions().Connection().OpenSession())
{
otherSession.Save(new DomainClass());
otherSession.Flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public bool OnPreInsert(PreInsertEvent e)
return false;

// this will join into the parent's transaction
using (var session = e.Session.GetChildSession())
using (var session = e.Session.SessionWithOptions().Connection().OpenSession())
{
//should insert log record here
session.Save(new LogClass());
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/NH2374/NH2374Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void OneToOne_with_EntityMode_Map()

using (ISession sroot = OpenSession())
{
using (ISession s = sroot.GetChildSession())
using (ISession s = sroot.SessionWithOptions().Connection().OpenSession())
{
using (ITransaction t = s.BeginTransaction())
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/NH2420/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void ShouldBeAbleToReleaseSuppliedConnectionAfterDistributedTransaction()
using (connection)
{
connection.Open();
using (s = Sfi.OpenSession(connection))
using (s = Sfi.WithOptions().Connection(connection).OpenSession())
{
s.Save(new MyTable { String = "hello!" });
}
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public void GetChildSession_ShouldReturnNonDisposedInstance()
{
using (var rootSession = OpenSession())
{
using (var childSession1 = rootSession.GetChildSession())
using (var childSession1 = rootSession.SessionWithOptions().Connection().OpenSession())
{
}

using (var childSession2 = rootSession.GetChildSession())
using (var childSession2 = rootSession.SessionWithOptions().Connection().OpenSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
Expand All @@ -30,10 +30,10 @@ public void GetChildSession_ShouldReturnNonClosedInstance()
{
using (var rootSession = OpenSession())
{
var childSession1 = rootSession.GetChildSession();
var childSession1 = rootSession.SessionWithOptions().Connection().OpenSession();
childSession1.Close();

using (var childSession2 = rootSession.GetChildSession())
using (var childSession2 = rootSession.SessionWithOptions().Connection().OpenSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,8 @@
<Compile Include="ReadOnly\StudentDto.cs" />
<Compile Include="ReadOnly\TextHolder.cs" />
<Compile Include="ReadOnly\VersionedNode.cs" />
<Compile Include="SessionBuilder\Entity.cs" />
<Compile Include="SessionBuilder\Fixture.cs" />
<Compile Include="SqlCommandTest\SqlTokenizerFixture.cs" />
<Compile Include="RecordingInterceptor.cs" />
<Compile Include="Stateless\Contact.cs" />
Expand Down Expand Up @@ -3269,6 +3271,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="SessionBuilder\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1904\StructMappings.hbm.xml" />
<EmbeddedResource Include="Insertordering\FamilyModel\Mappings.hbm.xml" />
<EmbeddedResource Include="Insertordering\AnimalModel\Mappings.hbm.xml" />
Expand Down
10 changes: 10 additions & 0 deletions src/NHibernate.Test/SessionBuilder/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace NHibernate.Test.SessionBuilder
{
class Entity
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
}
}
Loading