示例#1
0
 public void TransactionRolledBackIfNotCommitted()
 {
     using (var sw = new MsSqlWorker(ConnectionString))
         using (var tran = sw.TransactionBegin())
         {
             var insertsCount = sw.Exec(
                 command: @"insert into numbers values (@number, @square, @sqrt, @is_prime, @as_text)",
                 parameters: new SwParameters
             {
                 { "number", 100500 },
                 { "square", -1 },
                 { "sqrt", 0.0 },
                 { "is_prime", false },
                 { "as_text", (string)null },
             },
                 transaction: tran);
             Assert.AreEqual(1, insertsCount);
         }
     using (var sw = new MsSqlWorker(ConnectionString))
     {
         Assert.AreEqual(
             expected: 0,
             actual: sw.Query("select COUNT(*) from numbers where number = 100500", dr => (int)dr[0]).Single());
     }
 }
示例#2
0
 public void CanCommitTransaction()
 {
     using (var sw = new MsSqlWorker(ConnectionString))
         using (var tran = sw.TransactionBegin())
         {
             var insertsCount = sw.Exec(
                 command: @"insert into numbers values (@number, @square, @sqrt, @is_prime, @as_text)",
                 parameters: new SwParameters
             {
                 { "number", 4 },
                 { "square", 16L },
                 { "sqrt", 2.0 },
                 { "is_prime", false },
                 { "as_text", "four" },
             },
                 transaction: tran);
             Assert.AreEqual(1, insertsCount);
             tran.Commit();
         }
     using (var sw = new MsSqlWorker(ConnectionString))
     {
         Assert.AreEqual(
             expected: (4, 16L, 2.0, false, "four"),
             actual: sw.Query("select * from numbers where number = 4", dr => ((int)dr[0], (long)dr[1], (double)dr[2], (bool)dr[3], (string)dr[4])).Single());
     }
 }