From 84108d3705108c1a6c39d1d69cd1ecb8e125e17d Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Fri, 2 Feb 2018 22:36:07 -0800 Subject: [PATCH] Use Temp tables in tests (dotnet/corefx#26805) * Move tests to use Temp tables to avoid problems with NetFx Tests * Fix indentation Commit migrated from https://github.com/dotnet/corefx/commit/a4e3009f56530e49796db10fe0e460f8eaf44ba8 --- .../SQL/AsyncTest/BeginExecAsyncTest.cs | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/BeginExecAsyncTest.cs b/src/libraries/System.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/BeginExecAsyncTest.cs index a73ccfa..79863b5 100644 --- a/src/libraries/System.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/BeginExecAsyncTest.cs +++ b/src/libraries/System.Data.SqlClient/tests/ManualTests/SQL/AsyncTest/BeginExecAsyncTest.cs @@ -2,31 +2,41 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Threading.Tasks; using Xunit; namespace System.Data.SqlClient.ManualTesting.Tests { public static class BeginExecAsyncTest { - private static string commandText = - "INSERT INTO[dbo].[Shippers] " + - "([CompanyName] " + - ",[Phone]) " + - "VALUES " + - "('Acme Inc.' " + - ",'555-1212'); " + - "WAITFOR DELAY '0:0:3';" + - "DELETE FROM dbo.Shippers WHERE ShipperID > 3;"; - + private static string GenerateCommandText() + { + int suffix = (new Random()).Next(5000); + + string commandText = + $"CREATE TABLE #Shippers{suffix}(" + + $"[ShipperID][int] NULL," + + $"[CompanyName] [nvarchar] (40) NOT NULL," + + $"[Phone] [nvarchar] (24) NULL )" + + $"INSERT INTO #Shippers{suffix}" + + $"([CompanyName] " + + $",[Phone])" + + $"VALUES " + + $"('Acme Inc.' " + + $",'555-1212'); " + + $"WAITFOR DELAY '0:0:3'; " + + $"DELETE FROM #Shippers{suffix} WHERE ShipperID > 3;"; + + return commandText; + } + [CheckConnStrSetupFact] public static void ExecuteTest() { using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr)) { try - { - SqlCommand command = new SqlCommand(commandText, connection); + { + SqlCommand command = new SqlCommand(GenerateCommandText(), connection); connection.Open(); IAsyncResult result = command.BeginExecuteNonQuery(); @@ -63,7 +73,7 @@ namespace System.Data.SqlClient.ManualTesting.Tests using (SqlConnection connection = new SqlConnection(DataTestUtility.TcpConnStr)) { bool caughtException = false; - SqlCommand command = new SqlCommand(commandText, connection); + SqlCommand command = new SqlCommand(GenerateCommandText(), connection); connection.Open(); //Try to execute a synchronous query on same command -- 2.7.4