public async Task TestSchemaLoaderCacheWithExistingConnectionAndImmediateLoadingAsync() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); List <ISqlBulkHelpersDBSchemaLoader> schemaLoadersList = new List <ISqlBulkHelpersDBSchemaLoader>(); using (var conn = await sqlConnectionProvider.NewConnectionAsync()) { schemaLoadersList.Add(SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(conn)); } using (var conn = await sqlConnectionProvider.NewConnectionAsync()) { schemaLoadersList.Add(SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(conn)); } using (var conn = await sqlConnectionProvider.NewConnectionAsync()) { schemaLoadersList.Add(SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(conn)); } Assert.IsNotNull(schemaLoadersList[0]); Assert.IsNotNull(schemaLoadersList[1]); Assert.IsNotNull(schemaLoadersList[2]); Assert.AreEqual(schemaLoadersList[0], schemaLoadersList[1]); Assert.AreEqual(schemaLoadersList[1], schemaLoadersList[2]); Assert.AreEqual(schemaLoadersList[0], schemaLoadersList[2]); //ALL should already be initialized since used existing connections to construct them! Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[0]).IsInitialized); Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[1]).IsInitialized); Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[2]).IsInitialized); }
public void TestSchemaLoaderCacheWithLazyLoading() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); List <ISqlBulkHelpersDBSchemaLoader> schemaLoadersList = new List <ISqlBulkHelpersDBSchemaLoader> { SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(sqlConnectionProvider), SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(sqlConnectionProvider), SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(sqlConnectionProvider) }; Assert.IsNotNull(schemaLoadersList[0]); Assert.IsNotNull(schemaLoadersList[1]); Assert.IsNotNull(schemaLoadersList[2]); Assert.AreEqual(schemaLoadersList[0], schemaLoadersList[1]); Assert.AreEqual(schemaLoadersList[1], schemaLoadersList[2]); Assert.AreEqual(schemaLoadersList[0], schemaLoadersList[2]); //NOTE: We can't actually test this since it's Cached and the TestFramework may have already // initialized the Schema Definitions for the connection from other tests! //Assert.IsFalse(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[0]).IsInitialized); schemaLoadersList[1].InitializeSchemaDefinitions(); Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[0]).IsInitialized); Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[1]).IsInitialized); Assert.IsTrue(((SqlBulkHelpersDBSchemaStaticLoader)schemaLoadersList[2]).IsInitialized); }
public async Task TestBulkInsertConstructorWithExistingConnectionAndTransactionAsync() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); using (var conn = await sqlConnectionProvider.NewConnectionAsync()) using (SqlTransaction transaction = conn.BeginTransaction()) { ISqlBulkHelper <TestElement> sqlBulkIdentityHelper = new SqlBulkIdentityHelper <TestElement>(conn, transaction); await DoInsertOrUpdateTestAsync(sqlBulkIdentityHelper, transaction); } }
public async Task TestBulkInsertConstructorWithDBSchemaLoaderInstanceDeferred() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); var sqlBulkDbSchemaLoader = SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(sqlConnectionProvider); using (var conn = await sqlConnectionProvider.NewConnectionAsync()) using (SqlTransaction transaction = conn.BeginTransaction()) { ISqlBulkHelper <TestElement> sqlBulkIdentityHelper = new SqlBulkIdentityHelper <TestElement>(sqlBulkDbSchemaLoader); await DoInsertOrUpdateTestAsync(sqlBulkIdentityHelper, transaction); } }
public async Task TestBulkInsertConstructorWithDBSchemaLoaderInstanceFromExistingConnectionAndTransaction() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); using (var conn = await sqlConnectionProvider.NewConnectionAsync()) using (SqlTransaction transaction = conn.BeginTransaction()) { //TEST the code flow where the DB Schema Loader is initialized from existing //Connection + Transaction and immediately initialized var sqlBulkDbSchemaLoader = SqlBulkHelpersSchemaLoaderCache.GetSchemaLoader(conn, transaction, true); ISqlBulkHelper <TestElement> sqlBulkIdentityHelper = new SqlBulkIdentityHelper <TestElement>(sqlBulkDbSchemaLoader); await DoInsertOrUpdateTestAsync(sqlBulkIdentityHelper, transaction); } }
public async Task TestBulkInsertConstructorWithExistingConnectionOnlyAsync() { ISqlBulkHelpersConnectionProvider sqlConnectionProvider = SqlConnectionHelper.GetConnectionProvider(); using (var conn = await sqlConnectionProvider.NewConnectionAsync()) { //NOTE: IN THIS CASE we must initialize BEFORE the transaction is created or an error may occur // when initializing the DB Schema Definitions because we are intentionally not passing // in the Transaction to test this code flow. ISqlBulkHelper <TestElement> sqlBulkIdentityHelper = new SqlBulkIdentityHelper <TestElement>(conn); using (SqlTransaction transaction = conn.BeginTransaction()) { await DoInsertOrUpdateTestAsync(sqlBulkIdentityHelper, transaction); } } }