55using System ;
66using System . Data ;
77using System . Threading . Tasks ;
8+ using Microsoft . Data . SqlClient . ManualTesting . Tests ;
89using Xunit ;
910
10- namespace Microsoft . Data . SqlClient . ManualTesting . Tests
11+ namespace Microsoft . Data . SqlClient . ManualTests . BulkCopy
1112{
1213 public class CacheMetadata
1314 {
@@ -16,8 +17,12 @@ public class CacheMetadata
1617 private static readonly string sourceQueryTemplate = "select top 5 EmployeeID, LastName, FirstName from {0}" ;
1718
1819 // Test that CacheMetadata option works for multiple WriteToServer calls to the same table.
19- public static void Test ( string srcConstr , string dstConstr , string dstTable )
20+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
21+ public void Test ( )
2022 {
23+ string srcConstr = DataTestUtility . TCPConnectionString ;
24+ string dstConstr = DataTestUtility . TCPConnectionString ;
25+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadata" , false ) ;
2126 string sourceQuery = string . Format ( sourceQueryTemplate , sourceTable ) ;
2227 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
2328
@@ -76,8 +81,12 @@ public class CacheMetadataInvalidate
7681 private static readonly string sourceQueryTemplate = "select top 5 EmployeeID, LastName, FirstName from {0}" ;
7782
7883 // Test that ClearCachedMetadata forces a fresh metadata query.
79- public static void Test ( string srcConstr , string dstConstr , string dstTable )
84+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
85+ public void Test ( )
8086 {
87+ string srcConstr = DataTestUtility . TCPConnectionString ;
88+ string dstConstr = DataTestUtility . TCPConnectionString ;
89+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataInvalidate" , false ) ;
8190 string sourceQuery = string . Format ( sourceQueryTemplate , sourceTable ) ;
8291 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
8392
@@ -128,8 +137,13 @@ public class CacheMetadataDestinationChange
128137 private static readonly string sourceQueryTemplate = "select top 5 EmployeeID, LastName, FirstName from {0}" ;
129138
130139 // Test that changing DestinationTableName invalidates the cache and works correctly with a new table.
131- public static void Test ( string srcConstr , string dstConstr , string dstTable1 , string dstTable2 )
140+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
141+ public void Test ( )
132142 {
143+ string srcConstr = DataTestUtility . TCPConnectionString ;
144+ string dstConstr = DataTestUtility . TCPConnectionString ;
145+ string dstTable1 = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataDstChange0" , false ) ;
146+ string dstTable2 = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataDstChange1" , false ) ;
133147 string sourceQuery = string . Format ( sourceQueryTemplate , sourceTable ) ;
134148 string initialQuery1 = string . Format ( initialQueryTemplate , dstTable1 ) ;
135149 string initialQuery2 = string . Format ( initialQueryTemplate , dstTable2 ) ;
@@ -182,8 +196,12 @@ public class CacheMetadataWithoutFlag
182196 private static readonly string sourceQueryTemplate = "select top 5 EmployeeID, LastName, FirstName from {0}" ;
183197
184198 // Test that without the CacheMetadata flag, multiple writes still work (no regression).
185- public static void Test ( string srcConstr , string dstConstr , string dstTable )
199+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
200+ public void Test ( )
186201 {
202+ string srcConstr = DataTestUtility . TCPConnectionString ;
203+ string dstConstr = DataTestUtility . TCPConnectionString ;
204+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataNoFlag" , false ) ;
187205 string sourceQuery = string . Format ( sourceQueryTemplate , sourceTable ) ;
188206 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
189207
@@ -230,8 +248,11 @@ public class CacheMetadataWithDataTable
230248 private static readonly string initialQueryTemplate = "create table {0} (col1 int, col2 nvarchar(50), col3 nvarchar(50))" ;
231249
232250 // Test that CacheMetadata works with DataTable source as well as IDataReader.
233- public static void Test ( string dstConstr , string dstTable )
251+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
252+ public void Test ( )
234253 {
254+ string dstConstr = DataTestUtility . TCPConnectionString ;
255+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataDT" , false ) ;
235256 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
236257
237258 using DataTable sourceData = new ( ) ;
@@ -275,8 +296,11 @@ public class CacheMetadataColumnMappingsChange
275296 // Test that changing ColumnMappings between WriteToServer calls works correctly with CacheMetadata.
276297 // The cached metadata describes the destination table schema, not the column mappings,
277298 // so modifying mappings between calls should work without cache invalidation.
278- public static void Test ( string dstConstr , string dstTable )
299+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
300+ public void Test ( )
279301 {
302+ string dstConstr = DataTestUtility . TCPConnectionString ;
303+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataColMap" , false ) ;
280304 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
281305
282306 using DataTable sourceData = new DataTable ( ) ;
@@ -348,8 +372,11 @@ public class CacheMetadataColumnSubsetChange
348372 // second call, works correctly with CacheMetadata. This verifies that null-pruning of
349373 // unmatched columns in AnalyzeTargetAndCreateUpdateBulkCommand does not mutate the
350374 // cached metadata, which would cause a NullReferenceException on the second call.
351- public static void Test ( string dstConstr , string dstTable )
375+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
376+ public void Test ( )
352377 {
378+ string dstConstr = DataTestUtility . TCPConnectionString ;
379+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataSubset" , false ) ;
353380 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
354381
355382 using DataTable sourceData = new DataTable ( ) ;
@@ -407,8 +434,12 @@ public class CacheMetadataAsync
407434 private static readonly string sourceQueryTemplate = "select top 5 EmployeeID, LastName, FirstName from {0}" ;
408435
409436 // Test that CacheMetadata works correctly with WriteToServerAsync.
410- public static void Test ( string srcConstr , string dstConstr , string dstTable )
437+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
438+ public void Test ( )
411439 {
440+ string srcConstr = DataTestUtility . TCPConnectionString ;
441+ string dstConstr = DataTestUtility . TCPConnectionString ;
442+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataAsync" , false ) ;
412443 Task t = TestAsync ( srcConstr , dstConstr , dstTable ) ;
413444 t . Wait ( ) ;
414445 Assert . True ( t . IsCompleted , "Task did not complete! Status: " + t . Status ) ;
@@ -472,8 +503,11 @@ public class CacheMetadataCombinedWithKeepNulls
472503 private static readonly string initialQueryTemplate = "create table {0} (col1 int, col2 nvarchar(50) default 'DefaultVal', col3 nvarchar(50))" ;
473504
474505 // Test that CacheMetadata works correctly when combined with other SqlBulkCopyOptions.
475- public static void Test ( string dstConstr , string dstTable )
506+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureServer ) ) ]
507+ public void Test ( )
476508 {
509+ string dstConstr = DataTestUtility . TCPConnectionString ;
510+ string dstTable = DataTestUtility . GetShortName ( "SqlBulkCopyTest_CacheMetadataKeepNulls" , false ) ;
477511 string initialQuery = string . Format ( initialQueryTemplate , dstTable ) ;
478512
479513 using DataTable sourceData = new ( ) ;
0 commit comments