Esempio n. 1
0
        public void TransactionsTest()
        {
            DatabaseWrapper.BeginTransaction();
            var tableName = "testingTable" + HelperObjectFactory.GetRandomInt(0);

            DatabaseWrapper.ExecuteSql($"CREATE TABLE {tableName}(a,b);");
            DatabaseWrapper.ExecuteSql($"INSERT INTO {tableName}(a,b) VALUES ('test0', 'test1');");
            DatabaseWrapper.CommitTransaction();

            using (var cursor = DatabaseWrapper.ExecuteSingleResultQuery($"SELECT * FROM {tableName};"))
            {
                Assert.IsTrue(DatabaseWrapper.HasOneRecordAndClose(cursor));
            }

            DatabaseWrapper.BeginTransaction();
            DatabaseWrapper.ExecuteSql($"INSERT INTO {tableName}(a,b) VALUES ('test20', 'test21');");
            DatabaseWrapper.ExecuteSql($"INSERT INTO {tableName}(a,b) VALUES ('test20', 'test21');");
            DatabaseWrapper.RollBackTransaction();

            Assert.AreEqual(DatabaseWrapper.ExecuteCountQuery($"SELECT COUNT(a) FROM {tableName};"), 1);

            DatabaseWrapper.BeginTransaction();
            DatabaseWrapper.ExecuteSql($"INSERT INTO {tableName}(a,b) VALUES ('test20', 'test21');");
            DatabaseWrapper.ExecuteSql($"INSERT INTO {tableName}(a,b) VALUES ('test20', 'test21');");
            DatabaseWrapper.CommitTransaction();

            Assert.AreEqual(DatabaseWrapper.ExecuteCountQuery($"SELECT COUNT(a) FROM {tableName};"), 3);
        }