Skip to content

Commit 97052bb

Browse files
Tests: check session factory before creating schema. (#700)
1 parent 2fa35fc commit 97052bb

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

src/NHibernate.Test/Async/NHSpecificTest/LoadingNullEntityInSet/Fixture.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ protected override DebugSessionFactory BuildSessionFactory()
3838
.CollectionTable.Name = "WantedProfessions";
3939
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
4040
.CollectionTable.Name = "WantedProfessions";
41-
return base.BuildSessionFactory();
42-
}
43-
44-
protected override void OnTearDown()
45-
{
46-
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Primaries")
47-
.CollectionTable.Name = "WantedProfessions_DUMMY_1";
48-
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
49-
.CollectionTable.Name = "WantedProfessions_DUMMY_2";
50-
base.OnTearDown();
41+
try
42+
{
43+
return base.BuildSessionFactory();
44+
}
45+
finally
46+
{
47+
// Restore configuration.
48+
Configure();
49+
}
5150
}
5251

5352
[Test]

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ protected override DebugSessionFactory BuildSessionFactory()
2727
.CollectionTable.Name = "WantedProfessions";
2828
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
2929
.CollectionTable.Name = "WantedProfessions";
30-
return base.BuildSessionFactory();
31-
}
32-
33-
protected override void OnTearDown()
34-
{
35-
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Primaries")
36-
.CollectionTable.Name = "WantedProfessions_DUMMY_1";
37-
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
38-
.CollectionTable.Name = "WantedProfessions_DUMMY_2";
39-
base.OnTearDown();
30+
try
31+
{
32+
return base.BuildSessionFactory();
33+
}
34+
finally
35+
{
36+
// Restore configuration.
37+
Configure();
38+
}
4039
}
4140

4241
[Test]

src/NHibernate.Test/TestCase.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,12 @@ public void TestFixtureSetUp()
6868
Assert.Ignore(GetType() + " does not apply to " + Dialect);
6969
}
7070

71-
CreateSchema();
72-
try
71+
_sessionFactory = BuildSessionFactory();
72+
if (!AppliesTo(_sessionFactory))
7373
{
74-
_sessionFactory = BuildSessionFactory();
75-
if (!AppliesTo(_sessionFactory))
76-
{
77-
Assert.Ignore(GetType() + " does not apply with the current session-factory configuration");
78-
}
79-
}
80-
catch
81-
{
82-
DropSchema();
83-
throw;
74+
Assert.Ignore(GetType() + " does not apply with the current session-factory configuration");
8475
}
76+
CreateSchema();
8577
}
8678
catch (Exception e)
8779
{
@@ -116,7 +108,8 @@ public void TestFixtureTearDown()
116108
if (!AppliesTo(Dialect))
117109
return;
118110

119-
DropSchema();
111+
if (AppliesTo(_sessionFactory))
112+
DropSchema();
120113
Cleanup();
121114
}
122115
}
@@ -261,7 +254,10 @@ private bool CheckConnectionsWereClosed()
261254
return false;
262255
}
263256

264-
private void Configure()
257+
/// <summary>
258+
/// (Re)Create the configuration.
259+
/// </summary>
260+
protected void Configure()
265261
{
266262
cfg = TestConfigurationHelper.GetDefaultConfiguration();
267263

0 commit comments

Comments
 (0)