2 // SqlTransactionTest.cs - NUnit Test Cases for testing the
3 // SqlTransaction class
5 // Umadevi S (sumadevi@novell.com)
6 // Sureshkumar T (tsureshkumar@novell.com)
8 // Copyright (c) 2004 Novell Inc., and the individuals listed
9 // on the ChangeLog entries.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Data.Common;
34 using System.Data.SqlClient;
36 using NUnit.Framework;
38 namespace MonoTests.System.Data.SqlClient
41 [Category ("sqlserver")]
42 public class SqlTransactionTest
46 String connectionString;
52 connectionString = ConnectionManager.Singleton.ConnectionString;
53 engine = ConnectionManager.Singleton.Engine;
57 public void TearDown ()
69 Assert.Ignore ("NotWorking");
71 SqlConnection connA = null;
72 SqlConnection connB = null;
75 connA = new SqlConnection (connectionString);
78 connB = new SqlConnection (connectionString);
81 using (trans = connA.BeginTransaction ()) {
82 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
83 SqlCommand cmd = new SqlCommand (sql, connA, trans);
84 cmd.ExecuteNonQuery ();
87 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connA, trans);
88 using (SqlDataReader reader = cmd.ExecuteReader ()) {
89 Assert.IsTrue (reader.Read (), "#A1");
90 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#A2");
91 Assert.IsFalse (reader.Read (), "#A3");
94 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connB);
95 cmd.CommandTimeout = 2;
99 } catch (SqlException ex) {
100 // Timeout expired. The timeout period
101 // elapsed prior to completion of the
102 // operation or the server is not responding
103 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#B2");
104 Assert.AreEqual ((byte) 11, ex.Class, "#B3");
105 Assert.IsNull (ex.InnerException, "#B4");
106 Assert.IsNotNull (ex.Message, "#B5");
107 Assert.AreEqual (-2, ex.Number, "#B6");
108 Assert.AreEqual ((byte) 0, ex.State, "#B7");
113 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connB);
114 using (SqlDataReader reader = cmd.ExecuteReader ()) {
115 Assert.IsTrue (reader.Read (), "#C1");
116 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
117 Assert.IsFalse (reader.Read (), "#C3");
120 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connA);
121 using (SqlDataReader reader = cmd.ExecuteReader ()) {
122 Assert.IsTrue (reader.Read (), "#D1");
123 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#D2");
124 Assert.IsFalse (reader.Read (), "#D3");
133 conn = new SqlConnection (connectionString);
135 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
140 public void Commit_Connection_Closed ()
143 conn = new SqlConnection (connectionString);
146 trans = conn.BeginTransaction ();
148 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
149 SqlCommand cmd = new SqlCommand (sql, conn, trans);
150 cmd.ExecuteNonQuery ();
158 } catch (InvalidOperationException ex) {
159 // This SqlTransaction has completed; it is no
161 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
162 Assert.IsNull (ex.InnerException, "#A3");
163 Assert.IsNotNull (ex.Message, "#A4");
166 conn = new SqlConnection (connectionString);
169 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
170 using (SqlDataReader reader = cmd.ExecuteReader ()) {
171 Assert.IsFalse (reader.Read (), "#B");
179 conn = new SqlConnection (connectionString);
181 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
186 public void Commit_Reader_Open ()
189 Assert.Ignore ("NotWorking");
193 conn = new SqlConnection (connectionString);
196 trans = conn.BeginTransaction ();
199 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
200 cmd = new SqlCommand (sql, conn, trans);
201 cmd.ExecuteNonQuery ();
204 cmd = new SqlCommand ("select @@version", conn, trans);
205 using (SqlDataReader reader = cmd.ExecuteReader ()) {
209 } catch (InvalidOperationException ex) {
210 // There is already an open DataReader
211 // associated with this Command which
212 // must be closed first
213 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
214 Assert.IsNull (ex.InnerException, "#A3");
215 Assert.IsNotNull (ex.Message, "#A4");
219 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn, trans);
220 using (SqlDataReader reader = cmd.ExecuteReader ()) {
221 Assert.IsTrue (reader.Read (), "#B1");
229 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
230 using (SqlDataReader reader = cmd.ExecuteReader ()) {
231 Assert.IsFalse (reader.Read (), "#C1");
239 conn = new SqlConnection (connectionString);
241 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
246 public void Commit_Transaction_Committed ()
249 conn = new SqlConnection (connectionString);
252 using (trans = conn.BeginTransaction ()) {
253 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
254 SqlCommand cmd = new SqlCommand (sql, conn, trans);
255 cmd.ExecuteNonQuery ();
263 } catch (InvalidOperationException ex) {
264 // This SqlTransaction has completed; it is no
266 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
267 Assert.IsNull (ex.InnerException, "#A3");
268 Assert.IsNotNull (ex.Message, "#A4");
271 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
272 using (SqlDataReader reader = cmd.ExecuteReader ()) {
273 Assert.IsTrue (reader.Read (), "#B1");
274 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#B2");
275 Assert.IsFalse (reader.Read (), "#B3");
279 conn = new SqlConnection (connectionString);
282 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
283 using (SqlDataReader reader = cmd.ExecuteReader ()) {
284 Assert.IsTrue (reader.Read (), "#C1");
285 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
286 Assert.IsFalse (reader.Read (), "#C3");
293 conn = new SqlConnection (connectionString);
295 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
300 public void Commit_Transaction_Disposed ()
303 conn = new SqlConnection (connectionString);
306 using (trans = conn.BeginTransaction ()) {
307 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
308 SqlCommand cmd = new SqlCommand (sql, conn, trans);
309 cmd.ExecuteNonQuery ();
317 } catch (InvalidOperationException ex) {
318 // This SqlTransaction has completed; it is no
320 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
321 Assert.IsNull (ex.InnerException, "#A3");
322 Assert.IsNotNull (ex.Message, "#A4");
325 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
326 using (SqlDataReader reader = cmd.ExecuteReader ()) {
327 Assert.IsFalse (reader.Read (), "#B1");
334 conn = new SqlConnection (connectionString);
336 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
341 public void Commit_Transaction_Rolledback ()
344 Assert.Ignore ("NotWorking");
347 conn = new SqlConnection (connectionString);
350 using (trans = conn.BeginTransaction ()) {
351 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
352 SqlCommand cmd = new SqlCommand (sql, conn, trans);
353 cmd.ExecuteNonQuery ();
361 } catch (InvalidOperationException ex) {
362 // This SqlTransaction has completed; it is no
364 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
365 Assert.IsNull (ex.InnerException, "#A3");
366 Assert.IsNotNull (ex.Message, "#A4");
369 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
370 using (SqlDataReader reader = cmd.ExecuteReader ()) {
371 Assert.IsFalse (reader.Read (), "#B1");
375 using (trans = conn.BeginTransaction ()) {
376 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
377 SqlCommand cmd = new SqlCommand (sql, conn, trans);
378 cmd.ExecuteNonQuery ();
381 trans.Save ("SAVE1");
383 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
384 cmd = new SqlCommand (sql, conn, trans);
385 cmd.ExecuteNonQuery ();
388 trans.Rollback ("SAVE1");
391 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
392 using (SqlDataReader reader = cmd.ExecuteReader ()) {
393 Assert.IsTrue (reader.Read (), "#D1");
394 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#D2");
395 Assert.IsFalse (reader.Read (), "#D3");
398 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
399 using (SqlDataReader reader = cmd.ExecuteReader ()) {
400 Assert.IsFalse (reader.Read (), "#E1");
407 conn = new SqlConnection (connectionString);
409 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
414 public void Connection_Transaction_Committed ()
416 conn = new SqlConnection (connectionString);
419 trans = conn.BeginTransaction ();
422 Assert.IsNull (trans.Connection);
426 public void Connection_Transaction_Disposed ()
428 conn = new SqlConnection (connectionString);
431 trans = conn.BeginTransaction ();
434 Assert.IsNull (trans.Connection);
438 public void Connection_Transaction_Open ()
440 conn = new SqlConnection (connectionString);
443 trans = conn.BeginTransaction ();
445 Assert.AreSame (conn, trans.Connection);
449 public void Connection_Transaction_Rolledback ()
452 Assert.Ignore ("NotWorking");
454 conn = new SqlConnection (connectionString);
457 trans = conn.BeginTransaction ();
460 Assert.IsNull (trans.Connection);
465 trans = conn.BeginTransaction ();
466 trans.Save ("SAVE1");
468 trans.Rollback ("SAVE1");
469 Assert.AreSame (conn, trans.Connection);
476 public void Connection_Transaction_Saved ()
478 conn = new SqlConnection (connectionString);
481 trans = conn.BeginTransaction ();
482 trans.Save ("SAVE1");
484 Assert.AreSame (conn, trans.Connection);
488 public void Dispose ()
491 SqlCommand cmd = null;
494 conn = new SqlConnection (connectionString);
497 trans = conn.BeginTransaction ();
499 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
500 cmd = new SqlCommand (sql, conn, trans);
501 cmd.ExecuteNonQuery ();
504 trans.Save ("SAVE1");
506 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
507 cmd = new SqlCommand (sql, conn, trans);
508 cmd.ExecuteNonQuery ();
514 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
515 using (SqlDataReader reader = cmd.ExecuteReader ()) {
516 Assert.IsFalse (reader.Read (), "#1");
519 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
520 using (SqlDataReader reader = cmd.ExecuteReader ()) {
521 Assert.IsFalse (reader.Read (), "#2");
531 conn = new SqlConnection (connectionString);
533 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
538 public void Dispose_Connection_Closed ()
541 conn = new SqlConnection (connectionString);
544 trans = conn.BeginTransaction ();
546 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
547 SqlCommand cmd = new SqlCommand (sql, conn, trans);
548 cmd.ExecuteNonQuery ();
555 conn = new SqlConnection (connectionString);
558 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
559 using (SqlDataReader reader = cmd.ExecuteReader ()) {
560 Assert.IsFalse (reader.Read ());
568 conn = new SqlConnection (connectionString);
570 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
575 public void Dispose_Reader_Open ()
578 Assert.Ignore ("NotWorking");
581 conn = new SqlConnection (connectionString);
584 trans = conn.BeginTransaction ();
586 SqlCommand cmd = new SqlCommand ("select * from employee", conn, trans);
587 using (SqlDataReader reader = cmd.ExecuteReader ()) {
591 } catch (InvalidOperationException ex) {
592 // There is already an open DataReader
593 // associated with this Connection
594 // which must be closed first
595 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
596 Assert.IsNull (ex.InnerException, "#A3");
597 Assert.IsNotNull (ex.Message, "#A4");
603 } catch (InvalidOperationException ex) {
604 // There is already an open DataReader
605 // associated with this Connection
606 // which must be closed first
607 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
608 Assert.IsNull (ex.InnerException, "#B3");
609 Assert.IsNotNull (ex.Message, "#B4");
623 public void IsolationLevel_Reader_Open ()
625 conn = new SqlConnection (connectionString);
628 trans = conn.BeginTransaction ();
631 SqlCommand cmd = new SqlCommand ("select @@version", conn, trans);
632 using (SqlDataReader reader = cmd.ExecuteReader ()) {
633 Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel);
642 public void IsolationLevel_Transaction_Committed ()
644 conn = new SqlConnection (connectionString);
647 trans = conn.BeginTransaction ();
651 IsolationLevel iso = trans.IsolationLevel;
652 Assert.Fail ("#1:" + iso);
653 } catch (InvalidOperationException ex) {
654 // This SqlTransaction has completed; it is no
656 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
657 Assert.IsNull (ex.InnerException, "#3");
658 Assert.IsNotNull (ex.Message, "#4");
663 public void IsolationLevel_Transaction_Disposed ()
665 conn = new SqlConnection (connectionString);
668 trans = conn.BeginTransaction ();
672 IsolationLevel iso = trans.IsolationLevel;
673 Assert.Fail ("#1:" + iso);
674 } catch (InvalidOperationException ex) {
675 // This SqlTransaction has completed; it is no
677 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
678 Assert.IsNull (ex.InnerException, "#3");
679 Assert.IsNotNull (ex.Message, "#4");
684 public void IsolationLevel_Transaction_Open ()
686 conn = new SqlConnection (connectionString);
689 trans = conn.BeginTransaction ();
690 Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel);
694 public void IsolationLevel_Transaction_Rolledback ()
697 Assert.Ignore ("NotWorking");
699 conn = new SqlConnection (connectionString);
702 trans = conn.BeginTransaction ();
706 IsolationLevel iso = trans.IsolationLevel;
707 Assert.Fail ("#A1:" + iso);
708 } catch (InvalidOperationException ex) {
709 // This SqlTransaction has completed; it is no
711 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
712 Assert.IsNull (ex.InnerException, "#A3");
713 Assert.IsNotNull (ex.Message, "#A4");
718 trans = conn.BeginTransaction ();
719 trans.Save ("SAVE1");
720 trans.Rollback ("SAVE1");
722 Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel, "#B1");
726 public void IsolationLevel_Transaction_Saved ()
728 conn = new SqlConnection (connectionString);
731 trans = conn.BeginTransaction ();
732 trans.Save ("SAVE1");
733 Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel);
736 [Test] // Rollback ()
737 public void Rollback1 ()
740 SqlCommand cmd = null;
741 SqlConnection connA = null;
742 SqlConnection connB = null;
745 connA = new SqlConnection (connectionString);
748 connB = new SqlConnection (connectionString);
751 using (trans = connA.BeginTransaction ()) {
752 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
753 cmd = new SqlCommand (sql, connA, trans);
754 cmd.ExecuteNonQuery ();
757 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connA, trans);
758 using (SqlDataReader reader = cmd.ExecuteReader ()) {
759 Assert.IsTrue (reader.Read (), "#A1");
760 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#A2");
761 Assert.IsFalse (reader.Read (), "#A3");
766 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connA);
767 using (SqlDataReader reader = cmd.ExecuteReader ()) {
768 Assert.IsFalse (reader.Read (), "#B1");
771 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", connB);
772 using (SqlDataReader reader = cmd.ExecuteReader ()) {
773 Assert.IsFalse (reader.Read (), "#C1");
784 conn = new SqlConnection (connectionString);
786 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
790 conn = new SqlConnection (connectionString);
793 trans = conn.BeginTransaction ();
795 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
796 cmd = new SqlCommand (sql, conn, trans);
797 cmd.ExecuteNonQuery ();
800 trans.Save ("SAVE1");
802 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
803 cmd = new SqlCommand (sql, conn, trans);
804 cmd.ExecuteNonQuery ();
807 trans.Save ("SAVE2");
809 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6668, 'Novell', '1997-04-07', '2003-06-25')";
810 cmd = new SqlCommand (sql, conn, trans);
811 cmd.ExecuteNonQuery ();
817 conn = new SqlConnection (connectionString);
820 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
821 using (SqlDataReader reader = cmd.ExecuteReader ()) {
822 Assert.IsFalse (reader.Read (), "#D1");
825 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
826 using (SqlDataReader reader = cmd.ExecuteReader ()) {
827 Assert.IsFalse (reader.Read (), "#E1");
830 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6668", conn);
831 using (SqlDataReader reader = cmd.ExecuteReader ()) {
832 Assert.IsFalse (reader.Read (), "#F1");
842 conn = new SqlConnection (connectionString);
844 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
848 conn = new SqlConnection (connectionString);
851 trans = conn.BeginTransaction ();
859 [Test] // Rollback ()
860 public void Rollback1_Connection_Closed ()
863 conn = new SqlConnection (connectionString);
866 trans = conn.BeginTransaction ();
868 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
869 SqlCommand cmd = new SqlCommand (sql, conn, trans);
870 cmd.ExecuteNonQuery ();
878 } catch (InvalidOperationException ex) {
879 // This SqlTransaction has completed; it is no
881 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
882 Assert.IsNull (ex.InnerException, "#A3");
883 Assert.IsNotNull (ex.Message, "#A4");
886 conn = new SqlConnection (connectionString);
889 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
890 using (SqlDataReader reader = cmd.ExecuteReader ()) {
891 Assert.IsFalse (reader.Read (), "#B1");
897 conn = new SqlConnection (connectionString);
899 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
903 [Test] // Rollback ()
904 public void Rollback1_Reader_Open ()
907 Assert.Ignore ("NotWorking");
911 conn = new SqlConnection (connectionString);
914 trans = conn.BeginTransaction ();
917 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
918 cmd = new SqlCommand (sql, conn, trans);
919 cmd.ExecuteNonQuery ();
922 cmd = new SqlCommand ("select @@version", conn, trans);
923 using (SqlDataReader reader = cmd.ExecuteReader ()) {
927 } catch (InvalidOperationException ex) {
928 // There is already an open DataReader
929 // associated with this Command which
930 // must be closed first
931 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
932 Assert.IsNull (ex.InnerException, "#3");
933 Assert.IsNotNull (ex.Message, "#4");
942 [Test] // Rollback ()
943 public void Rollback1_Transaction_Committed ()
946 conn = new SqlConnection (connectionString);
949 using (trans = conn.BeginTransaction ()) {
950 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
951 SqlCommand cmd = new SqlCommand (sql, conn, trans);
952 cmd.ExecuteNonQuery ();
960 } catch (InvalidOperationException ex) {
961 // This SqlTransaction has completed; it is no
963 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
964 Assert.IsNull (ex.InnerException, "#A3");
965 Assert.IsNotNull (ex.Message, "#A4");
968 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
969 using (SqlDataReader reader = cmd.ExecuteReader ()) {
970 Assert.IsTrue (reader.Read (), "#B1");
971 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#B2");
972 Assert.IsFalse (reader.Read (), "#B3");
976 conn = new SqlConnection (connectionString);
979 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
980 using (SqlDataReader reader = cmd.ExecuteReader ()) {
981 Assert.IsTrue (reader.Read (), "#C1");
982 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
983 Assert.IsFalse (reader.Read (), "#C3");
990 conn = new SqlConnection (connectionString);
992 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
996 [Test] // Rollback ()
997 public void Rollback1_Transaction_Disposed ()
1000 conn = new SqlConnection (connectionString);
1003 using (trans = conn.BeginTransaction ()) {
1004 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1005 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1006 cmd.ExecuteNonQuery ();
1012 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1013 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1014 Assert.IsFalse (reader.Read (), "#B1");
1021 conn = new SqlConnection (connectionString);
1023 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1027 [Test] // Rollback ()
1028 public void Rollback1_Transaction_Rolledback ()
1031 Assert.Ignore ("NotWorking");
1034 conn = new SqlConnection (connectionString);
1037 using (trans = conn.BeginTransaction ()) {
1038 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1039 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1040 cmd.ExecuteNonQuery ();
1047 Assert.Fail ("#A1");
1048 } catch (InvalidOperationException ex) {
1049 // This SqlTransaction has completed; it is no
1051 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1052 Assert.IsNull (ex.InnerException, "#A3");
1053 Assert.IsNotNull (ex.Message, "#A4");
1056 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1057 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1058 Assert.IsFalse (reader.Read (), "#B1");
1062 using (trans = conn.BeginTransaction ()) {
1063 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1064 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1065 cmd.ExecuteNonQuery ();
1068 trans.Save ("SAVE1");
1070 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
1071 cmd = new SqlCommand (sql, conn, trans);
1072 cmd.ExecuteNonQuery ();
1075 trans.Rollback ("SAVE1");
1077 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn, trans);
1078 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1079 Assert.IsTrue (reader.Read (), "#C1");
1080 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
1081 Assert.IsFalse (reader.Read (), "#C3");
1086 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1087 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1088 Assert.IsFalse (reader.Read (), "#D1");
1095 conn = new SqlConnection (connectionString);
1097 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1101 [Test] // Rollback (String)
1102 public void Rollback2 ()
1105 Assert.Ignore ("NotWorking");
1108 SqlCommand cmd = null;
1111 conn = new SqlConnection (connectionString);
1114 trans = conn.BeginTransaction ();
1116 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1117 cmd = new SqlCommand (sql, conn, trans);
1118 cmd.ExecuteNonQuery ();
1121 trans.Save ("SAVE1");
1123 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
1124 cmd = new SqlCommand (sql, conn, trans);
1125 cmd.ExecuteNonQuery ();
1128 trans.Save ("SAVE2");
1130 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6668, 'Novell', '1997-04-07', '2003-06-25')";
1131 cmd = new SqlCommand (sql, conn, trans);
1132 cmd.ExecuteNonQuery ();
1135 trans.Save ("SAVE3");
1137 trans.Rollback ("SAVE1");
1141 conn = new SqlConnection (connectionString);
1144 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1145 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1146 Assert.IsTrue (reader.Read (), "#A1");
1147 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#A2");
1148 Assert.IsFalse (reader.Read (), "#A3");
1151 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
1152 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1153 Assert.IsFalse (reader.Read (), "#B1");
1156 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6668", conn);
1157 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1158 Assert.IsFalse (reader.Read (), "#C1");
1168 conn = new SqlConnection (connectionString);
1170 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1174 conn = new SqlConnection (connectionString);
1177 trans = conn.BeginTransaction ();
1179 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1180 cmd = new SqlCommand (sql, conn, trans);
1181 cmd.ExecuteNonQuery ();
1184 trans.Save ("SAVE1");
1186 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
1187 cmd = new SqlCommand (sql, conn, trans);
1188 cmd.ExecuteNonQuery ();
1191 trans.Save ("SAVE2");
1193 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6668, 'Novell', '1997-04-07', '2003-06-25')";
1194 cmd = new SqlCommand (sql, conn, trans);
1195 cmd.ExecuteNonQuery ();
1198 trans.Save ("SAVE1");
1200 trans.Rollback ("SAVE1");
1204 conn = new SqlConnection (connectionString);
1207 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1208 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1209 Assert.IsTrue (reader.Read (), "#D1");
1210 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#D2");
1211 Assert.IsFalse (reader.Read (), "#D3");
1214 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
1215 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1216 Assert.IsTrue (reader.Read (), "#E1");
1217 Assert.AreEqual ("BangaloreNovell", reader.GetString (0), "#E2");
1218 Assert.IsFalse (reader.Read (), "#E3");
1221 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6668", conn);
1222 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1223 Assert.IsTrue (reader.Read (), "#F1");
1224 Assert.AreEqual ("Novell", reader.GetString (0), "#F2");
1225 Assert.IsFalse (reader.Read (), "#F3");
1235 conn = new SqlConnection (connectionString);
1237 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1241 [Test] // Rollback (String)
1242 public void Rollback2_Connection_Closed ()
1245 conn = new SqlConnection (connectionString);
1248 trans = conn.BeginTransaction ();
1250 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1251 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1252 cmd.ExecuteNonQuery ();
1258 trans.Rollback ("SAVE1");
1259 Assert.Fail ("#A1");
1260 } catch (InvalidOperationException ex) {
1261 // This SqlTransaction has completed; it is no
1263 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1264 Assert.IsNull (ex.InnerException, "#A3");
1265 Assert.IsNotNull (ex.Message, "#A4");
1268 conn = new SqlConnection (connectionString);
1271 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1272 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1273 Assert.IsFalse (reader.Read (), "#B");
1281 conn = new SqlConnection (connectionString);
1283 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1287 [Test] // Rollback (String)
1288 public void Rollback2_Reader_Open ()
1291 Assert.Ignore ("NotWorking");
1295 conn = new SqlConnection (connectionString);
1298 trans = conn.BeginTransaction ();
1301 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1302 cmd = new SqlCommand (sql, conn, trans);
1303 cmd.ExecuteNonQuery ();
1306 trans.Save ("SAVE1");
1308 cmd = new SqlCommand ("select @@version", conn, trans);
1309 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1311 trans.Rollback ("SAVE1");
1313 } catch (InvalidOperationException ex) {
1314 // There is already an open DataReader
1315 // associated with this Command which
1316 // must be closed first
1317 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1318 Assert.IsNull (ex.InnerException, "#3");
1319 Assert.IsNotNull (ex.Message, "#4");
1328 [Test] // Rollback (String)
1329 public void Rollback2_Transaction_Committed ()
1332 conn = new SqlConnection (connectionString);
1335 using (trans = conn.BeginTransaction ()) {
1336 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1337 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1338 cmd.ExecuteNonQuery ();
1344 trans.Rollback ("SAVE1");
1345 Assert.Fail ("#A1");
1346 } catch (InvalidOperationException ex) {
1347 // This SqlTransaction has completed; it is no
1349 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1350 Assert.IsNull (ex.InnerException, "#A3");
1351 Assert.IsNotNull (ex.Message, "#A4");
1354 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1355 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1356 Assert.IsTrue (reader.Read (), "#B1");
1357 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#B2");
1358 Assert.IsFalse (reader.Read (), "#B3");
1362 conn = new SqlConnection (connectionString);
1365 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1366 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1367 Assert.IsTrue (reader.Read (), "#C1");
1368 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
1369 Assert.IsFalse (reader.Read (), "#C3");
1376 conn = new SqlConnection (connectionString);
1378 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1382 [Test] // Rollback (String)
1383 public void Rollback2_Transaction_Disposed ()
1386 Assert.Ignore ("NotWorking");
1389 conn = new SqlConnection (connectionString);
1392 using (trans = conn.BeginTransaction ()) {
1393 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1394 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1395 cmd.ExecuteNonQuery ();
1401 trans.Rollback ("SAVE1");
1402 Assert.Fail ("#A1");
1403 } catch (InvalidOperationException ex) {
1404 // This SqlTransaction has completed; it is no
1406 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1407 Assert.IsNull (ex.InnerException, "#A3");
1408 Assert.IsNotNull (ex.Message, "#A4");
1411 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1412 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1413 Assert.IsFalse (reader.Read (), "#B1");
1420 conn = new SqlConnection (connectionString);
1422 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1426 [Test] // Rollback (String)
1427 public void Rollback2_Transaction_Rolledback ()
1430 Assert.Ignore ("NotWorking");
1433 conn = new SqlConnection (connectionString);
1436 using (trans = conn.BeginTransaction ()) {
1437 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1438 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1439 cmd.ExecuteNonQuery ();
1445 trans.Rollback ("SAVE1");
1446 Assert.Fail ("#A1");
1447 } catch (InvalidOperationException ex) {
1448 // This SqlTransaction has completed; it is no
1450 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1451 Assert.IsNull (ex.InnerException, "#A3");
1452 Assert.IsNotNull (ex.Message, "#A4");
1455 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1456 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1457 Assert.IsFalse (reader.Read (), "#B1");
1461 using (trans = conn.BeginTransaction ()) {
1462 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1463 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1464 cmd.ExecuteNonQuery ();
1467 trans.Save ("SAVE1");
1468 trans.Rollback ("SAVE1");
1471 trans.Rollback ("SAVE1");
1472 Assert.Fail ("#C1");
1473 } catch (SqlException ex) {
1474 // Cannot roll back SAVE1. No transaction
1475 // or savepoint of that name was found
1476 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#C2");
1477 Assert.AreEqual ((byte) 16, ex.Class, "#C3");
1478 Assert.IsNull (ex.InnerException, "#C4");
1479 Assert.IsNotNull (ex.Message, "#C5");
1480 Assert.IsTrue (ex.Message.IndexOf ("SAVE1") != -1, "#C6");
1481 Assert.AreEqual (6401, ex.Number, "#C7");
1482 Assert.AreEqual ((byte) 1, ex.State, "#C8");
1485 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn, trans);
1486 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1487 Assert.IsTrue (reader.Read (), "#D1");
1494 conn = new SqlConnection (connectionString);
1496 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1500 [Test] // Rollback (String)
1501 public void Rollback2_TransactionName_DoesNotExist ()
1503 conn = new SqlConnection (connectionString);
1506 using (trans = conn.BeginTransaction ()) {
1508 trans.Rollback ("SAVE1");
1510 } catch (SqlException ex) {
1511 // Cannot roll back SAVE1. No transaction
1512 // or savepoint of that name was found
1513 Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
1514 Assert.AreEqual ((byte) 16, ex.Class, "#3");
1515 Assert.IsNull (ex.InnerException, "#4");
1516 Assert.IsNotNull (ex.Message, "#5");
1517 Assert.IsTrue (ex.Message.IndexOf ("SAVE1") != -1, "#6");
1518 Assert.AreEqual (6401, ex.Number, "#7");
1519 if (ClientVersion == 7)
1520 Assert.AreEqual ((byte) 2, ex.State, "#8");
1522 Assert.AreEqual ((byte) 1, ex.State, "#8");
1529 [Test] // Rollback (String)
1530 public void Rollback2_TransactionName_Empty ()
1533 Assert.Ignore ("NotWorking");
1535 conn = new SqlConnection (connectionString);
1538 using (trans = conn.BeginTransaction ()) {
1540 trans.Rollback (string.Empty);
1542 } catch (ArgumentException ex) {
1543 // Invalid transaction or invalid name
1544 // for a point at which to save within
1546 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1547 Assert.IsNull (ex.InnerException, "#3");
1548 Assert.IsNotNull (ex.Message, "#4");
1549 Assert.IsNull (ex.ParamName, "#5");
1556 [Test] // Rollback (String)
1557 public void Rollback2_TransactionName_Null ()
1560 Assert.Ignore ("NotWorking");
1562 conn = new SqlConnection (connectionString);
1565 using (trans = conn.BeginTransaction ()) {
1567 trans.Rollback ((string) null);
1569 } catch (ArgumentException ex) {
1570 // Invalid transaction or invalid name
1571 // for a point at which to save within
1573 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1574 Assert.IsNull (ex.InnerException, "#3");
1575 Assert.IsNotNull (ex.Message, "#4");
1576 Assert.IsNull (ex.ParamName, "#5");
1584 public void Save_Connection_Closed ()
1587 conn = new SqlConnection (connectionString);
1590 trans = conn.BeginTransaction ();
1592 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1593 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1594 cmd.ExecuteNonQuery ();
1600 trans.Save ("SAVE1");
1601 Assert.Fail ("#A1");
1602 } catch (InvalidOperationException ex) {
1603 // This SqlTransaction has completed; it is no
1605 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1606 Assert.IsNull (ex.InnerException, "#A3");
1607 Assert.IsNotNull (ex.Message, "#A4");
1610 conn = new SqlConnection (connectionString);
1613 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1614 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1615 Assert.IsFalse (reader.Read (), "#B1");
1623 conn = new SqlConnection (connectionString);
1625 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1633 SqlCommand cmd = null;
1636 conn = new SqlConnection (connectionString);
1639 trans = conn.BeginTransaction ();
1641 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1642 cmd = new SqlCommand (sql, conn, trans);
1643 cmd.ExecuteNonQuery ();
1646 trans.Save ("SAVE1");
1648 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
1649 cmd = new SqlCommand (sql, conn, trans);
1650 cmd.ExecuteNonQuery ();
1653 trans.Save ("SAVE2");
1655 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6668, 'Novell', '1997-04-07', '2003-06-25')";
1656 cmd = new SqlCommand (sql, conn, trans);
1657 cmd.ExecuteNonQuery ();
1662 conn = new SqlConnection (connectionString);
1665 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1666 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1667 Assert.IsFalse (reader.Read (), "#A1");
1670 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
1671 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1672 Assert.IsFalse (reader.Read (), "#B1");
1675 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6668", conn);
1676 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1677 Assert.IsFalse (reader.Read (), "#C1");
1687 conn = new SqlConnection (connectionString);
1689 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1693 conn = new SqlConnection (connectionString);
1696 trans = conn.BeginTransaction ();
1698 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1699 cmd = new SqlCommand (sql, conn, trans);
1700 cmd.ExecuteNonQuery ();
1703 trans.Save ("SAVE1");
1705 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6667, 'BangaloreNovell', '1999-03-10', '2006-08-23')";
1706 cmd = new SqlCommand (sql, conn, trans);
1707 cmd.ExecuteNonQuery ();
1710 trans.Save ("SAVE2");
1712 sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6668, 'Novell', '1997-04-07', '2003-06-25')";
1713 cmd = new SqlCommand (sql, conn, trans);
1714 cmd.ExecuteNonQuery ();
1719 conn = new SqlConnection (connectionString);
1722 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1723 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1724 Assert.IsTrue (reader.Read (), "#D1");
1725 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#D2");
1726 Assert.IsFalse (reader.Read (), "#D3");
1729 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6667", conn);
1730 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1731 Assert.IsTrue (reader.Read (), "#E1");
1732 Assert.AreEqual ("BangaloreNovell", reader.GetString (0), "#E2");
1733 Assert.IsFalse (reader.Read (), "#E3");
1736 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6668", conn);
1737 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1738 Assert.IsTrue (reader.Read (), "#F1");
1739 Assert.AreEqual ("Novell", reader.GetString (0), "#F2");
1740 Assert.IsFalse (reader.Read (), "#F3");
1750 conn = new SqlConnection (connectionString);
1752 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1757 public void Save_Reader_Open ()
1760 Assert.Ignore ("NotWorking");
1764 conn = new SqlConnection (connectionString);
1767 trans = conn.BeginTransaction ();
1770 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1771 cmd = new SqlCommand (sql, conn, trans);
1772 cmd.ExecuteNonQuery ();
1775 cmd = new SqlCommand ("select @@version", conn, trans);
1776 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1778 trans.Save ("SAVE1");
1780 } catch (InvalidOperationException ex) {
1781 // There is already an open DataReader
1782 // associated with this Command which
1783 // must be closed first
1784 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1785 Assert.IsNull (ex.InnerException, "#3");
1786 Assert.IsNotNull (ex.Message, "#4");
1796 public void Save_Transaction_Committed ()
1799 conn = new SqlConnection (connectionString);
1802 using (trans = conn.BeginTransaction ()) {
1803 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1804 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1805 cmd.ExecuteNonQuery ();
1811 trans.Save ("SAVE1");
1812 Assert.Fail ("#A1");
1813 } catch (InvalidOperationException ex) {
1814 // This SqlTransaction has completed; it is no
1816 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1817 Assert.IsNull (ex.InnerException, "#A3");
1818 Assert.IsNotNull (ex.Message, "#A4");
1821 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1822 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1823 Assert.IsTrue (reader.Read (), "#B1");
1824 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#B2");
1825 Assert.IsFalse (reader.Read (), "#B3");
1829 conn = new SqlConnection (connectionString);
1832 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1833 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1834 Assert.IsTrue (reader.Read (), "#C1");
1835 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#C2");
1836 Assert.IsFalse (reader.Read (), "#C3");
1843 conn = new SqlConnection (connectionString);
1845 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1850 public void Save_Transaction_Disposed ()
1853 Assert.Ignore ("NotWorking");
1856 conn = new SqlConnection (connectionString);
1859 using (trans = conn.BeginTransaction ()) {
1860 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1861 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1862 cmd.ExecuteNonQuery ();
1868 trans.Save ("SAVE1");
1869 Assert.Fail ("#A1");
1870 } catch (InvalidOperationException ex) {
1871 // This SqlTransaction has completed; it is no
1873 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1874 Assert.IsNull (ex.InnerException, "#A3");
1875 Assert.IsNotNull (ex.Message, "#A4");
1878 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1879 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1880 Assert.IsFalse (reader.Read (), "#B1");
1887 conn = new SqlConnection (connectionString);
1889 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1894 public void Save_Transaction_Rolledback ()
1897 Assert.Ignore ("NotWorking");
1900 conn = new SqlConnection (connectionString);
1903 using (trans = conn.BeginTransaction ()) {
1904 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1905 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1906 cmd.ExecuteNonQuery ();
1912 trans.Save ("SAVE1");
1913 Assert.Fail ("#A1");
1914 } catch (InvalidOperationException ex) {
1915 // This SqlTransaction has completed; it is no
1917 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1918 Assert.IsNull (ex.InnerException, "#A3");
1919 Assert.IsNotNull (ex.Message, "#A4");
1922 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1923 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1924 Assert.IsFalse (reader.Read (), "#B1");
1928 using (trans = conn.BeginTransaction ()) {
1929 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1930 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1931 cmd.ExecuteNonQuery ();
1934 trans.Save ("SAVE1");
1935 trans.Rollback ("SAVE1");
1936 trans.Save ("SAVE1");
1938 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn, trans);
1939 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1940 Assert.IsTrue (reader.Read (), "#D1");
1947 conn = new SqlConnection (connectionString);
1949 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
1954 public void Save_TransactionName_Empty ()
1957 Assert.Ignore ("NotWorking");
1960 conn = new SqlConnection (connectionString);
1963 trans = conn.BeginTransaction ();
1965 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
1966 SqlCommand cmd = new SqlCommand (sql, conn, trans);
1967 cmd.ExecuteNonQuery ();
1971 trans.Save (string.Empty);
1972 Assert.Fail ("#A1");
1973 } catch (ArgumentException ex) {
1974 // Invalid transaction or invalid name
1975 // for a point at which to save within
1977 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1978 Assert.IsNull (ex.InnerException, "#A3");
1979 Assert.IsNotNull (ex.Message, "#A4");
1980 Assert.IsNull (ex.ParamName, "#A5");
1986 conn = new SqlConnection (connectionString);
1989 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
1990 using (SqlDataReader reader = cmd.ExecuteReader ()) {
1991 Assert.IsFalse (reader.Read (), "#B1");
1999 conn = new SqlConnection (connectionString);
2001 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
2006 public void Save_TransactionName_Null ()
2009 Assert.Ignore ("NotWorking");
2012 conn = new SqlConnection (connectionString);
2015 trans = conn.BeginTransaction ();
2017 string sql = "INSERT INTO employee (id, fname, dob, doj) VALUES (6666, 'NovellBangalore', '1989-02-11', '2005-07-22')";
2018 SqlCommand cmd = new SqlCommand (sql, conn, trans);
2019 cmd.ExecuteNonQuery ();
2023 trans.Save ((string) null);
2024 Assert.Fail ("#A1");
2025 } catch (ArgumentException ex) {
2026 // Invalid transaction or invalid name
2027 // for a point at which to save within
2029 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
2030 Assert.IsNull (ex.InnerException, "#A3");
2031 Assert.IsNotNull (ex.Message, "#A4");
2032 Assert.IsNull (ex.ParamName, "#A5");
2038 conn = new SqlConnection (connectionString);
2041 cmd = new SqlCommand ("SELECT fname FROM employee WHERE id=6666", conn);
2042 using (SqlDataReader reader = cmd.ExecuteReader ()) {
2043 Assert.IsTrue (reader.Read (), "#B1");
2044 Assert.AreEqual ("NovellBangalore", reader.GetString (0), "#B2");
2045 Assert.IsFalse (reader.Read (), "#B3");
2053 conn = new SqlConnection (connectionString);
2055 DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
2061 return (engine.ClientVersion);
2065 static bool RunningOnMono {
2068 return (Type.GetType ("System.MonoType", false) != null);