Skip to content

Reuse SchemaExport in CreateSchema/DropSchema in tests #1519

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 3 commits into from
Jan 11, 2018
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
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH1635/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
protected override void CreateSchema()
{
var script = new StringBuilder();
new SchemaExport(cfg).Create(sl=> script.Append(sl) , true);
SchemaExport.Create(sl => script.Append(sl), true);
Assert.That(script.ToString(), Does.Not.Contain("LatestMessage"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Async/NHSpecificTest/NH1939/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task Can_Parameterise_Auxiliary_Database_ObjectsAsync()
{
schemaBuilder = new StringBuilder();

SchemaExport schemaExport = new SchemaExport(cfg);
SchemaExport schemaExport = SchemaExport;
await (schemaExport.ExecuteAsync(AddString, false, false));

string schema = schemaBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ protected override void OnSetUp()
}
}

private object SchemaExport(NHibernate.Cfg.Configuration cfg)
{
throw new NotImplementedException();
}

protected override void OnTearDown()
{
base.OnTearDown();
Expand Down Expand Up @@ -161,4 +156,4 @@ public async Task MultiCriteriaQueriesWithStringsShouldExecuteCorrectlyAsync()
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/NH1635/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void CleanUp()
protected override void CreateSchema()
{
var script = new StringBuilder();
new SchemaExport(cfg).Create(sl=> script.Append(sl) , true);
SchemaExport.Create(sl => script.Append(sl), true);
Assert.That(script.ToString(), Does.Not.Contain("LatestMessage"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/NH1939/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Can_Parameterise_Auxiliary_Database_Objects()
{
schemaBuilder = new StringBuilder();

SchemaExport schemaExport = new SchemaExport(cfg);
SchemaExport schemaExport = SchemaExport;
schemaExport.Execute(AddString, false, false);

string schema = schemaBuilder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ protected override void OnSetUp()
}
}

private object SchemaExport(NHibernate.Cfg.Configuration cfg)
{
throw new NotImplementedException();
}

protected override void OnTearDown()
{
base.OnTearDown();
Expand Down Expand Up @@ -150,4 +145,4 @@ public void MultiCriteriaQueriesWithStringsShouldExecuteCorrectly()
}
}
}
}
}
8 changes: 6 additions & 2 deletions src/NHibernate.Test/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public abstract class TestCase
private const bool OutputDdl = false;
protected Configuration cfg;
private DebugSessionFactory _sessionFactory;
private SchemaExport _schemaExport;

private static readonly ILog log = LogManager.GetLogger(typeof(TestCase));

Expand All @@ -48,6 +49,8 @@ protected virtual string MappingsAssembly
get { return "NHibernate.DomainModel"; }
}

protected SchemaExport SchemaExport => _schemaExport ?? (_schemaExport = new SchemaExport(cfg));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NHSpecificTest\NH2195\SQLiteMultiCriteriaTest.cs(35,18): warning CS0108: 'SQLiteMultiCriteriaTest.SchemaExport(Configuration)' hides inherited member 'TestCase.SchemaExport'. Use the new keyword if hiding was intended.

Release build will fail. Maybe is it time to enable warning as error in the test project debug config too.


static TestCase()
{
// Configure log4net here since configuration through an attribute doesn't always work.
Expand Down Expand Up @@ -281,12 +284,12 @@ protected virtual void AddMappings(Configuration configuration)

protected virtual void CreateSchema()
{
new SchemaExport(cfg).Create(OutputDdl, true);
SchemaExport.Create(OutputDdl, true);
}

protected virtual void DropSchema()
{
DropSchema(OutputDdl, new SchemaExport(cfg), Sfi);
DropSchema(OutputDdl, SchemaExport, Sfi);
}

public static void DropSchema(bool useStdOut, SchemaExport export, ISessionFactoryImplementor sfi)
Expand Down Expand Up @@ -315,6 +318,7 @@ private void Cleanup()
Sfi?.Close();
_sessionFactory = null;
cfg = null;
_schemaExport = null;
}

public int ExecuteStatement(string sql)
Expand Down
7 changes: 3 additions & 4 deletions src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ public partial class SchemaExport
return ExecuteAsync(null, execute, true, exportOutput, cancellationToken);
}

private async Task ExecuteAsync(Action<string> scriptAction, bool execute, bool throwOnError, TextWriter exportOutput,
private async Task ExecuteInitializedAsync(Action<string> scriptAction, bool execute, bool throwOnError, TextWriter exportOutput,
DbCommand statement, string sql, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
await (InitializeAsync(cancellationToken)).ConfigureAwait(false);
try
{
string formatted = formatter.Format(sql);
Expand Down Expand Up @@ -268,14 +267,14 @@ public async Task ExecuteAsync(Action<string> scriptAction, bool execute, bool j
{
for (int i = 0; i < dropSQL.Length; i++)
{
await (ExecuteAsync(scriptAction, execute, false, exportOutput, statement, dropSQL[i], cancellationToken)).ConfigureAwait(false);
await (ExecuteInitializedAsync(scriptAction, execute, false, exportOutput, statement, dropSQL[i], cancellationToken)).ConfigureAwait(false);
}

if (!justDrop)
{
for (int j = 0; j < createSQL.Length; j++)
{
await (ExecuteAsync(scriptAction, execute, true, exportOutput, statement, createSQL[j], cancellationToken)).ConfigureAwait(false);
await (ExecuteInitializedAsync(scriptAction, execute, true, exportOutput, statement, createSQL[j], cancellationToken)).ConfigureAwait(false);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/NHibernate/Tool/hbm2ddl/SchemaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ public void Drop(TextWriter exportOutput, bool execute)
Execute(null, execute, true, exportOutput);
}

private void Execute(Action<string> scriptAction, bool execute, bool throwOnError, TextWriter exportOutput,
private void ExecuteInitialized(Action<string> scriptAction, bool execute, bool throwOnError, TextWriter exportOutput,
DbCommand statement, string sql)
{
Initialize();
try
{
string formatted = formatter.Format(sql);
Expand Down Expand Up @@ -272,14 +271,14 @@ public void Execute(Action<string> scriptAction, bool execute, bool justDrop, Db
{
for (int i = 0; i < dropSQL.Length; i++)
{
Execute(scriptAction, execute, false, exportOutput, statement, dropSQL[i]);
ExecuteInitialized(scriptAction, execute, false, exportOutput, statement, dropSQL[i]);
}

if (!justDrop)
{
for (int j = 0; j < createSQL.Length; j++)
{
Execute(scriptAction, execute, true, exportOutput, statement, createSQL[j]);
ExecuteInitialized(scriptAction, execute, true, exportOutput, statement, createSQL[j]);
}
}
}
Expand Down