Beispiel #1
0
        public void ExecuteSqlStringWithoutParametersButWithValues()
        {
            using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
            {
                using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
                {
                    string sql = "select * from TestTable";

                    DbParameter[] parameters = new DbParameter[]
                    {
                        database.CreateParameter("@Param1", DbType.Int32, 0, 1),
                        database.CreateParameter("@Param2", DbType.String, 50, "Uno")
                    };

                    using (IDataReader reader = database.ExecuteReader(sql, parameters))
                    {
                        reader.Read();
                        Assert.AreEqual(1, reader["TestColumn"]);
                        Assert.AreEqual("Uno", reader["TestColumn2"]);
                        reader.Read();
                        Assert.AreEqual(2, reader["TestColumn"]);
                        Assert.AreEqual("Dos", reader["TestColumn2"]);
                        reader.Read();
                        Assert.AreEqual(3, reader["TestColumn"]);
                        Assert.AreEqual("Tres", reader["TestColumn2"]);
                        reader.Read();
                        Assert.AreEqual(4, reader["TestColumn"]);
                        Assert.AreEqual("Cuatro", reader["TestColumn2"]);
                    }
                }
            }
        }
Beispiel #2
0
        public void WhatGetsReturnedWhenWeDoAnInsertThroughDbCommandExecute()
        {
            using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
            {
                int         count  = -1;
                IDataReader reader = null;

                using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
                {
                    try
                    {
                        string insertString = @"insert into TestTable values (5, 'Cinco')";

                        reader = database.ExecuteReader(insertString);
                        count  = reader.RecordsAffected;
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }

                        string deleteString = "Delete from TestTable where TestColumn = 5";
                        database.ExecuteNonQuery(deleteString);
                    }

                    Assert.AreEqual(1, count);
                }
            }
        }
Beispiel #3
0
 public void ExecuteReaderWithEmptyStringThrows()
 {
     using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
     {
         using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
         {
             database.ExecuteReader(String.Empty);
         }
     }
 }
Beispiel #4
0
 public void ExecuteReaderWithNullDbCommandThrows()
 {
     using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
     {
         using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
         {
             database.ExecuteReader((DbCommand)null);
         }
     }
 }
Beispiel #5
0
        public void CanExecuteReaderWithCommandText()
        {
            using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
            {
                using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
                {
                    string queryString = @"select * from TestTable";

                    string accumulator = "";
                    using (IDataReader reader = database.ExecuteReader(queryString))
                    {
                        while (reader.Read())
                        {
                            accumulator += ((string)reader["TestColumn2"]).Trim();
                        }
                    }

                    Assert.AreEqual("UnoDosTresCuatro", accumulator);
                }
            }
        }
Beispiel #6
0
        public void ExecuteSqlStringCommandWithParameters()
        {
            using (TestResourceFile dbFile = new TestResourceFile(this, "Datastore.sdf"))
            {
                using (SmartClientDatabase database = DatabaseFactory.CreateDatabase() as SmartClientDatabase)
                {
                    string sql = "select * from TestTable where (TestColumn=@Param1) and TestColumn2=@Param2";

                    DbParameter[] parameters = new DbParameter[]
                    {
                        database.CreateParameter("@Param1", DbType.Int32, 0, 1),
                        database.CreateParameter("@Param2", DbType.String, 50, "Uno")
                    };

                    using (IDataReader reader = database.ExecuteReader(sql, parameters))
                    {
                        reader.Read();
                        Assert.AreEqual(1, reader["TestColumn"]);
                        Assert.AreEqual("Uno", reader["TestColumn2"]);
                    }
                }
            }
        }