public void LoadMerchantsAndCommitWithLocalTransaction() { string query = @"SELECT Merchant.Name FROM Merchant WHERE MerchantId = @MerchantId;"; MerchantData actual = null; DatabaseConnector databaseConnector = new DatabaseConnector(connectionString); try { // Inicializa uma transação de banco de dados. databaseConnector.BeginTransaction(); actual = databaseConnector.ExecuteReaderFetchAll<MerchantData>(query, new { MerchantId = 1 }).FirstOrDefault(); Assert.IsNotNull(actual); Assert.AreEqual("Merchant Number One", actual.Name); actual = databaseConnector.ExecuteReaderFetchAll<MerchantData>(query, new { MerchantId = 2 }).FirstOrDefault(); Assert.IsNotNull(actual); Assert.AreEqual("Another Merchant", actual.Name); databaseConnector.Commit(); } catch { databaseConnector.Rollback(); } finally { databaseConnector.Close(); } }
public void CommitNullTransaction() { using (DatabaseConnector databaseConnector = new DatabaseConnector(connectionString)) { databaseConnector.Commit(); } }
public void MultipleTransactions() { DatabaseConnector databaseConnector = new DatabaseConnector(connectionString); //DatabaseConnector.BeginTransaction(connectionString); try { databaseConnector.BeginTransaction(); databaseConnector.ExecuteNonQuery("SELECT banana FROM Merchant;"); databaseConnector.Commit(); //DatabaseConnector.CommitTransaction(); } catch (Exception) { //DatabaseConnector.RollbackTransaction(); databaseConnector.Rollback(); } using (DatabaseConnector dbConnector = new DatabaseConnector(connectionString)) { DateTime dateTime = dbConnector.ExecuteScalar<DateTime>("SELECT GETUTCDATE();"); } }