Skip to content

Tests: check session factory before creating schema. #700

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
Sep 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ protected override DebugSessionFactory BuildSessionFactory()
.CollectionTable.Name = "WantedProfessions";
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
.CollectionTable.Name = "WantedProfessions";
return base.BuildSessionFactory();
}

protected override void OnTearDown()
{
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Primaries")
.CollectionTable.Name = "WantedProfessions_DUMMY_1";
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
.CollectionTable.Name = "WantedProfessions_DUMMY_2";
base.OnTearDown();
try
{
return base.BuildSessionFactory();
}
finally
{
// Restore configuration.
Configure();
}
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ protected override DebugSessionFactory BuildSessionFactory()
.CollectionTable.Name = "WantedProfessions";
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
.CollectionTable.Name = "WantedProfessions";
return base.BuildSessionFactory();
}

protected override void OnTearDown()
{
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Primaries")
.CollectionTable.Name = "WantedProfessions_DUMMY_1";
cfg.GetCollectionMapping(typeof (Employee).FullName + ".Secondaries")
.CollectionTable.Name = "WantedProfessions_DUMMY_2";
base.OnTearDown();
try
{
return base.BuildSessionFactory();
}
finally
{
// Restore configuration.
Configure();
}
}

[Test]
Expand Down
24 changes: 10 additions & 14 deletions src/NHibernate.Test/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,12 @@ public void TestFixtureSetUp()
Assert.Ignore(GetType() + " does not apply to " + Dialect);
}

CreateSchema();
try
_sessionFactory = BuildSessionFactory();
if (!AppliesTo(_sessionFactory))
{
_sessionFactory = BuildSessionFactory();
if (!AppliesTo(_sessionFactory))
{
Assert.Ignore(GetType() + " does not apply with the current session-factory configuration");
}
}
catch
{
DropSchema();
throw;
Assert.Ignore(GetType() + " does not apply with the current session-factory configuration");
}
CreateSchema();
}
catch (Exception e)
{
Expand Down Expand Up @@ -116,7 +108,8 @@ public void TestFixtureTearDown()
if (!AppliesTo(Dialect))
return;

DropSchema();
if (AppliesTo(_sessionFactory))
DropSchema();
Cleanup();
}
}
Expand Down Expand Up @@ -261,7 +254,10 @@ private bool CheckConnectionsWereClosed()
return false;
}

private void Configure()
/// <summary>
/// (Re)Create the configuration.
/// </summary>
protected void Configure()
{
cfg = TestConfigurationHelper.GetDefaultConfiguration();

Expand Down