From 9de793e770a63872f746fc44a7f187f3c740af96 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Mon, 17 Aug 2020 10:57:21 -0700 Subject: [PATCH 1/7] [Test] Add External utilities to setup and drop database to be used in tests. --- .gitignore | 2 +- build.proj | 1 + src/Microsoft.Data.SqlClient.sln | 102 +++++++++++ .../SqlConnectionStringBuilderTest.cs | 2 +- .../ManualTests/DataCommon/DataTestUtility.cs | 163 +++++------------ ....Data.SqlClient.ManualTesting.Tests.csproj | 9 +- .../SQL/ExceptionTest/ExceptionTest.cs | 7 +- .../SQL/ParameterTest/ParametersTest.cs | 1 - .../SQL/SqlBulkCopyTest/Bug84548.cs | 4 +- .../SQL/SqlBulkCopyTest/Bug85007.cs | 4 +- .../SQL/SqlBulkCopyTest/OrderHint.cs | 8 +- .../SQL/SqlBulkCopyTest/OrderHintAsync.cs | 8 +- .../OrderHintDuplicateColumn.cs | 8 +- .../OrderHintIdentityColumn.cs | 8 +- .../OrderHintMissingTargetColumn.cs | 8 +- .../SqlBulkCopyTest/OrderHintTransaction.cs | 8 +- .../SQL/SqlBulkCopyTest/SqlBulkCopyTest.cs | 92 +++++----- .../SQL/UdtTest/SqlServerTypesTest.cs | 3 +- ...crosoft.Data.SqlClient.ExtUtilities.csproj | 17 ++ .../Runner.cs | 32 ++++ .../SqlDbManager.cs | 172 ++++++++++++++++++ .../Config.cs | 54 ++++++ ...rosoft.Data.SqlClient.TestUtilities.csproj | 19 ++ .../Utils.cs | 42 +++++ .../config.default.json | 0 tools/props/Versions.props | 1 + 26 files changed, 564 insertions(+), 211 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj create mode 100644 src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs rename src/Microsoft.Data.SqlClient/tests/{ManualTests => tools/Microsoft.Data.SqlClient.TestUtilities}/config.default.json (100%) diff --git a/.gitignore b/.gitignore index a8dac2d5c7..df05bd9b0f 100644 --- a/.gitignore +++ b/.gitignore @@ -359,4 +359,4 @@ MigrationBackup/ .nuget/ # Config Json file -src/Microsoft.Data.SqlClient/tests/ManualTests/config.json +**/config.json diff --git a/build.proj b/build.proj index edebcec39e..50c7f15156 100644 --- a/build.proj +++ b/build.proj @@ -40,6 +40,7 @@ + diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index eea16852c3..e82eb25141 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -173,6 +173,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.Do EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.NSLibrary", "Microsoft.Data.SqlClient\tests\NSLibrary\Microsoft.Data.SqlClient.NSLibrary.csproj", "{E7336BFB-8521-423A-A140-3123F9065C5D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.TestUtilities", "Microsoft.Data.SqlClient\tests\tools\Microsoft.Data.SqlClient.TestUtilities\Microsoft.Data.SqlClient.TestUtilities.csproj", "{89D6D382-9B36-43C9-A912-03802FDA8E36}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.ExtUtilities", "Microsoft.Data.SqlClient\tests\tools\Microsoft.Data.SqlClient.ExtUtilities\Microsoft.Data.SqlClient.ExtUtilities.csproj", "{E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1085,6 +1089,102 @@ Global {E7336BFB-8521-423A-A140-3123F9065C5D}.Release|x64.Build.0 = Release|x64 {E7336BFB-8521-423A-A140-3123F9065C5D}.Release|x86.ActiveCfg = Release|x86 {E7336BFB-8521-423A-A140-3123F9065C5D}.Release|x86.Build.0 = Release|x86 + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|x64.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|x64.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|x86.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Debug|x86.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|Any CPU.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|x64.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|x64.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|x86.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Debug|x86.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|Any CPU.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|Any CPU.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|x64.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|x64.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|x86.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.net46-Release|x86.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|Any CPU.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|x64.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|x64.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|x86.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Debug|x86.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|Any CPU.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|Any CPU.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|x64.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|x64.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|x86.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp2.1-Release|x86.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|Any CPU.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|x64.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|x64.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|x86.ActiveCfg = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Debug|x86.Build.0 = Debug|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|Any CPU.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|Any CPU.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|x64.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|x64.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|x86.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.netcoreapp3.1-Release|x86.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|Any CPU.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|x64.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|x64.Build.0 = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|x86.ActiveCfg = Release|Any CPU + {89D6D382-9B36-43C9-A912-03802FDA8E36}.Release|x86.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|x64.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|x64.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|x86.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Debug|x86.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|Any CPU.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|x64.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|x64.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|x86.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Debug|x86.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|Any CPU.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|Any CPU.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|x64.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|x64.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|x86.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.net46-Release|x86.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|Any CPU.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|x64.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|x64.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|x86.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Debug|x86.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|Any CPU.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|Any CPU.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|x64.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|x64.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|x86.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp2.1-Release|x86.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|Any CPU.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|x64.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|x64.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|x86.ActiveCfg = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Debug|x86.Build.0 = Debug|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|Any CPU.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|Any CPU.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|x64.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|x64.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|x86.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.netcoreapp3.1-Release|x86.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|Any CPU.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x64.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x64.Build.0 = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x86.ActiveCfg = Release|Any CPU + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1117,6 +1217,8 @@ Global {5A7600BD-AED8-44AB-8F2A-7CB33A8D9C02} = {71F356DC-DFA3-4163-8BFE-D268722CE189} {833157E1-1E53-4908-B4CB-5C5507A44582} = {0CC4817A-12F3-4357-912C-09315FAAD008} {E7336BFB-8521-423A-A140-3123F9065C5D} = {0CC4817A-12F3-4357-912C-09315FAAD008} + {89D6D382-9B36-43C9-A912-03802FDA8E36} = {0CC4817A-12F3-4357-912C-09315FAAD008} + {E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B} = {0CC4817A-12F3-4357-912C-09315FAAD008} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {01D48116-37A2-4D33-B9EC-94793C702431} diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs index f0b08da092..9ba85c3312 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionStringBuilderTest.cs @@ -38,7 +38,7 @@ public class SqlConnectionStringBuilderTest [InlineData("Encrypt = true")] [InlineData("Enlist = false")] [InlineData("Initial Catalog = Northwind; Failover Partner = randomserver.sys.local")] - [InlineData("Initial Catalog = Northwind")] + [InlineData("Initial Catalog = tempdb")] [InlineData("Integrated Security = true")] [InlineData("Trusted_Connection = false")] [InlineData("Max Pool Size = 50")] diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 1e8fa398c6..46069feb18 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -13,7 +13,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Identity.Client; -using Newtonsoft.Json; +using Microsoft.Data.SqlClient.TestUtilities; using Xunit; namespace Microsoft.Data.SqlClient.ManualTesting.Tests @@ -53,101 +53,62 @@ public static class DataTestUtility public const string AKVKeyName = "TestSqlClientAzureKeyVaultProvider"; private const string ManagedNetworkingAppContextSwitch = "Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows"; - private static readonly string[] AzureSqlServerEndpoints = {".database.windows.net", - ".database.cloudapi.de", - ".database.usgovcloudapi.net", - ".database.chinacloudapi.cn"}; - private static Dictionary AvailableDatabases; private static TraceEventListener TraceListener; - private class Config - { - public string TCPConnectionString = null; - public string NPConnectionString = null; - public string TCPConnectionStringHGSVBS = null; - public string TCPConnectionStringAASVBS = null; - public string TCPConnectionStringAASSGX = null; - public string AADAuthorityURL = null; - public string AADPasswordConnectionString = null; - public string AADServicePrincipalId = null; - public string AADServicePrincipalSecret = null; - public string AzureKeyVaultURL = null; - public string AzureKeyVaultClientId = null; - public string AzureKeyVaultClientSecret = null; - public bool EnclaveEnabled = false; - public bool TracingEnabled = false; - public bool SupportsIntegratedSecurity = false; - public bool SupportsLocalDb = false; - public bool SupportsFileStream = false; - public bool UseManagedSNIOnWindows = false; - public string DNSCachingConnString = null; - public string DNSCachingServerCR = null; // this is for the control ring - public string DNSCachingServerTR = null; // this is for the tenant ring - public bool IsDNSCachingSupportedCR = false; // this is for the control ring - public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring - } - static DataTestUtility() { - using (StreamReader r = new StreamReader("config.json")) - { - string json = r.ReadToEnd(); - Config c = JsonConvert.DeserializeObject(json); - - NPConnectionString = c.NPConnectionString; - TCPConnectionString = c.TCPConnectionString; - TCPConnectionStringHGSVBS = c.TCPConnectionStringHGSVBS; - TCPConnectionStringAASVBS = c.TCPConnectionStringAASVBS; - TCPConnectionStringAASSGX = c.TCPConnectionStringAASSGX; - AADAuthorityURL = c.AADAuthorityURL; - AADPasswordConnectionString = c.AADPasswordConnectionString; - AADServicePrincipalId = c.AADServicePrincipalId; - AADServicePrincipalSecret = c.AADServicePrincipalSecret; - SupportsLocalDb = c.SupportsLocalDb; - SupportsIntegratedSecurity = c.SupportsIntegratedSecurity; - SupportsFileStream = c.SupportsFileStream; - EnclaveEnabled = c.EnclaveEnabled; - TracingEnabled = c.TracingEnabled; - UseManagedSNIOnWindows = c.UseManagedSNIOnWindows; - - DNSCachingConnString = c.DNSCachingConnString; - DNSCachingServerCR = c.DNSCachingServerCR; - DNSCachingServerTR = c.DNSCachingServerTR; - IsDNSCachingSupportedCR = c.IsDNSCachingSupportedCR; - IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR; - - if (TracingEnabled) - { - TraceListener = new DataTestUtility.TraceEventListener(); - } + Config c = Config.Load(); + NPConnectionString = c.NPConnectionString; + TCPConnectionString = c.TCPConnectionString; + TCPConnectionStringHGSVBS = c.TCPConnectionStringHGSVBS; + TCPConnectionStringAASVBS = c.TCPConnectionStringAASVBS; + TCPConnectionStringAASSGX = c.TCPConnectionStringAASSGX; + AADAuthorityURL = c.AADAuthorityURL; + AADPasswordConnectionString = c.AADPasswordConnectionString; + AADServicePrincipalId = c.AADServicePrincipalId; + AADServicePrincipalSecret = c.AADServicePrincipalSecret; + SupportsLocalDb = c.SupportsLocalDb; + SupportsIntegratedSecurity = c.SupportsIntegratedSecurity; + SupportsFileStream = c.SupportsFileStream; + EnclaveEnabled = c.EnclaveEnabled; + TracingEnabled = c.TracingEnabled; + UseManagedSNIOnWindows = c.UseManagedSNIOnWindows; + DNSCachingConnString = c.DNSCachingConnString; + DNSCachingServerCR = c.DNSCachingServerCR; + DNSCachingServerTR = c.DNSCachingServerTR; + IsDNSCachingSupportedCR = c.IsDNSCachingSupportedCR; + IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR; - if (UseManagedSNIOnWindows) - { - AppContext.SetSwitch(ManagedNetworkingAppContextSwitch, true); - Console.WriteLine($"App Context switch {ManagedNetworkingAppContextSwitch} enabled on {Environment.OSVersion}"); - } + if (TracingEnabled) + { + TraceListener = new DataTestUtility.TraceEventListener(); + } - if (IsAADPasswordConnStrSetup() && IsAADAuthorityURLSetup()) - { - string username = RetrieveValueFromConnStr(AADPasswordConnectionString, new string[] { "User ID", "UID" }); - string password = RetrieveValueFromConnStr(AADPasswordConnectionString, new string[] { "Password", "PWD" }); - AADAccessToken = GenerateAccessToken(AADAuthorityURL, username, password); - } + if (UseManagedSNIOnWindows) + { + AppContext.SetSwitch(ManagedNetworkingAppContextSwitch, true); + Console.WriteLine($"App Context switch {ManagedNetworkingAppContextSwitch} enabled on {Environment.OSVersion}"); + } - string url = c.AzureKeyVaultURL; - Uri AKVBaseUri = null; - if (!string.IsNullOrEmpty(url) && Uri.TryCreate(url, UriKind.Absolute, out AKVBaseUri)) - { - AKVBaseUri = new Uri(AKVBaseUri, "/"); - AKVBaseUrl = AKVBaseUri.AbsoluteUri; - AKVUrl = (new Uri(AKVBaseUri, $"/keys/{AKVKeyName}")).AbsoluteUri; - } + if (IsAADPasswordConnStrSetup() && IsAADAuthorityURLSetup()) + { + string username = RetrieveValueFromConnStr(AADPasswordConnectionString, new string[] { "User ID", "UID" }); + string password = RetrieveValueFromConnStr(AADPasswordConnectionString, new string[] { "Password", "PWD" }); + AADAccessToken = GenerateAccessToken(AADAuthorityURL, username, password); + } - AKVClientId = c.AzureKeyVaultClientId; - AKVClientSecret = c.AzureKeyVaultClientSecret; + string url = c.AzureKeyVaultURL; + if (!string.IsNullOrEmpty(url) && Uri.TryCreate(url, UriKind.Absolute, out Uri AKVBaseUri)) + { + AKVBaseUri = new Uri(AKVBaseUri, "/"); + AKVBaseUrl = AKVBaseUri.AbsoluteUri; + AKVUrl = (new Uri(AKVBaseUri, $"/keys/{AKVKeyName}")).AbsoluteUri; } + AKVClientId = c.AzureKeyVaultClientId; + AKVClientSecret = c.AzureKeyVaultClientSecret; + if (EnclaveEnabled) { if (!string.IsNullOrEmpty(TCPConnectionStringHGSVBS)) @@ -201,6 +162,7 @@ public static IEnumerable ConnectionStrings } } } + private static string GenerateAccessToken(string authorityURL, string aADAuthUserID, string aADAuthPassword) { return AcquireTokenAsync(authorityURL, aADAuthUserID, aADAuthPassword).Result; @@ -313,7 +275,7 @@ public static bool IsAADAuthorityURLSetup() public static bool IsNotAzureServer() { - return AreConnStringsSetup() ? !DataTestUtility.IsAzureSqlServer(new SqlConnectionStringBuilder((DataTestUtility.TCPConnectionString)).DataSource) : true; + return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder((DataTestUtility.TCPConnectionString)).DataSource); } public static bool IsAKVSetupAvailable() @@ -425,35 +387,6 @@ public static string GetAccessToken() public static bool IsFileStreamSetup() => SupportsFileStream; - // This method assumes dataSource parameter is in TCP connection string format. - public static bool IsAzureSqlServer(string dataSource) - { - int i = dataSource.LastIndexOf(','); - if (i >= 0) - { - dataSource = dataSource.Substring(0, i); - } - - i = dataSource.LastIndexOf('\\'); - if (i >= 0) - { - dataSource = dataSource.Substring(0, i); - } - - // trim redundant whitespace - dataSource = dataSource.Trim(); - - // check if servername end with any azure endpoints - for (i = 0; i < AzureSqlServerEndpoints.Length; i++) - { - if (dataSource.EndsWith(AzureSqlServerEndpoints[i], StringComparison.OrdinalIgnoreCase)) - { - return true; - } - } - return false; - } - private static bool CheckException(Exception ex, string exceptionMessage, bool innerExceptionMustBeNull) where TException : Exception { return ((ex != null) && (ex is TException) && diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj index 34bd1e6ead..01eb6aa85c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj @@ -13,9 +13,6 @@ $(ObjFolder)$(Configuration).$(Platform).$(AssemblyName) $(BinFolder)$(Configuration).$(Platform).$(AssemblyName) - - - @@ -202,10 +199,6 @@ PreserveNewest data.xml - - PreserveNewest - config.json - PreserveNewest MultipleResultsTest.bsl @@ -260,6 +253,7 @@ + Address @@ -288,7 +282,6 @@ - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs index 47b8b081de..6f7d9ad6cd 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ExceptionTest.cs @@ -57,7 +57,8 @@ private static bool EmployeesTableHasFullTextIndex() using (SqlCommand cmd = conn.CreateCommand()) { conn.Open(); - cmd.CommandText = "SELECT object_id FROM sys.fulltext_indexes WHERE object_id = object_id('Northwind.dbo.Employees')"; + string db = conn.DataSource; + cmd.CommandText = $"SELECT object_id FROM sys.fulltext_indexes WHERE object_id = object_id('{db}.dbo.Employees')"; return (cmd.ExecuteScalar() != null); } @@ -92,7 +93,7 @@ public static void WarningsBeforeRowsTest() sqlConnection.FireInfoMessageEventOnUserErrors = messagesOnErrors; // These queries should return warnings because AND here is a noise word. - SqlCommand cmd = new SqlCommand("select FirstName from Northwind.dbo.Employees where contains(FirstName, '\"Anne AND\"')" + orderClause, sqlConnection); + SqlCommand cmd = new SqlCommand("select FirstName from Employees where contains(FirstName, '\"Anne AND\"')" + orderClause, sqlConnection); using (SqlDataReader reader = cmd.ExecuteReader()) { Assert.True(reader.HasRows, "FAILED: SqlDataReader.HasRows is not correct (should be TRUE)"); @@ -107,7 +108,7 @@ public static void WarningsBeforeRowsTest() } hitWarnings = false; - cmd.CommandText = "select FirstName from Northwind.dbo.Employees where contains(FirstName, '\"NotARealPerson AND\"')" + orderClause; + cmd.CommandText = "select FirstName from Employees where contains(FirstName, '\"NotARealPerson AND\"')" + orderClause; using (SqlDataReader reader = cmd.ExecuteReader()) { Assert.False(reader.HasRows, "FAILED: SqlDataReader.HasRows is not correct (should be FALSE)"); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs index 0132b464c1..865fd62cab 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/ParametersTest.cs @@ -250,7 +250,6 @@ public static void Test_WithGuidValue_ShouldReturnGuid() public static void TestParametersWithDatatablesTVPInsert() { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString); - builder.InitialCatalog = "tempdb"; int x = 4, y = 5; DataTable table = new DataTable { Columns = { { "x", typeof(int) }, { "y", typeof(int) } }, Rows = { { x, y } } }; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs index b41feb55fc..48c65a4247 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs @@ -40,7 +40,7 @@ public static void Test(string srcConstr, string dstConstr, string targettable) srcConn.Open(); // First copy the customer ID list across - SqlCommand customerCommand = new SqlCommand("SELECT CustomerID from Northwind..Customers", srcConn); + SqlCommand customerCommand = new SqlCommand("SELECT CustomerID from Customers", srcConn); using (DbDataReader reader = customerCommand.ExecuteReader()) { using (SqlBulkCopy bulkcopy = new SqlBulkCopy(dstConn)) @@ -50,7 +50,7 @@ public static void Test(string srcConstr, string dstConstr, string targettable) } } - SqlCommand srcCmd = new SqlCommand("select OrderID, CustomerID from Northwind..Orders where OrderId = 10643", srcConn); + SqlCommand srcCmd = new SqlCommand("select OrderID, CustomerID from Orders where OrderId = 10643", srcConn); using (DbDataReader reader = srcCmd.ExecuteReader()) { using (SqlBulkCopy bulkcopy = new SqlBulkCopy(dstConn)) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs index f9983bc8d7..26d9db5bda 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs @@ -50,7 +50,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable) ") ON [PRIMARY]"); using (SqlConnection srcConn = new SqlConnection(srcConstr)) - using (SqlCommand customerCmd = new SqlCommand("SELECT CustomerID from Northwind..Customers", srcConn)) + using (SqlCommand customerCmd = new SqlCommand("SELECT CustomerID from Customers", srcConn)) { srcConn.Open(); @@ -90,7 +90,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable) ColumnMappings.Add("ShipCountry", "ShipCountry"); bulkcopy.WriteToServer(reader); - + DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 830, "Unexpected number of rows."); } Helpers.VerifyResults(dstConn, dstTable, 14, 830); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHint.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHint.cs index 7145679431..fbfbb57ecd 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHint.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHint.cs @@ -19,10 +19,8 @@ public class OrderHint private static readonly string sourceQueryTemplate2 = "SELECT LastName, FirstName FROM {0}"; private static readonly string getRowCountQueryTemplate = "SELECT COUNT(*) FROM {0}"; - public static void Test(string srcConstr, string dstTable, string dstTable2) + public static void Test(string connStr, string dstTable, string dstTable2) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); string sourceQuery2 = string.Format(sourceQueryTemplate2, sourceTable2); string initialQuery = string.Format(initialQueryTemplate, dstTable); @@ -30,13 +28,13 @@ public static void Test(string srcConstr, string dstTable, string dstTable2) string getRowCountQuery = string.Format(getRowCountQueryTemplate, sourceTable); string getRowCountQuery2 = string.Format(getRowCountQueryTemplate, sourceTable2); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { dstConn.Open(); Helpers.TryExecute(dstCmd, initialQuery); Helpers.TryExecute(dstCmd, initialQuery2); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(getRowCountQuery, srcConn)) { srcConn.Open(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintAsync.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintAsync.cs index d9c4515428..c818200864 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintAsync.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintAsync.cs @@ -27,10 +27,8 @@ public static void Test(string srcConstr, string dstTable, string dstTable2) Assert.True(t.IsCompleted, "Task did not complete! Status: " + t.Status); } - public static async Task TestAsync(string srcConstr, string dstTable, string dstTable2) + public static async Task TestAsync(string connStr, string dstTable, string dstTable2) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); string sourceQuery2 = string.Format(sourceQueryTemplate2, sourceTable2); string initialQuery = string.Format(initialQueryTemplate, dstTable); @@ -38,13 +36,13 @@ public static async Task TestAsync(string srcConstr, string dstTable, string dst string getRowCountQuery = string.Format(getRowCountQueryTemplate, sourceTable); string getRowCountQuery2 = string.Format(getRowCountQueryTemplate, sourceTable2); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { await dstConn.OpenAsync(); Helpers.TryExecute(dstCmd, initialQuery); Helpers.TryExecute(dstCmd, initialQuery2); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(getRowCountQuery, srcConn)) { await srcConn.OpenAsync(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintDuplicateColumn.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintDuplicateColumn.cs index 59e82a8a97..9e535ccae1 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintDuplicateColumn.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintDuplicateColumn.cs @@ -15,20 +15,18 @@ public class OrderHintDuplicateColumn private static readonly string sourceQueryTemplate = "SELECT CustomerID, CompanyName, ContactName FROM {0}"; private static readonly string getRowCountQueryTemplate = "SELECT COUNT(*) FROM {0}"; - public static void Test(string srcConstr, string dstTable) + public static void Test(string connStr, string dstTable) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string initialQuery = string.Format(initialQueryTemplate, dstTable); string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); string getRowCountQuery = string.Format(getRowCountQueryTemplate, sourceTable); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { dstConn.Open(); Helpers.TryExecute(dstCmd, initialQuery); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(getRowCountQuery, srcConn)) { srcConn.Open(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintIdentityColumn.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintIdentityColumn.cs index a95c13ad36..04cd1977b4 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintIdentityColumn.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintIdentityColumn.cs @@ -14,20 +14,18 @@ public class OrderHintIdentityColumn private static readonly string sourceQueryTemplate = "SELECT CustomerId, CompanyName, ContactName FROM {0}"; private static readonly string getRowCountQueryTemplate = "SELECT COUNT(*) FROM {0}"; - public static void Test(string srcConstr, string dstTable) + public static void Test(string connStr, string dstTable) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); string initialQuery = string.Format(initialQueryTemplate, dstTable); string getRowCountQuery = string.Format(getRowCountQueryTemplate, sourceTable); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { dstConn.Open(); Helpers.TryExecute(dstCmd, initialQuery); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(getRowCountQuery, srcConn)) { srcConn.Open(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintMissingTargetColumn.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintMissingTargetColumn.cs index dcfeb6e311..46a7f39eee 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintMissingTargetColumn.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintMissingTargetColumn.cs @@ -14,19 +14,17 @@ public class OrderHintMissingTargetColumn private static readonly string initialQueryTemplate = "create table {0} (CustomerID nvarchar(50), CompanyName nvarchar(50), ContactName nvarchar(50))"; private static readonly string sourceQueryTemplate = "SELECT CustomerID, CompanyName, ContactName FROM {0}"; - public static void Test(string srcConstr, string dstTable) + public static void Test(string connStr, string dstTable) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string initialQuery = string.Format(initialQueryTemplate, dstTable); string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { dstConn.Open(); Helpers.TryExecute(dstCmd, initialQuery); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(sourceQuery, srcConn)) { srcConn.Open(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintTransaction.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintTransaction.cs index 73dae137aa..94bd28b02a 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintTransaction.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/OrderHintTransaction.cs @@ -12,14 +12,12 @@ class OrderHintTransaction private static readonly string initialQueryTemplate = "create table {0} (CustomerID nvarchar(50), CompanyName nvarchar(50), ContactName nvarchar(50))"; private static readonly string sourceQueryTemplate = "SELECT CustomerID, CompanyName, ContactName FROM {0}"; - public static void Test(string srcConstr, string dstTable) + public static void Test(string connStr, string dstTable) { - srcConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "Northwind" }).ConnectionString; - string dstConstr = (new SqlConnectionStringBuilder(srcConstr)).ConnectionString; string initialQuery = string.Format(initialQueryTemplate, dstTable); string sourceQuery = string.Format(sourceQueryTemplate, sourceTable); - using (SqlConnection dstConn = new SqlConnection(dstConstr)) + using (SqlConnection dstConn = new SqlConnection(connStr)) using (SqlCommand dstCmd = dstConn.CreateCommand()) { dstConn.Open(); @@ -27,7 +25,7 @@ public static void Test(string srcConstr, string dstTable) dstCmd.Transaction = txn; Helpers.TryExecute(dstCmd, initialQuery); - using (SqlConnection srcConn = new SqlConnection(srcConstr)) + using (SqlConnection srcConn = new SqlConnection(connStr)) using (SqlCommand srcCmd = new SqlCommand(sourceQuery, srcConn)) { srcConn.Open(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/SqlBulkCopyTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/SqlBulkCopyTest.cs index 965dfde9f1..9c1d60e07c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/SqlBulkCopyTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/SqlBulkCopyTest.cs @@ -9,15 +9,13 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests { public class SqlBulkCopyTest { - private string srcConstr = null; - private string dstConstr = null; - private static bool IsAzureServer() => DataTestUtility.IsAzureSqlServer(new SqlConnectionStringBuilder((DataTestUtility.TCPConnectionString)).DataSource); + private string _connStr = null; + private static bool IsAzureServer() => !DataTestUtility.IsNotAzureServer(); private static bool AreConnectionStringsSetup() => DataTestUtility.AreConnStringsSetup(); public SqlBulkCopyTest() { - srcConstr = DataTestUtility.TCPConnectionString; - dstConstr = (new SqlConnectionStringBuilder(srcConstr) { InitialCatalog = "tempdb" }).ConnectionString; + _connStr = DataTestUtility.TCPConnectionString; } public string AddGuid(string stringin) @@ -35,254 +33,254 @@ public void AzureDistributedTransactionTest() [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyAllFromReaderTest() { - CopyAllFromReader.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopyAllFromReader")); + CopyAllFromReader.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopyAllFromReader")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyAllFromReader1Test() { - CopyAllFromReader1.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopyAllFromReader1")); + CopyAllFromReader1.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopyAllFromReader1")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyMultipleReadersTest() { - CopyMultipleReaders.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopyMultipleReaders")); + CopyMultipleReaders.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopyMultipleReaders")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopySomeFromReaderTest() { - CopySomeFromReader.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopySomeFromReader")); + CopySomeFromReader.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopySomeFromReader")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopySomeFromDataTableTest() { - CopySomeFromDataTable.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopySomeFromDataTable")); + CopySomeFromDataTable.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopySomeFromDataTable")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopySomeFromRowArrayTest() { - CopySomeFromRowArray.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopySomeFromRowArray")); + CopySomeFromRowArray.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopySomeFromRowArray")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyWithEventTest() { - CopyWithEvent.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopyWithEvent")); + CopyWithEvent.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopyWithEvent")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyWithEvent1Test() { - CopyWithEvent1.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_CopyWithEvent1")); + CopyWithEvent1.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_CopyWithEvent1")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void InvalidAccessFromEventTest() { - InvalidAccessFromEvent.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_InvalidAccessFromEvent")); + InvalidAccessFromEvent.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_InvalidAccessFromEvent")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Bug84548Test() { - Bug84548.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Bug84548")); + Bug84548.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Bug84548")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void MissingTargetTableTest() { - MissingTargetTable.Test(srcConstr, dstConstr, AddGuid("@SqlBulkCopyTest_MissingTargetTable")); + MissingTargetTable.Test(_connStr, _connStr, AddGuid("@SqlBulkCopyTest_MissingTargetTable")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void MissingTargetColumnTest() { - MissingTargetColumn.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_MissingTargetColumn")); + MissingTargetColumn.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_MissingTargetColumn")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Bug85007Test() { - Bug85007.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Bug85007")); + Bug85007.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Bug85007")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CheckConstraintsTest() { - CheckConstraints.Test(dstConstr, AddGuid("SqlBulkCopyTest_Extensionsrc"), AddGuid("SqlBulkCopyTest_Extensiondst")); + CheckConstraints.Test(_connStr, AddGuid("SqlBulkCopyTest_Extensionsrc"), AddGuid("SqlBulkCopyTest_Extensiondst")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void TransactionTest() { - Transaction.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Transaction0")); + Transaction.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Transaction0")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Transaction1Test() { - Transaction1.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Transaction1")); + Transaction1.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Transaction1")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Transaction2Test() { - Transaction2.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Transaction2")); + Transaction2.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Transaction2")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Transaction3Test() { - Transaction3.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Transaction3")); + Transaction3.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Transaction3")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Transaction4Test() { - Transaction4.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_Transaction4")); + Transaction4.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_Transaction4")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyVariantsTest() { - CopyVariants.Test(dstConstr, AddGuid("SqlBulkCopyTest_Variants")); + CopyVariants.Test(_connStr, AddGuid("SqlBulkCopyTest_Variants")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Bug98182Test() { - Bug98182.Test(dstConstr, AddGuid("@SqlBulkCopyTest_Bug98182 ")); + Bug98182.Test(_connStr, AddGuid("@SqlBulkCopyTest_Bug98182 ")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void FireTriggerTest() { - FireTrigger.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_FireTrigger")); + FireTrigger.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_FireTrigger")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void ErrorOnRowsMarkedAsDeletedTest() { - ErrorOnRowsMarkedAsDeleted.Test(dstConstr, AddGuid("SqlBulkCopyTest_ErrorOnRowsMarkedAsDeleted")); + ErrorOnRowsMarkedAsDeleted.Test(_connStr, AddGuid("SqlBulkCopyTest_ErrorOnRowsMarkedAsDeleted")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void SpecialCharacterNamesTest() { - SpecialCharacterNames.Test(srcConstr, dstConstr, AddGuid("@SqlBulkCopyTest_SpecialCharacterNames")); + SpecialCharacterNames.Test(_connStr, _connStr, AddGuid("@SqlBulkCopyTest_SpecialCharacterNames")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void Bug903514Test() { - Bug903514.Test(dstConstr, AddGuid("SqlBulkCopyTest_Bug903514")); + Bug903514.Test(_connStr, AddGuid("SqlBulkCopyTest_Bug903514")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void ColumnCollationTest() { - ColumnCollation.Test(dstConstr, AddGuid("SqlBulkCopyTest_ColumnCollation")); + ColumnCollation.Test(_connStr, AddGuid("SqlBulkCopyTest_ColumnCollation")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyAllFromReaderAsyncTest() { - CopyAllFromReaderAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest1")); //Async + Reader + CopyAllFromReaderAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest1")); //Async + Reader } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopySomeFromRowArrayAsyncTest() { - CopySomeFromRowArrayAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest2")); //Async + Some Rows + CopySomeFromRowArrayAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest2")); //Async + Some Rows } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopySomeFromDataTableAsyncTest() { - CopySomeFromDataTableAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest3")); //Async + Some Table + CopySomeFromDataTableAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest3")); //Async + Some Table } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyWithEventAsyncTest() { - CopyWithEventAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest4")); //Async + Rows + Notification + CopyWithEventAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest4")); //Async + Rows + Notification } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void CopyAllFromReaderCancelAsyncTest() { - CopyAllFromReaderCancelAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest5")); //Async + Reader + cancellation token + CopyAllFromReaderCancelAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest5")); //Async + Reader + cancellation token } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void CopyAllFromReaderConnectionClosedAsyncTest() { - CopyAllFromReaderConnectionClosedAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest6")); //Async + Reader + Connection closed + CopyAllFromReaderConnectionClosedAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest6")); //Async + Reader + Connection closed } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void CopyAllFromReaderConnectionClosedOnEventAsyncTest() { - CopyAllFromReaderConnectionClosedOnEventAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_AsyncTest7")); //Async + Reader + Connection closed during the event + CopyAllFromReaderConnectionClosedOnEventAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_AsyncTest7")); //Async + Reader + Connection closed during the event } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void TransactionTestAsyncTest() { - TransactionTestAsync.Test(srcConstr, dstConstr, AddGuid("SqlBulkCopyTest_TransactionTestAsync")); //Async + Transaction rollback + TransactionTestAsync.Test(_connStr, _connStr, AddGuid("SqlBulkCopyTest_TransactionTestAsync")); //Async + Transaction rollback } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))] public void CopyWidenNullInexactNumericsTest() { - CopyWidenNullInexactNumerics.Test(srcConstr, dstConstr); + CopyWidenNullInexactNumerics.Test(_connStr, _connStr); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void DestinationTableNameWithSpecialCharTest() { - DestinationTableNameWithSpecialChar.Test(srcConstr, AddGuid("SqlBulkCopyTest_DestinationTableNameWithSpecialChar")); + DestinationTableNameWithSpecialChar.Test(_connStr, AddGuid("SqlBulkCopyTest_DestinationTableNameWithSpecialChar")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void OrderHintTest() { - OrderHint.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHint"), AddGuid("SqlBulkCopyTest_OrderHint2")); + OrderHint.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHint"), AddGuid("SqlBulkCopyTest_OrderHint2")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void OrderHintAsyncTest() { - OrderHintAsync.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHintAsync"), AddGuid("SqlBulkCopyTest_OrderHintAsync2")); + OrderHintAsync.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHintAsync"), AddGuid("SqlBulkCopyTest_OrderHintAsync2")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void OrderHintMissingTargetColumnTest() { - OrderHintMissingTargetColumn.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHintMissingTargetColumn")); + OrderHintMissingTargetColumn.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHintMissingTargetColumn")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void OrderHintDuplicateColumnTest() { - OrderHintDuplicateColumn.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHintDuplicateColumn")); + OrderHintDuplicateColumn.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHintDuplicateColumn")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void OrderHintTransactionTest() { - OrderHintTransaction.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHintTransaction")); + OrderHintTransaction.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHintTransaction")); } [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] [ActiveIssue(12219)] public void OrderHintIdentityColumnTest() { - OrderHintIdentityColumn.Test(srcConstr, AddGuid("SqlBulkCopyTest_OrderHintIdentityColumn")); + OrderHintIdentityColumn.Test(_connStr, AddGuid("SqlBulkCopyTest_OrderHintIdentityColumn")); } } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs index bdb75348dc..516c8654e2 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs @@ -19,6 +19,7 @@ public static class SqlServerTypesTest [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public static void GetSchemaTableTest() { + string db = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString).InitialCatalog; using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) using (SqlCommand cmd = new SqlCommand("select hierarchyid::Parse('/1/') as col0", conn)) { @@ -32,7 +33,7 @@ public static void GetSchemaTableTest() DataTestUtility.AssertEqualsWithDescription("col0", columnName, "Unexpected column name."); string dataTypeName = (string)schemaTable.Rows[0][schemaTable.Columns["DataTypeName"]]; - DataTestUtility.AssertEqualsWithDescription("Northwind.sys.hierarchyid", dataTypeName, "Unexpected data type name."); + DataTestUtility.AssertEqualsWithDescription($"{db}.sys.hierarchyid", dataTypeName, "Unexpected data type name."); string udtAssemblyName = (string)schemaTable.Rows[0][schemaTable.Columns["UdtAssemblyQualifiedName"]]; Assert.True(udtAssemblyName?.StartsWith("Microsoft.SqlServer.Types.SqlHierarchyId"), "Unexpected UDT assembly name: " + udtAssemblyName); diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj new file mode 100644 index 0000000000..29e45648f9 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp3.1 + Microsoft.Data.SqlClient.ExtUtilities.Runner + + + + + + + + + + + diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs new file mode 100644 index 0000000000..b89e090318 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs @@ -0,0 +1,32 @@ +using System; + +namespace Microsoft.Data.SqlClient.ExtUtilities +{ + public static class Runner + { + /// + /// Runs utility tools for SqlClient Tests + /// + /// + /// SqlDbManager Tools: + /// [0] = CreateDatabase, DropDatabase + /// [1] = Name of Database + /// + public static void Main(string [] args) + { + if (args == null || args.Length < 1) + { + throw new ArgumentException("Utility name not provided."); + } + + if (args[0].Contains("Database")) + { + SqlDbManager.Run(args); + } + else + { + throw new ArgumentException("Utility not supported."); + } + } + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs new file mode 100644 index 0000000000..85d80154b1 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Data.SqlClient.TestUtilities; +using Microsoft.SqlServer.Management.Common; + +namespace Microsoft.Data.SqlClient.ExtUtilities +{ + public static class SqlDbManager + { + private static Config s_configJson; + private static Dictionary s_activeConnectionStrings; + + private const string DB_Northwind = "Northwind"; + private const string DB_Master = "master"; + private const string NorthWindScriptPath = @"..\..\..\..\..\tools\testsql\createNorthwindDb.sql"; + private const string ConfigPath = @"..\Microsoft.Data.SqlClient.TestUtilities\config.json"; + + private const string TCPConnectionString = "TCPConnectionString"; + private const string NPConnectionString = "NPConnectionString"; + private const string TCPConnectionStringAASSGX = "TCPConnectionStringAASSGX"; + private const string TCPConnectionStringAASVBS = "TCPConnectionStringAASVBS"; + private const string TCPConnectionStringHGSVBS = "TCPConnectionStringHGSVBS"; + + /// + /// Creates/ drops database as requested. + /// + /// + /// [0] = CreateDatabase, DropDatabase + /// [1] = Name of Database + /// + public static void Run(string[] args) + { + if (args == null || args.Length < 2) + { + throw new InvalidArgumentException("Incomplete arguments provided."); + } + + try + { + var dbName = args[1]; + s_configJson = Config.Load(ConfigPath); + LoadActiveConnectionStrings(); + + foreach (KeyValuePair activeConnString in s_activeConnectionStrings) + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder((activeConnString.Value)); + if (!Utils.IsAzureSqlServer(builder.DataSource)) + { + builder.InitialCatalog = DB_Master; + using SqlConnection conn = new SqlConnection(builder.ConnectionString); + SqlServer.Management.Smo.Server server = new SqlServer.Management.Smo.Server(new ServerConnection(conn)); + ServerConnection context = server.ConnectionContext; + + if (args[0] == "CreateDatabase") + { + //Create a new database + CreateDatabase(dbName, context); + Console.WriteLine($"Database [{dbName}] created successfully in {builder.DataSource}"); + + // Update Config.json accordingly + builder.InitialCatalog = dbName; + UpdateConfig(activeConnString.Key, builder); + } + else if (args[0] == "DropDatabase") + { + // Drop Northwind for test run. + DropIfExistsDatabase(dbName, context); + Console.WriteLine($"Database [{dbName}] dropped successfully in {builder.DataSource}"); + } + else + { + Console.WriteLine($"Utility '{args[0]}' not supported in {builder.DataSource}"); + } + } + else + { + Console.WriteLine($"Database Utilities are not supported for Azure SQL in {activeConnString.Key}"); + } + } + if (args[0] == "CreateDatabase") + { + // Update config.json with Initial Catalog = for "Active Connection Strings" + Config.UpdateConfig(s_configJson, ConfigPath); + } + } + catch (Exception e) + { + throw new Exception($"{args[0]} execution failed with Error: {e.Message}"); + } + } + + private static void LoadActiveConnectionStrings() + { + s_activeConnectionStrings = new Dictionary(); + if (!string.IsNullOrEmpty(s_configJson.TCPConnectionString)) + { + s_activeConnectionStrings.Add(TCPConnectionString, s_configJson.TCPConnectionString); + } + if (!string.IsNullOrEmpty(s_configJson.NPConnectionString)) + { + s_activeConnectionStrings.Add(TCPConnectionString, s_configJson.NPConnectionString); + } + if (s_configJson.EnclaveEnabled) + { + if (!string.IsNullOrEmpty(s_configJson.TCPConnectionStringAASSGX)) + { + s_activeConnectionStrings.Add(TCPConnectionStringAASSGX, s_configJson.TCPConnectionStringAASSGX); + } + if (!string.IsNullOrEmpty(s_configJson.TCPConnectionStringAASVBS)) + { + s_activeConnectionStrings.Add(TCPConnectionStringAASVBS, s_configJson.TCPConnectionStringAASVBS); + } + if (!string.IsNullOrEmpty(s_configJson.TCPConnectionStringHGSVBS)) + { + s_activeConnectionStrings.Add(TCPConnectionStringHGSVBS, s_configJson.TCPConnectionStringHGSVBS); + } + } + } + + private static void UpdateConfig(string key, SqlConnectionStringBuilder builder) + { + switch (key) + { + case TCPConnectionString: + s_configJson.TCPConnectionString = builder.ConnectionString; + break; + case NPConnectionString: + s_configJson.NPConnectionString = builder.ConnectionString; + break; + case TCPConnectionStringAASSGX: + s_configJson.TCPConnectionStringAASSGX = builder.ConnectionString; + break; + case TCPConnectionStringAASVBS: + s_configJson.TCPConnectionStringAASVBS = builder.ConnectionString; + break; + case TCPConnectionStringHGSVBS: + s_configJson.TCPConnectionStringHGSVBS = builder.ConnectionString; + break; + } + } + + private static void DropIfExistsDatabase(string dbName, ServerConnection context) + { + try + { + string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE {dbName} END;"; + context.ExecuteNonQuery(dropScript); + } + catch (Exception) + { + throw; + } + } + + private static void CreateDatabase(string dbName, ServerConnection context) + { + DropIfExistsDatabase(dbName, context); + string createScript = File.ReadAllText(NorthWindScriptPath); + + try + { + createScript = createScript.Replace(DB_Northwind, dbName); + context.ExecuteNonQuery(createScript); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs new file mode 100644 index 0000000000..ba22769200 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using Newtonsoft.Json; + +namespace Microsoft.Data.SqlClient.TestUtilities +{ + public class Config + { + public string TCPConnectionString = null; + public string NPConnectionString = null; + public string TCPConnectionStringHGSVBS = null; + public string TCPConnectionStringAASVBS = null; + public string TCPConnectionStringAASSGX = null; + public string AADAuthorityURL = null; + public string AADPasswordConnectionString = null; + public string AADServicePrincipalId = null; + public string AADServicePrincipalSecret = null; + public string AzureKeyVaultURL = null; + public string AzureKeyVaultClientId = null; + public string AzureKeyVaultClientSecret = null; + public bool EnclaveEnabled = false; + public bool TracingEnabled = false; + public bool SupportsIntegratedSecurity = false; + public bool SupportsLocalDb = false; + public bool SupportsFileStream = false; + public bool UseManagedSNIOnWindows = false; + public string DNSCachingConnString = null; + public string DNSCachingServerCR = null; // this is for the control ring + public string DNSCachingServerTR = null; // this is for the tenant ring + public bool IsDNSCachingSupportedCR = false; // this is for the control ring + public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring + + public static Config Load(string configPath = @"config.json") + { + try + { + using (StreamReader r = new StreamReader(configPath)) + { + return JsonConvert.DeserializeObject(r.ReadToEnd()); + } + } + catch + { + throw; + } + } + + public static void UpdateConfig(Config updatedConfig, string configPath = @"config.json") + { + string config = JsonConvert.SerializeObject(updatedConfig); + File.WriteAllText(configPath, config); + } + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj new file mode 100644 index 0000000000..e230b0961b --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj @@ -0,0 +1,19 @@ + + + + net46;netcoreapp2.1; + + + + + + + + + PreserveNewest + config.json + + + + + diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs new file mode 100644 index 0000000000..636819def2 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; + +namespace Microsoft.Data.SqlClient.TestUtilities +{ + public static class Utils + { + private static readonly string[] s_azureSqlServerEndpoints = {".database.windows.net", + ".database.cloudapi.de", + ".database.usgovcloudapi.net", + ".database.chinacloudapi.cn"}; + + // This method assumes dataSource parameter is in TCP connection string format. + public static bool IsAzureSqlServer(string dataSource) + { + int i = dataSource.LastIndexOf(','); + if (i >= 0) + { + dataSource = dataSource.Substring(0, i); + } + + i = dataSource.LastIndexOf('\\'); + if (i >= 0) + { + dataSource = dataSource.Substring(0, i); + } + + // trim redundant whitespace + dataSource = dataSource.Trim(); + + // check if server name end with any azure endpoints + for (i = 0; i < s_azureSqlServerEndpoints.Length; i++) + { + if (dataSource.EndsWith(s_azureSqlServerEndpoints[i], StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + return false; + } + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json similarity index 100% rename from src/Microsoft.Data.SqlClient/tests/ManualTests/config.default.json rename to src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json diff --git a/tools/props/Versions.props b/tools/props/Versions.props index 16c550dfd6..46d17b87ea 100644 --- a/tools/props/Versions.props +++ b/tools/props/Versions.props @@ -63,6 +63,7 @@ 2.4.1 5.0.0-beta.20206.4 2.0.8 + 161.41011.9 $(NugetPackageVersion) From b53c342ef8b2ef24a25ed826c36ce5e4927ea828 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 27 Aug 2020 15:06:05 -0700 Subject: [PATCH 2/7] Fixes --- .../tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs | 2 +- .../Microsoft.Data.SqlClient.ExtUtilities.csproj | 4 ++-- .../Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs | 2 +- .../Microsoft.Data.SqlClient.TestUtilities.csproj | 6 +++++- .../config.default.json | 2 +- tools/testsql/createNorthwindDb.sql | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs index 516c8654e2..ae29f5e6c4 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/UdtTest/SqlServerTypesTest.cs @@ -33,7 +33,7 @@ public static void GetSchemaTableTest() DataTestUtility.AssertEqualsWithDescription("col0", columnName, "Unexpected column name."); string dataTypeName = (string)schemaTable.Rows[0][schemaTable.Columns["DataTypeName"]]; - DataTestUtility.AssertEqualsWithDescription($"{db}.sys.hierarchyid", dataTypeName, "Unexpected data type name."); + DataTestUtility.AssertEqualsWithDescription($"{db}.sys.hierarchyid".ToUpper(), dataTypeName.ToUpper(), "Unexpected data type name."); string udtAssemblyName = (string)schemaTable.Rows[0][schemaTable.Columns["UdtAssemblyQualifiedName"]]; Assert.True(udtAssemblyName?.StartsWith("Microsoft.SqlServer.Types.SqlHierarchyId"), "Unexpected UDT assembly name: " + udtAssemblyName); diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj index 4f0d4f337b..a34912adbe 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 Microsoft.Data.SqlClient.ExtUtilities.Runner @@ -11,7 +11,7 @@ - + diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index 21de7b8221..d874f5d0b0 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -142,7 +142,7 @@ private static void DropIfExistsDatabase(string dbName, ServerConnection context { try { - string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE {dbName} END;"; + string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE [{dbName}] END;"; context.ExecuteNonQuery(dropScript); } catch (Exception) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj index 1da5a435a1..ce1d11e438 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj @@ -1,5 +1,9 @@  - + + + netcoreapp2.1 + + diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json index 010064c025..e80b223ea9 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json @@ -17,5 +17,5 @@ "SupportsLocalDb": false, "SupportsFileStream": false, "UseManagedSNIOnWindows": false, - "EnclaveAzureDatabaseConnString": "", + "EnclaveAzureDatabaseConnString": "" } diff --git a/tools/testsql/createNorthwindDb.sql b/tools/testsql/createNorthwindDb.sql index 01f48aaec6..fa3a2271fb 100644 --- a/tools/testsql/createNorthwindDb.sql +++ b/tools/testsql/createNorthwindDb.sql @@ -4318,7 +4318,7 @@ SELECT @isFullTextSearchingEnabled = FULLTEXTSERVICEPROPERTY('IsFullTextInstalle IF(@isFullTextSearchingEnabled = 1) BEGIN Use [Northwind] - CREATE FULLTEXT CATALOG Northwind_Employee_FTC AS DEFAULT; + CREATE FULLTEXT CATALOG [Northwind_Employee_FTC] AS DEFAULT; CREATE FULLTEXT INDEX ON Employees (FirstName, Title, City) KEY INDEX PK_Employees; PRINT N'Successfully Created FULLTEXT INDEX ON Employees (FirstName, Title, City)' From 0b95354f4449f4b5f2cbef1a13499c1f0b30250f Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 27 Aug 2020 17:23:42 -0700 Subject: [PATCH 3/7] More fixes --- .../SqlDbManager.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index d874f5d0b0..22b7e2073f 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -53,25 +53,29 @@ public static void Run(string[] args) SqlServer.Management.Smo.Server server = new SqlServer.Management.Smo.Server(new ServerConnection(conn)); ServerConnection context = server.ConnectionContext; - if (args[0] == "CreateDatabase") + // We do not create/drop database for HGS-VBS since SQL Server for AASVBS and HGSVBS connection strings is same. + if (activeConnString.Key != TCPConnectionStringHGSVBS) { - //Create a new database - CreateDatabase(dbName, context); - Console.WriteLine($"Database [{dbName}] created successfully in {builder.DataSource}"); + if (args[0] == "CreateDatabase") + { + //Create a new database + CreateDatabase(dbName, context); + Console.WriteLine($"Database [{dbName}] created successfully in {builder.DataSource}"); - // Update Config.json accordingly - builder.InitialCatalog = dbName; - UpdateConfig(activeConnString.Key, builder); - } - else if (args[0] == "DropDatabase") - { - // Drop Northwind for test run. - DropIfExistsDatabase(dbName, context); - Console.WriteLine($"Database [{dbName}] dropped successfully in {builder.DataSource}"); - } - else - { - Console.WriteLine($"Utility '{args[0]}' not supported in {builder.DataSource}"); + // Update Config.json accordingly + builder.InitialCatalog = dbName; + UpdateConfig(activeConnString.Key, builder); + } + else if (args[0] == "DropDatabase") + { + // Drop Northwind for test run. + DropIfExistsDatabase(dbName, context); + Console.WriteLine($"Database [{dbName}] dropped successfully in {builder.DataSource}"); + } + else + { + Console.WriteLine($"Utility '{args[0]}' not supported in {builder.DataSource}"); + } } } } From 098150c4322b7fefaf3c81d4423508d3a130634a Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 27 Aug 2020 18:17:46 -0700 Subject: [PATCH 4/7] More fixes --- ...crosoft.Data.SqlClient.ExtUtilities.csproj | 6 --- .../SqlDbManager.cs | 39 ++++++++++++------- ...rosoft.Data.SqlClient.TestUtilities.csproj | 11 +++--- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj index a34912adbe..614ab2d91e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Microsoft.Data.SqlClient.ExtUtilities.csproj @@ -1,17 +1,11 @@  - Exe netcoreapp3.1 Microsoft.Data.SqlClient.ExtUtilities.Runner - - - - - diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index 22b7e2073f..bc541bf299 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -48,34 +48,39 @@ public static void Run(string[] args) if (!Utils.IsAzureSqlServer(builder.DataSource)) { builder.InitialCatalog = DB_Master; - using(SqlConnection conn = new SqlConnection(builder.ConnectionString)) + using (SqlConnection conn = new SqlConnection(builder.ConnectionString)) { SqlServer.Management.Smo.Server server = new SqlServer.Management.Smo.Server(new ServerConnection(conn)); ServerConnection context = server.ConnectionContext; - // We do not create/drop database for HGS-VBS since SQL Server for AASVBS and HGSVBS connection strings is same. - if (activeConnString.Key != TCPConnectionStringHGSVBS) + if (args[0] == "CreateDatabase") { - if (args[0] == "CreateDatabase") + // We do not create database for HGS-VBS since SQL Server for AASVBS and HGSVBS connection strings is same. + // Do not create database for NP connection string, since server is always same as TCP + if (activeConnString.Key != TCPConnectionStringHGSVBS && activeConnString.Key != NPConnectionString) { //Create a new database CreateDatabase(dbName, context); Console.WriteLine($"Database [{dbName}] created successfully in {builder.DataSource}"); - - // Update Config.json accordingly - builder.InitialCatalog = dbName; - UpdateConfig(activeConnString.Key, builder); } - else if (args[0] == "DropDatabase") + // Update Config.json accordingly + builder.InitialCatalog = dbName; + UpdateConfig(activeConnString.Key, builder); + } + else if (args[0] == "DropDatabase") + { + // We do not drop database for HGS-VBS since SQL Server for AASVBS and HGSVBS connection strings is same. + // Do not drop database for NP connection string, since server is always same as TCP + if (activeConnString.Key != TCPConnectionStringHGSVBS && activeConnString.Key != NPConnectionString) { // Drop Northwind for test run. DropIfExistsDatabase(dbName, context); Console.WriteLine($"Database [{dbName}] dropped successfully in {builder.DataSource}"); } - else - { - Console.WriteLine($"Utility '{args[0]}' not supported in {builder.DataSource}"); - } + } + else + { + Console.WriteLine($"Utility '{args[0]}' not supported in {builder.DataSource}"); } } } @@ -103,6 +108,10 @@ private static void LoadActiveConnectionStrings() { s_activeConnectionStrings.Add(TCPConnectionString, s_configJson.TCPConnectionString); } + if (!string.IsNullOrEmpty(s_configJson.NPConnectionString)) + { + s_activeConnectionStrings.Add(NPConnectionString, s_configJson.NPConnectionString); + } if (s_configJson.EnclaveEnabled) { if (!string.IsNullOrEmpty(s_configJson.TCPConnectionStringAASSGX)) @@ -149,9 +158,9 @@ private static void DropIfExistsDatabase(string dbName, ServerConnection context string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE [{dbName}] END;"; context.ExecuteNonQuery(dropScript); } - catch (Exception) + catch { - throw; + Console.WriteLine($"FAILED to drop database '{dbName}'"); } } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj index ce1d11e438..c4c9cacd62 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj @@ -1,13 +1,15 @@  - - netcoreapp2.1 + netcoreapp + netfx + Debug;Release;net46-Release;net46-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release + AnyCPU;x86;x64 + $(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName) + $(BinFolder)$(Configuration).$(Platform)\$(AssemblyName) - - PreserveNewest @@ -15,5 +17,4 @@ - From 1d4ca464a9cdd92a95d96d1e114ed9d586c062fd Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 28 Aug 2020 12:04:32 -0700 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: David Engel --- .../tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs | 6 +++++- .../Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs | 6 +++++- .../tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs | 6 +++++- .../tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs index b89e090318..9eda28368f 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// 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; namespace Microsoft.Data.SqlClient.ExtUtilities { diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index bc541bf299..e5e460ec7e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// 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; using System.Collections.Generic; using System.IO; using Microsoft.Data.SqlClient.TestUtilities; diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs index ce3ef0b84f..611037ae92 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// 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; using System.IO; using Newtonsoft.Json; diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs index 636819def2..5d708e757d 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Utils.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// 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; using System.Collections.Generic; namespace Microsoft.Data.SqlClient.TestUtilities From 0eef0a55b79167ed6256ff1fedeb067003963a19 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 28 Aug 2020 12:46:04 -0700 Subject: [PATCH 6/7] Trigger build --- .../tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index e5e460ec7e..805d454a78 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -178,7 +178,7 @@ private static void CreateDatabase(string dbName, ServerConnection context) createScript = createScript.Replace(DB_Northwind, dbName); context.ExecuteNonQuery(createScript); } - catch (Exception) + catch { throw; } From c5887b71ccdc63cf587de9318a592777c54f4649 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 28 Aug 2020 13:04:52 -0700 Subject: [PATCH 7/7] Trigger build --- .../SqlDbManager.cs | 2 +- .../Microsoft.Data.SqlClient.TestUtilities.csproj | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index 805d454a78..e5e460ec7e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -178,7 +178,7 @@ private static void CreateDatabase(string dbName, ServerConnection context) createScript = createScript.Replace(DB_Northwind, dbName); context.ExecuteNonQuery(createScript); } - catch + catch (Exception) { throw; } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj index c4c9cacd62..d6e934cae7 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj @@ -1,10 +1,11 @@ - + + net46;netcoreapp2.1 netcoreapp netfx - Debug;Release;net46-Release;net46-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release + Debug;Release;net46-Release;net46-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release; AnyCPU;x86;x64 - $(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName) + $(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName) $(BinFolder)$(Configuration).$(Platform)\$(AssemblyName) @@ -17,4 +18,4 @@ - + \ No newline at end of file