// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using NUnit.Framework;
-using System.Data.OracleClient;
-using System.Data;
using System;
+using System.Data;
+using System.Data.OracleClient;
+using System.Data.SqlClient;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.OracleClient
+{
+ [TestFixture]
+ public class OracleCommandTest
+ {
+ const string COMMAND_TEXT = "SELECT * FROM dual";
+
+ OracleCommand command;
+ IDbCommand interface_command;
+
+ [SetUp]
+ public void SetUp ()
+ {
+ command = new OracleCommand ();
+ interface_command = command;
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ command.Dispose ();
+ }
+
+ [Test] // ctor ()
+ public void Constructor1 ()
+ {
+ OracleCommand cmd = new OracleCommand ();
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
+ Assert.IsNull (cmd.Connection, "#4");
+ Assert.IsNull (cmd.Container, "#5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#6");
+ Assert.IsNotNull (cmd.Parameters, "#7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#8");
+ Assert.IsNull (cmd.Site, "#9");
+ Assert.IsNull (cmd.Transaction, "#10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#11");
+ }
+
+ [Test] // ctor (String)
+ public void Constructor2 ()
+ {
+ OracleCommand cmd = new OracleCommand (COMMAND_TEXT);
+ Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+ Assert.IsNull (cmd.Connection, "#A4");
+ Assert.IsNull (cmd.Container, "#A5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+ Assert.IsNotNull (cmd.Parameters, "#A7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+ Assert.IsNull (cmd.Site, "#A9");
+ Assert.IsNull (cmd.Transaction, "#A10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+ cmd = new OracleCommand ((string) null);
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+ Assert.IsNull (cmd.Connection, "#B4");
+ Assert.IsNull (cmd.Container, "#B5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+ Assert.IsNotNull (cmd.Parameters, "#B7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+ Assert.IsNull (cmd.Site, "#B9");
+ Assert.IsNull (cmd.Transaction, "#B10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+ }
+
+ [Test] // ctor (String, OracleConnection)
+ public void Constructor3 ()
+ {
+ OracleConnection conn = new OracleConnection ();
+ OracleCommand cmd;
+
+ cmd = new OracleCommand (COMMAND_TEXT, conn);
+ Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+ Assert.AreSame (conn, cmd.Connection, "#A4");
+ Assert.IsNull (cmd.Container, "#A5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+ Assert.IsNotNull (cmd.Parameters, "#A7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+ Assert.IsNull (cmd.Site, "#A9");
+ Assert.IsNull (cmd.Transaction, "#A10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+ cmd = new OracleCommand ((string) null, conn);
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+ Assert.AreSame (conn, cmd.Connection, "#B4");
+ Assert.IsNull (cmd.Container, "#B5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+ Assert.IsNotNull (cmd.Parameters, "#B7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+ Assert.IsNull (cmd.Site, "#B9");
+ Assert.IsNull (cmd.Transaction, "#B10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+ cmd = new OracleCommand (COMMAND_TEXT, (OracleConnection) null);
+ Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#C2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+ Assert.IsNull (cmd.Connection, "#C4");
+ Assert.IsNull (cmd.Container, "#C5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+ Assert.IsNotNull (cmd.Parameters, "#C7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+ Assert.IsNull (cmd.Site, "#C9");
+ Assert.IsNull (cmd.Transaction, "#C10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+ }
+
+ [Test] // ctor (String, OracleConnection, OracleTransaction)
+ public void Constructor4 ()
+ {
+ OracleConnection conn = new OracleConnection ();
+ OracleCommand cmd;
+
+ cmd = new OracleCommand (COMMAND_TEXT, conn, (OracleTransaction) null);
+ Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+ Assert.AreSame (conn, cmd.Connection, "#A4");
+ Assert.IsNull (cmd.Container, "#A5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+ Assert.IsNotNull (cmd.Parameters, "#A7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+ Assert.IsNull (cmd.Site, "#A9");
+ Assert.IsNull (cmd.Transaction, "#A10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+ cmd = new OracleCommand ((string) null, conn, (OracleTransaction) null);
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+ Assert.AreSame (conn, cmd.Connection, "#B4");
+ Assert.IsNull (cmd.Container, "#B5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+ Assert.IsNotNull (cmd.Parameters, "#B7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+ Assert.IsNull (cmd.Site, "#B9");
+ Assert.IsNull (cmd.Transaction, "#B10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+ cmd = new OracleCommand (COMMAND_TEXT, (OracleConnection) null, (OracleTransaction) null);
+ Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+#if NET_2_0
+ Assert.AreEqual (0, cmd.CommandTimeout, "#C2");
+#endif
+ Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+ Assert.IsNull (cmd.Connection, "#C4");
+ Assert.IsNull (cmd.Container, "#C5");
+ Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+ Assert.IsNotNull (cmd.Parameters, "#C7");
+ Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+ Assert.IsNull (cmd.Site, "#C9");
+ Assert.IsNull (cmd.Transaction, "#C10");
+ Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+ }
+
+ [Test] // bug #78765
+ public void AllowNullTransactionTest ()
+ {
+ command.Transaction = null;
+ interface_command.Transaction = null;
+ }
+
+ [Test]
+ public void CommandText ()
+ {
+ OracleCommand cmd = new OracleCommand ();
+ cmd.CommandText = COMMAND_TEXT;
+ Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
+ cmd.CommandText = null;
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
+ cmd.CommandText = COMMAND_TEXT;
+ Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
+ cmd.CommandText = string.Empty;
+ Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
+ }
+
+#if NET_2_0
+ [Test]
+ public void CommandTimeout ()
+ {
+ Assert.AreEqual (0, command.CommandTimeout, "#1");
+ command.CommandTimeout = 10;
+ Assert.AreEqual (0, command.CommandTimeout, "#2");
+ command.CommandTimeout = int.MaxValue;
+ Assert.AreEqual (0, command.CommandTimeout, "#3");
+ command.CommandTimeout = int.MinValue;
+ Assert.AreEqual (0, command.CommandTimeout, "#4");
+ }
+#endif
+
+ [Test]
+ public void ConnectionTimeout_IDbConnection ()
+ {
+ Assert.AreEqual (0, interface_command.CommandTimeout, "#1");
+ interface_command.CommandTimeout = 10;
+ Assert.AreEqual (0, interface_command.CommandTimeout, "#2");
+ interface_command.CommandTimeout = int.MaxValue;
+ Assert.AreEqual (0, interface_command.CommandTimeout, "#3");
+ interface_command.CommandTimeout = int.MinValue;
+ Assert.AreEqual (0, interface_command.CommandTimeout, "#4");
+ }
+
+ [Test]
+ public void Connection ()
+ {
+ OracleConnection connection = new OracleConnection ();
+
+ Assert.IsNull (command.Connection, "#1");
+ command.Connection = connection;
+ Assert.AreSame (connection, command.Connection, "#2");
+ Assert.AreSame (connection, interface_command.Connection, "#3");
+ command.Connection = null;
+ Assert.IsNull (command.Connection, "#4");
+ Assert.IsNull (interface_command.Connection, "#5");
+ }
+
+ [Test]
+ public void Connection_IDbConnection ()
+ {
+ OracleConnection connection = new OracleConnection ();
+
+ Assert.IsNull (interface_command.Connection, "#A1");
+ interface_command.Connection = connection;
+ Assert.AreSame (connection, interface_command.Connection, "#A2");
+ Assert.AreSame (connection, command.Connection, "#A3");
+ interface_command.Connection = null;
+ Assert.IsNull (interface_command.Connection, "#A4");
+ Assert.IsNull (command.Connection, "#A5");
-namespace MonoTests.System.Data.OracleClient {
-
- [TestFixture]
- public class OracleCommandTest {
-
- OracleCommand command;
- IDbCommand interface_command;
-
- [SetUp]
- public void SetUp ()
- {
- command = new OracleCommand ();
- interface_command = command;
- }
-
- [TearDown]
- public void TearDown ()
- {
- command.Dispose ();
- }
-
- [Test] // regression for bug #78765
- public void AllowNullConnectionTest ()
- {
- command.Connection = null;
- try {
- interface_command.Connection = null;
- }
- catch (Exception) {
- Assert.Fail ("Connection property should be nullable");
- }
- }
-
- [Test] // regression for bug #78765
- public void AllowNullTransactionTest ()
- {
- command.Transaction = null;
- try {
- interface_command.Transaction = null;
- }
- catch (Exception) {
- Assert.Fail ("Transaction property should be nullable");
- }
- }
- }
-}
\ No newline at end of file
+ try {
+ interface_command.Connection = new SqlConnection ();
+ Assert.Fail ("#B1");
+ } catch (InvalidCastException ex) {
+ Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ }
+ }
+ }
+}