Author: gert
Date: 2007-10-18 04:55:05 -0400 (Thu, 18 Oct 2007)
New Revision: 87736

Added:
   trunk/gert/standalone/bug333082/Assert.cs
Modified:
   trunk/gert/standalone/bug333082/default.build
   trunk/gert/standalone/bug333082/test.cs
Log:
Improved test.


Added: trunk/gert/standalone/bug333082/Assert.cs
===================================================================
--- trunk/gert/standalone/bug333082/Assert.cs   2007-10-18 08:36:46 UTC (rev 
87735)
+++ trunk/gert/standalone/bug333082/Assert.cs   2007-10-18 08:55:05 UTC (rev 
87736)
@@ -0,0 +1,47 @@
+using System;
+using System.Data;
+using System.Globalization;
+
+class Assert
+{
+       public static void AreEqual (string x, string y, string msg)
+       {
+               if (x != y)
+                       throw new Exception (string.Format 
(CultureInfo.InvariantCulture,
+                               "Expected: {0}, but was: {1}. {2}",
+                               x, y, msg));
+       }
+
+       public static void AreEqual (IsolationLevel x, IsolationLevel y, string 
msg)
+       {
+               if (x != y)
+                       throw new Exception (string.Format 
(CultureInfo.InvariantCulture,
+                               "Expected: {0}, but was: {1}. {2}",
+                               x, y, msg));
+       }
+
+       public static void AreEqual (object x, object y, string msg)
+       {
+               if (x != y)
+                       throw new Exception (string.Format 
(CultureInfo.InvariantCulture,
+                               "Expected: {0}, but was: {1}. {2}",
+                               x, y, msg));
+       }
+
+       public static void Fail (string msg)
+       {
+               throw new Exception (msg);
+       }
+
+       public static void IsNotNull (object value, string msg)
+       {
+               if (value == null)
+                       throw new Exception (msg);
+       }
+
+       public static void IsNull (object value, string msg)
+       {
+               if (value != null)
+                       throw new Exception (msg);
+       }
+}


Property changes on: trunk/gert/standalone/bug333082/Assert.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/gert/standalone/bug333082/default.build
===================================================================
--- trunk/gert/standalone/bug333082/default.build       2007-10-18 08:36:46 UTC 
(rev 87735)
+++ trunk/gert/standalone/bug333082/default.build       2007-10-18 08:55:05 UTC 
(rev 87736)
@@ -44,6 +44,7 @@
        <target name="compile">
                <csc target="exe" define="${csc.defines}" output="test.exe" 
warnaserror="true" warninglevel="4">
                        <sources>
+                               <include name="Assert.cs" />
                                <include name="test.cs" />
                        </sources>
                        <references>

Modified: trunk/gert/standalone/bug333082/test.cs
===================================================================
--- trunk/gert/standalone/bug333082/test.cs     2007-10-18 08:36:46 UTC (rev 
87735)
+++ trunk/gert/standalone/bug333082/test.cs     2007-10-18 08:55:05 UTC (rev 
87736)
@@ -1,6 +1,7 @@
 using System;
 using System.Data;
 using System.Data.SqlClient;
+using System.Globalization;
 using System.Text;
 
 class Program
@@ -12,75 +13,128 @@
                conn.Open ();
 
                IsolationLevel level = GetIsolationLevel (conn, null);
-               if (level != IsolationLevel.ReadCommitted)
-                       return 1;
+               Assert.AreEqual (IsolationLevel.ReadCommitted, level, "#A");
 
                ChangeIsolationLevel (conn, null, "SERIALIZABLE");
 
                level = GetIsolationLevel (conn, null);
-               if (level != IsolationLevel.Serializable)
-                       return 2;
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#B");
 
                SqlTransaction trans = conn.BeginTransaction ();
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.ReadCommitted)
-                       return 3;
-               if (trans.IsolationLevel != IsolationLevel.ReadCommitted)
-                       return 4;
+               Assert.AreEqual (IsolationLevel.ReadCommitted, level, "#C1");
+               Assert.AreEqual (IsolationLevel.ReadCommitted, 
trans.IsolationLevel, "#C2");
                ChangeIsolationLevel (conn, trans, "SERIALIZABLE");
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.Serializable)
-                       return 5;
-               if (trans.IsolationLevel != IsolationLevel.ReadCommitted)
-                       return 6;
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#C3");
+               Assert.AreEqual (IsolationLevel.ReadCommitted, 
trans.IsolationLevel, "#C4");
                trans.Rollback ();
 
+               level = GetIsolationLevel (conn, null);
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#D");
+
 #if NET_2_0
                trans = conn.BeginTransaction (IsolationLevel.Unspecified);
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.ReadCommitted)
-                       return 7;
-               if (trans.IsolationLevel != IsolationLevel.ReadCommitted)
-                       return 8;
+               Assert.AreEqual (IsolationLevel.ReadCommitted, level, "#E1");
+               Assert.AreEqual (IsolationLevel.ReadCommitted, 
trans.IsolationLevel, "#E2");
                ChangeIsolationLevel (conn, trans, "SERIALIZABLE");
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.Serializable)
-                       return 9;
-               if (trans.IsolationLevel != IsolationLevel.ReadCommitted)
-                       return 10;
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#E3");
+               Assert.AreEqual (IsolationLevel.ReadCommitted, 
trans.IsolationLevel, "#E4");
                trans.Rollback ();
