Ejemplo n.º 1
0
        public void TestCreateRetrieveAndDeleteRow()
        {
            DBHelper dbHelper = new DBHelper(DatabaseType.MicrosoftSQLServer);
            SetupTestDatabaseForMSSQL(dbHelper);

            Query q = new Query("INSERT INTO test_table (ID, Description) "+
                                "VALUES (1, 'ettal')");
            SqlResult result = dbHelper.executeQuery(q);
            Assert.IsNotNull(result);

            Query q2 = new Query("SELECT Description "+
                                    "FROM test_table "+
                                    "WHERE ID=1");
            result = dbHelper.executeQuery(q2);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.DataRemaining());

            result.NextRow();
            var strResult = result.ReadString("Description");
            Assert.AreEqual("ettal", strResult);

            Query q3 = new Query("DELETE FROM test_table  " +
                                "WHERE ID=1");
            result = dbHelper.executeQuery(q3);
            Assert.IsNotNull(result);

            result = dbHelper.executeQuery(q2);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.AmountOfRows() == 0);
        }
Ejemplo n.º 2
0
        public void TestDateTime()
        {
            DBHelper dbHelper = new DBHelper(DatabaseType.MicrosoftSQLServer);
            SetupTestDatabaseForMSSQL(dbHelper);

            Query q = new Query("INSERT INTO test_table (ID, DateCreated) " +
                                "VALUES (1, @dateCreated)");
            q.addDateTimeParameter("datecreated", DateTime.Today.Date);
            SqlResult result = dbHelper.executeQuery(q);
            Assert.IsNotNull(result);

            Query q2 = new Query("SELECT DateCreated " +
                                    "FROM test_table " +
                                    "WHERE ID=1");
            result = dbHelper.executeQuery(q2);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.DataRemaining());

            result.NextRow();
            Assert.AreEqual(DateTime.Today.Date, result.ReadDateTime("DateCreated"));

            Query q3 = new Query("DELETE FROM test_table  " +
                                "WHERE ID=1");
            result = dbHelper.executeQuery(q3);
            Assert.IsNotNull(result);
        }
Ejemplo n.º 3
0
        public void TestConnectToDatabase()
        {
            DBHelper dbHelper = new DBHelper(DatabaseType.MicrosoftSQLServer);
            SetupTestDatabaseForMSSQL(dbHelper);

            Query q = new Query("SELECT DB_NAME() AS Name");
            SqlResult result = dbHelper.executeQuery(q);

            Assert.IsNotNull(result);

            result.NextRow();

            var strResult = result.ReadString("Name");

            Assert.AreEqual("testing", strResult);
        }
Ejemplo n.º 4
0
        public void TestIntParametrization()
        {
            DBHelper dbHelper = new DBHelper(DatabaseType.MicrosoftSQLServer);
            SetupTestDatabaseForMSSQL(dbHelper);

            Query q = new Query("INSERT INTO test_table (ID, Description) " +
                                "VALUES (@id, 'ettal')");
            q.addIntParameter("id", 1);
            SqlResult result = dbHelper.executeQuery(q);
            Assert.IsNotNull(result);

            Query q2 = new Query("SELECT Description " +
                                    "FROM test_table " +
                                    "WHERE ID=@id");
            q2.addIntParameter("id", 1);
            result = dbHelper.executeQuery(q2);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.DataRemaining());

            result.NextRow();
            var strResult = result.ReadString("Description");
            Assert.AreEqual("ettal", strResult);

            Query q3 = new Query("DELETE FROM test_table  " +
                                "WHERE ID=1");
            result = dbHelper.executeQuery(q3);
            Assert.IsNotNull(result);
        }