Skip to content

Commit

Permalink
Change pre-open to opening
Browse files Browse the repository at this point in the history
  • Loading branch information
pleb committed Jun 23, 2022
1 parent f74cffb commit afe343c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions PetaPoco.Tests.Unit/DatabaseConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ public void UsingConnectionClosing_AfterCreate_InstanceShouldHaveDelegate()
}

[Fact]
public void UsingConnectionPreOpened_AfterCreate_InstanceShouldHaveDelegate()
public void UsingConnectionOpening_AfterCreate_InstanceShouldHaveDelegate()
{
bool eventFired = false;
EventHandler<DbConnectionEventArgs> handler = (sender, args) => eventFired = true;

var db = config.UsingConnectionString("cs").UsingProvider<SqlServerDatabaseProvider>().UsingConnectionOpened(handler).Create();

(db as Database).OnConnectionPreOpened(null);
(db as Database).OnConnectionOpening(null);
eventFired.ShouldBeTrue();
}

Expand All @@ -294,7 +294,7 @@ public void UsingConnectionOpened_AfterCreate_InstanceShouldHaveDelegate()
bool eventFired = false;
EventHandler<DbConnectionEventArgs> handler = (sender, args) => eventFired = true;

var db = config.UsingConnectionString("cs").UsingProvider<SqlServerDatabaseProvider>().UsingConnectionPreOpened(handler).Create();
var db = config.UsingConnectionString("cs").UsingProvider<SqlServerDatabaseProvider>().UsingConnectionOpening(handler).Create();

(db as Database).OnConnectionOpened(null);
eventFired.ShouldBeTrue();
Expand Down
10 changes: 5 additions & 5 deletions PetaPoco/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public Database(IDatabaseBuildConfiguration configuration)
settings.TryGetSetting<int>(DatabaseConfigurationExtensions.CommandTimeout, v => CommandTimeout = v);
settings.TryGetSetting<IsolationLevel>(DatabaseConfigurationExtensions.IsolationLevel, v => IsolationLevel = v);

settings.TryGetSetting<EventHandler<DbConnectionEventArgs>>(DatabaseConfigurationExtensions.ConnectionPreOpened, v => ConnectionPreOpened += v);
settings.TryGetSetting<EventHandler<DbConnectionEventArgs>>(DatabaseConfigurationExtensions.ConnectionOpening, v => ConnectionOpening += v);
settings.TryGetSetting<EventHandler<DbConnectionEventArgs>>(DatabaseConfigurationExtensions.ConnectionOpened, v => ConnectionOpened += v);
settings.TryGetSetting<EventHandler<DbConnectionEventArgs>>(DatabaseConfigurationExtensions.ConnectionClosing, v => ConnectionClosing += v);
settings.TryGetSetting<EventHandler<DbTransactionEventArgs>>(DatabaseConfigurationExtensions.TransactionStarted, v => TransactionStarted += v);
Expand Down Expand Up @@ -346,7 +346,7 @@ public void OpenSharedConnection()
_sharedConnection = _factory.CreateConnection();
_sharedConnection.ConnectionString = _connectionString;

_sharedConnection = OnConnectionPreOpened(_sharedConnection);
_sharedConnection = OnConnectionOpening(_sharedConnection);

if (_sharedConnection.State == ConnectionState.Broken)
_sharedConnection.Close();
Expand Down Expand Up @@ -801,10 +801,10 @@ public virtual IDbConnection OnConnectionOpened(IDbConnection conn)
/// Override this method to provide custom logging of opening connection, or
/// to provide a proxy IDbConnection.
/// </remarks>
public virtual IDbConnection OnConnectionPreOpened(IDbConnection conn)
public virtual IDbConnection OnConnectionOpening(IDbConnection conn)
{
var args = new DbConnectionEventArgs(conn);
ConnectionPreOpened?.Invoke(this, args);
ConnectionOpening?.Invoke(this, args);
return args.Connection;
}

Expand Down Expand Up @@ -3153,7 +3153,7 @@ private async Task<object> CommandHelper(CancellationToken cancellationToken, Db
/// <summary>
/// Occurs when a database connection is about to be opened.
/// </summary>
public event EventHandler<DbConnectionEventArgs> ConnectionPreOpened;
public event EventHandler<DbConnectionEventArgs> ConnectionOpening;

/// <summary>
/// Occurs when a database exception has been thrown.
Expand Down
6 changes: 3 additions & 3 deletions PetaPoco/DatabaseConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class DatabaseConfigurationExtensions
internal const string TransactionEnding = "TransactionEnding";
internal const string CommandExecuting = "CommandExecuting";
internal const string CommandExecuted = "CommandExecuted";
internal const string ConnectionPreOpened = "ConnectionPreOpened";
internal const string ConnectionOpening = "ConnectionOpening";
internal const string ConnectionOpened = "ConnectionOpened";
internal const string ConnectionClosing = "ConnectionClosing";
internal const string ExceptionThrown = "ExceptionThrown";
Expand Down Expand Up @@ -359,9 +359,9 @@ public static IDatabaseBuildConfiguration UsingCommandExecuted(this IDatabaseBui
/// <param name="source">The configuration source.</param>
/// <param name="handler"></param>
/// <returns>The configuration source, to form a fluent interface.</returns>
public static IDatabaseBuildConfiguration UsingConnectionPreOpened(this IDatabaseBuildConfiguration source, EventHandler<DbConnectionEventArgs> handler)
public static IDatabaseBuildConfiguration UsingConnectionOpening(this IDatabaseBuildConfiguration source, EventHandler<DbConnectionEventArgs> handler)
{
source.SetSetting(ConnectionPreOpened, handler);
source.SetSetting(ConnectionOpening, handler);
return source;
}

Expand Down

0 comments on commit afe343c

Please sign in to comment.