+#else
+               try {
+                       conn.BeginTransaction (IsolationLevel.Unspecified);
+                       Assert.Fail ("#E1");
+               } catch (ArgumentException ex) {
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType 
(), "#E2");
+                       Assert.IsNull (ex.InnerException, "#E3");
+                       Assert.IsNotNull (ex.Message, "#E4");
+                       Assert.AreEqual ("Invalid IsolationLevel parameter: 
must be ReadCommitted, ReadUncommitted, RepeatableRead, or Serializable.", 
ex.Message, "#E5");
+                       Assert.IsNull (ex.ParamName, "#E6");
+               }
 #endif
 
+               level = GetIsolationLevel (conn, null);
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#F");
+
                trans = conn.BeginTransaction (IsolationLevel.RepeatableRead);
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.RepeatableRead)
-                       return 11;
-               if (trans.IsolationLevel != IsolationLevel.RepeatableRead)
-                       return 12;
+               Assert.AreEqual (IsolationLevel.RepeatableRead, level, "#G1");
+               Assert.AreEqual (IsolationLevel.RepeatableRead, 
trans.IsolationLevel, "#G2");
                ChangeIsolationLevel (conn, trans, "SERIALIZABLE");
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.Serializable)
-                       return 13;
-               if (trans.IsolationLevel != IsolationLevel.RepeatableRead)
-                       return 14;
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#G3");
+               Assert.AreEqual (IsolationLevel.RepeatableRead, 
trans.IsolationLevel, "#G4");
                trans.Rollback ();
 
+               level = GetIsolationLevel (conn, null);
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#H");
+
 #if NET_2_0
                trans = conn.BeginTransaction (IsolationLevel.Snapshot);
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.Snapshot)
-                       return 15;
-               if (trans.IsolationLevel != IsolationLevel.Snapshot)
-                       return 16;
+               Assert.AreEqual (IsolationLevel.Snapshot, level, "#I1");
+               Assert.AreEqual (IsolationLevel.Snapshot, trans.IsolationLevel, 
"#I2");
                ChangeIsolationLevel (conn, trans, "SERIALIZABLE");
                level = GetIsolationLevel (conn, trans);
-               if (level != IsolationLevel.Serializable)
-                       return 17;
-               if (trans.IsolationLevel != IsolationLevel.Snapshot)
-                       return 18;
+               Assert.AreEqual (IsolationLevel.Serializable, level, "#I3");
+               Assert.AreEqual (IsolationLevel.Snapshot, trans.IsolationLevel, 
"#I4");
                trans.Rollback ();
 #endif
 
+               try {
+                       conn.BeginTransaction (IsolationLevel.Chaos);
+                       Assert.Fail ("#J1");
+#if NET_2_0
+               } catch (ArgumentOutOfRangeException ex) {
+                       Assert.AreEqual (typeof (ArgumentOutOfRangeException), 
ex.GetType (), "#J2");
+                       Assert.IsNull (ex.InnerException, "#J3");
+                       Assert.IsNotNull (ex.Message, "#J4");
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "The IsolationLevel enumeration value, 16, is " 
+
+                               "not supported by the .Net Framework SqlClient 
" +
+                               "Data Provider.{0}Parameter name: 
IsolationLevel",
+                               Environment.NewLine), ex.Message, "#J5");
+                       Assert.IsNotNull (ex.ParamName, "#J6");
+                       Assert.AreEqual ("IsolationLevel", ex.ParamName, "#J7");
+               }
+#else
+               } catch (ArgumentException ex) {
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType 
(), "#J2");
+                       Assert.IsNull (ex.InnerException, "#J3");
+                       Assert.IsNotNull (ex.Message, "#J4");
+                       Assert.AreEqual ("Invalid IsolationLevel parameter: 
must be ReadCommitted, ReadUncommitted, RepeatableRead, or Serializable.", 
ex.Message, "#J5");
+                       Assert.IsNull (ex.ParamName, "#J6");
+               }
+#endif
+
+               try {
+                       conn.BeginTransaction ((IsolationLevel) 666);
+                       Assert.Fail ("#K");
+#if NET_2_0
+               } catch (ArgumentOutOfRangeException ex) {
+                       Assert.AreEqual (typeof (ArgumentOutOfRangeException), 
ex.GetType (), "#K2");
+                       Assert.IsNull (ex.InnerException, "#K3");
+                       Assert.IsNotNull (ex.Message, "#K4");
+                       Assert.AreEqual (string.Format 
(CultureInfo.InvariantCulture,
+                               "The IsolationLevel enumeration value, 666, " +
+                               "is invalid.{0}Parameter name: IsolationLevel",
+                               Environment.NewLine), ex.Message, "#K5");
+                       Assert.IsNotNull (ex.ParamName, "#K6");
+                       Assert.AreEqual ("IsolationLevel", ex.ParamName, "#K7");
+               }
+#else
+               } catch (ArgumentException ex) {
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType 
(), "#K2");
+                       Assert.IsNull (ex.InnerException, "#K3");
+                       Assert.IsNotNull (ex.Message, "#K4");
+                       Assert.AreEqual ("Invalid IsolationLevel parameter: 
must be ReadCommitted, ReadUncommitted, RepeatableRead, or Serializable.", 
ex.Message, "#K5");
+                       Assert.IsNull (ex.ParamName, "#K6");
+               }
+#endif
+
                return 0;
        }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to