forked from dotnet/SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix | Fix issue with SqlCommand OnStatementCompleted event not being …
…triggered (dotnet#216)
- Loading branch information
1 parent
a9279ac
commit 3ed8f60
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlCommand/SqlCommandCompletedTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Data; | ||
using Xunit; | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public static class SqlCommandCompletedTest | ||
{ | ||
private static readonly string s_connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { PacketSize = 512 }).ConnectionString; | ||
private static int completedHandlerExecuted = 0; | ||
|
||
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] | ||
public static void VerifyStatmentCompletedCalled() | ||
{ | ||
string tableName = DataTestUtility.GetUniqueNameForSqlServer("stmt"); | ||
|
||
using (var conn = new SqlConnection(s_connStr)) | ||
using (var cmd = conn.CreateCommand()) | ||
{ | ||
try | ||
{ | ||
cmd.StatementCompleted += StatementCompletedHandler; | ||
conn.Open(); | ||
|
||
cmd.CommandText = $"CREATE TABLE {tableName} (c1 int)"; | ||
var res = cmd.ExecuteScalar(); | ||
|
||
cmd.CommandText = $"INSERT {tableName} VALUES(1)"; //DML (+1) | ||
res = cmd.ExecuteScalar(); | ||
|
||
cmd.CommandText = $"Update {tableName} set c1=2"; //DML (+1) | ||
res = cmd.ExecuteScalar(); | ||
|
||
cmd.CommandText = $"SELECT * from {tableName}"; //DQL (+1) | ||
res = cmd.ExecuteScalar(); | ||
|
||
cmd.CommandText = $"DELETE FROM {tableName}"; //DML (+1) | ||
res = cmd.ExecuteScalar(); | ||
} | ||
finally | ||
{ | ||
cmd.CommandText = $"DROP TABLE {tableName}"; | ||
var res = cmd.ExecuteScalar(); | ||
} | ||
} | ||
// DDL and DQL queries that return DoneRowCount are accounted here. | ||
Assert.True(completedHandlerExecuted == 4); | ||
} | ||
|
||
private static void StatementCompletedHandler(object sender, StatementCompletedEventArgs args) | ||
{ | ||
// Increment on event pass through | ||
completedHandlerExecuted++; | ||
} | ||
} | ||
} |