88using System . Runtime . InteropServices ;
99using NUnit . Framework ;
1010using Snowflake . Data . Client ;
11- using Snowflake . Data . Core . Tools ;
1211using Snowflake . Data . Log ;
1312using Snowflake . Data . Tests . Util ;
1413
@@ -22,9 +21,37 @@ namespace Snowflake.Data.Tests
2221 using Newtonsoft . Json . Serialization ;
2322
2423 /*
25- * This is the base class for all tests that call blocking methods in the library - it uses MockSynchronizationContext to verify that
24+ * Base infrastructure shared by all test classes - provides common test utilities
25+ */
26+ public class BaseTestInfrastructure
27+ {
28+ protected virtual string TestName => TestContext . CurrentContext . Test . MethodName ;
29+ protected string TestNameWithWorker => TestName + TestContext . CurrentContext . WorkerId ? . Replace ( "#" , "_" ) ;
30+ }
31+
32+ /*
33+ * Base class for unit tests - it uses MockSynchronizationContext to verify that
34+ * there are no async deadlocks in the library
35+ */
36+ [ TestFixture ]
37+ public class UnitTestBase : BaseTestInfrastructure
38+ {
39+ [ SetUp ]
40+ public static void SetUpMockContext ( )
41+ {
42+ MockSynchronizationContext . SetupContext ( ) ;
43+ }
44+
45+ [ TearDown ]
46+ public static void TearDownMockContext ( )
47+ {
48+ MockSynchronizationContext . Verify ( ) ;
49+ }
50+ }
51+
52+ /*
53+ * Base class for integration tests that call blocking methods in the library - it uses MockSynchronizationContext to verify that
2654 * there are no async deadlocks in the library
27- *
2855 */
2956 [ TestFixture ]
3057 public class SFBaseTest : SFBaseTestAsync
@@ -43,8 +70,7 @@ public static void TearDownContext()
4370 }
4471
4572 /*
46- * This is the base class for all tests that call async methods in the library - it does not use a special SynchronizationContext
47- *
73+ * Base class for integration tests that call async methods - provides database connection infrastructure
4874 */
4975 [ TestFixture ]
5076 [ FixtureLifeCycle ( LifeCycle . InstancePerTestCase ) ]
@@ -276,7 +302,6 @@ public void Setup()
276302 Assert . IsTrue ( cloud == null || cloud == "AWS" || cloud == "AZURE" || cloud == "GCP" , "{0} is not supported. Specify AWS, AZURE or GCP as cloud environment" , cloud ) ;
277303
278304 TestConfig = ReadTestConfig ( ) ;
279- ModifySchema ( TestConfig . schema , SchemaAction . CREATE ) ;
280305 }
281306
282307 private static TestConfig ReadTestConfig ( )
@@ -361,12 +386,6 @@ internal static TestConfig ReadTestConfigFile(string fileName)
361386 }
362387 }
363388
364- [ OneTimeTearDown ]
365- public void Cleanup ( )
366- {
367- ModifySchema ( TestConfig . schema , SchemaAction . DROP ) ;
368- }
369-
370389 [ OneTimeSetUp ]
371390 public void SetupTestPerformance ( )
372391 {
@@ -390,56 +409,6 @@ public void CreateTestTimeArtifact()
390409 File . WriteAllText ( $ "..{ separator } ..{ separator } ..{ separator } { GetOs ( ) } _{ dotnetVersion } _{ cloudEnv } _performance.csv", resultText ) ;
391410 }
392411
393- private const string ConnectionStringFmt = "scheme={0};host={1};port={2};certRevocationCheckMode=enabled;" +
394- "account={3};role={4};db={5};warehouse={6};user={7};password={8};" ;
395-
396- private static string s_connectionString => string . Format ( ConnectionStringFmt ,
397- TestConfig . protocol ,
398- TestConfig . host ,
399- TestConfig . port ,
400- TestConfig . account ,
401- TestConfig . role ,
402- TestConfig . database ,
403- TestConfig . warehouse ,
404- TestConfig . user ,
405- TestConfig . password ) ;
406-
407- private enum SchemaAction
408- {
409- CREATE ,
410- DROP
411- }
412-
413- private static void ModifySchema ( string schemaName , SchemaAction schemaAction )
414- {
415- using ( IDbConnection conn = new SnowflakeDbConnection ( ) )
416- {
417- conn . ConnectionString = s_connectionString ;
418- conn . Open ( ) ;
419- var dbCommand = conn . CreateCommand ( ) ;
420- switch ( schemaAction )
421- {
422- case SchemaAction . CREATE :
423- dbCommand . CommandText = $ "CREATE OR REPLACE SCHEMA { schemaName } ";
424- break ;
425- case SchemaAction . DROP :
426- dbCommand . CommandText = $ "DROP SCHEMA IF EXISTS { schemaName } ";
427- break ;
428- default :
429- Assert . Fail ( $ "Not supported action on schema: { schemaAction } ") ;
430- break ;
431- }
432- try
433- {
434- dbCommand . ExecuteNonQuery ( ) ;
435- }
436- catch ( InvalidOperationException e )
437- {
438- Assert . Fail ( $ "Unable to { schemaAction . ToString ( ) . ToLower ( ) } schema { schemaName } :\n { e . StackTrace } ") ;
439- }
440- }
441- }
442-
443412 private static string GetOs ( )
444413 {
445414 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
0 commit comments