Exemplo n.º 1
0
        void CheckGetParameter(string databaseProvider, string name)
        {
            if (databaseProvider == null)
            {
                throw new ArgumentNullException("databaseProvider");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            GlazeFactory factory = new GlazeFactory(databaseProvider);
            DbCommand    command = factory.CreateCommand();

            DbParameter dbParameter = command.CreateParameter();

            dbParameter.ParameterName = name;
            dbParameter.Value         = "value";
            command.Parameters.Add(dbParameter);

            DbParameter found = command.Parameters[name];

            Assert.IsNotNull(found);
            Assert.AreEqual("value", found.Value);

            DbParameter first = command.Parameters[0];

            Assert.IsNotNull(first);
            Assert.AreEqual("value", first.Value);
        }
Exemplo n.º 2
0
        void CheckAdd(string databaseProvider, string from, string to)
        {
            if (databaseProvider == null)
            {
                throw new ArgumentNullException("databaseProvider");
            }

            if (from == null)
            {
                throw new ArgumentNullException("from");
            }

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            GlazeFactory factory = new GlazeFactory(databaseProvider);
            DbCommand    command = factory.CreateCommand();

            DbParameter dbParameter = command.CreateParameter();

            dbParameter.ParameterName = from;
            dbParameter.Value         = "value";
            command.Parameters.Add(dbParameter);

            Assert.AreEqual(1, command.Parameters.Count);
            Assert.AreEqual(to, command.Parameters[0].ParameterName);
        }
Exemplo n.º 3
0
        void CheckDateTime(GlazeFactory glazeFactory, DbConnection connection)
        {
            if (glazeFactory == null)
            {
                throw new ArgumentNullException("glazeFactory");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            DbCommand command = glazeFactory.CreateCommand();

            command.Connection  = connection;
            command.CommandText = "SELECT 2007-07-18T16:30:00";
            object c = command.ExecuteScalar();

            Assert.IsNotNull(c);

            DateTime dt = ResultToDate(c);

            Assert.AreEqual(2007, dt.Year);
            Assert.AreEqual(7, dt.Month);
            Assert.AreEqual(18, dt.Day);
            Assert.AreEqual(16, dt.Hour);
            Assert.AreEqual(30, dt.Minute);
            Assert.AreEqual(0, dt.Second);

            command.CommandText = "SELECT EXTRACT(year FROM 2007-07-18T16:30:00)";
            c = command.ExecuteScalar();
            Assert.AreEqual(2007, c);

            command.CommandText = "SELECT EXTRACT(month FROM 2007-07-18T16:30:00)";
            c = command.ExecuteScalar();
            Assert.AreEqual(7, c);

            command.CommandText = "SELECT EXTRACT(day FROM 2007-07-18T16:30:00)";
            c = command.ExecuteScalar();
            Assert.AreEqual(18, c);

            command.CommandText = "SELECT EXTRACT(hour FROM 2007-07-18T16:30:00)";
            c = command.ExecuteScalar();
            Assert.AreEqual(16, c);

            command.CommandText = "SELECT EXTRACT(minute FROM 2007-07-18T16:30:00)";
            c = command.ExecuteScalar();
            Assert.AreEqual(30, c);

            command.CommandText = "SELECT EXTRACT(second FROM 2007-07-18T16:30:04)";
            c = command.ExecuteScalar();
            Assert.AreEqual(4, c);

            command.CommandText = "SELECT EXTRACT(second FROM null)";
            c = command.ExecuteScalar();
            Assert.AreEqual(DBNull.Value, c);
        }
Exemplo n.º 4
0
 public void TestDatabaseProvider()
 {
     string[] providers = TestUtil.Providers;
     for (int i = 0; i < providers.Length; ++i)
     {
         GlazeFactory glazeFactory = new GlazeFactory(providers[i]);
         GlazeCommand glazeCommand = (GlazeCommand)(glazeFactory.CreateCommand());
         Assert.AreEqual(providers[i], glazeCommand.DatabaseProvider);
     }
 }
Exemplo n.º 5
0
 public void TestCreateCommand()
 {
     string[] providers = TestUtil.Providers;
     for (int i = 0; i < providers.Length; ++i)
     {
         GlazeFactory glazeFactory = new GlazeFactory(providers[i]);
         DbCommand    command      = glazeFactory.CreateCommand();
         GlazeCommand glazeCommand = command as GlazeCommand;
         Assert.IsNotNull(glazeCommand);
     }
 }
Exemplo n.º 6
0
        public void TestCreateDataAdapter()
        {
            string[] providers = TestUtil.Providers;
            for (int i = 0; i < providers.Length; ++i)
            {
                GlazeFactory glazeFactory = new GlazeFactory(providers[i]);
                DbCommand    command      = glazeFactory.CreateCommand();
                Assert.IsNotNull(command);

                DbDataAdapter dataAdapter = glazeFactory.CreateDataAdapter();

                // can't be encapsulated because SelectCommand isn't virtual
                dataAdapter.SelectCommand = ((GlazeCommand)command).Inner;

                Assert.IsNotNull(dataAdapter.SelectCommand);
            }
        }
Exemplo n.º 7
0
        void CheckCommandText(GlazeFactory glazeFactory, DbConnection connection)
        {
            if (glazeFactory == null)
            {
                throw new ArgumentNullException("glazeFactory");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            DbCommand command = glazeFactory.CreateCommand();

            Assert.IsNotNull(command);
            Assert.AreEqual("", command.CommandText);
        }
Exemplo n.º 8
0
        void CheckBindByName(GlazeFactory glazeFactory, DbConnection connection)
        {
            if (glazeFactory == null)
            {
                throw new ArgumentNullException("glazeFactory");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            DbCommand command = glazeFactory.CreateCommand();

            Assert.IsNotNull(command);
            GlazeCommand glazeCommand = (GlazeCommand)command;

            Assert.IsFalse(glazeCommand.BindByName);

            glazeCommand.BindByName = true;
            Assert.IsTrue(glazeCommand.BindByName);
        }