public void Test_CloseConnection_WithNoConnection_ShouldThrow()
        {
            var oraConn = new OracleConnection("conn_string", new TimeSpan(0, 0, 10));

            Assert.That(oraConn.IsConnected, Is.False);
            Assert.Throws <InvalidOperationException>(() => oraConn.CloseConnection());
        }
        public void Test_CloseConnection()
        {
            var oraConn = new OracleConnection("conn_string", new TimeSpan(0, 0, 10));

            oraConn.OpenConnection();
            Assert.That(oraConn.IsConnected, Is.True);

            oraConn.CloseConnection();
            Assert.That(oraConn.IsConnected, Is.False);
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     Console.WriteLine("DBCONNECTION - ABSTRACT");
     while (true)
     {
         System.Console.WriteLine("Enter 1 if you wish to continue else any other number to exit!");
         int Contin = Convert.ToInt32(Console.ReadLine());
         if (Contin.Equals(1))
         {
             //break;
         }
         else
         {
             break;
         }
         System.Console.WriteLine("Enter which DB to connect 1.SQL, 2.ORACLE");
         string Dbchoice = Console.ReadLine();
         //var ObjDb = new DbConnection();
         System.Console.WriteLine("ENter the Connection string");
         string ConnectionString = Console.ReadLine();
         try
         {
             if (Dbchoice == "1")
             {
                 var ObjDb = new SqlConnection(ConnectionString);
                 ObjDb.OpenConnection();
                 ObjDb.CloseConnection();
             }
             else if (Dbchoice == "2")
             {
                 var ObjDb = new OracleConnection(ConnectionString);
                 ObjDb.OpenConnection();
                 ObjDb.CloseConnection();
             }
             else
             {
                 System.Console.WriteLine("Enter a valid DB connection!");
                 continue;
             }
         }
         catch (System.Exception e)
         {
             System.Console.WriteLine(e.Message);
             continue;
             //throw;
         }
         //ObjDb.OpenConnection();
         //ObjDb.CloseConnection();
     }
 }
Esempio n. 4
0
        private static void Main()
        {
            var sql    = new SqlConnection("1");
            var oracle = new OracleConnection("2");

            sql.OpenConnection();
            oracle.OpenConnection();
            oracle.CloseConnection();
            sql.CloseConnection();

            var command1 = new DbCommand(new SqlConnection("1"), "Adam is the best SQL");
            var command2 = new DbCommand(new OracleConnection("2"), "Adam is the best Oracle");

            command1.Execute();
            command2.Execute();
        }
Esempio n. 5
0
        private static void TimeoutTester(OracleConnection connection, Operation op)
        {
            var startTime = DateTime.Now;

            try
            {
                while (true)
                {
                    switch (op)
                    {
                    case Operation.Open:
                        connection.OpenConnection();
                        break;

                    case Operation.Close:
                        connection.CloseConnection();
                        break;

                    default:
                        break;
                    }
                    if (DateTime.Now.Subtract(startTime).TotalSeconds > connection.Timeout.TotalSeconds)
                    {
                        connection.LogConnectionStatus(connection, false, op);
                        throw new TimeoutException();
                    }
                    else
                    {
                        connection.LogConnectionStatus(connection, true, op);
                        break;
                    }
                }
            }
            catch (ArgumentException)
            {
                throw;
            }
        }