Esempio n. 1
0
        public void TestQueryDataReaderWithParameter()
        {
            //arrange
            bool expect = true;
            bool actual = true;
            IDatabaseAccess target = new OracleClientDataAccess(this._ConnectionString);
            IDataReader result;
            DataAccessCommand command = new DataAccessCommand();
            List<Chatroom> roomCollection;

            //act
            command.SqlCommand = @"
            SELECT *
              FROM TABLE
             WHERE COLUMNNAME=:ID";
            command.AddParameter("ID", 150376);
            try
            {
                result = target.QueryWithDataReader(command);
                roomCollection = new List<Chatroom>();
                while (result.Read())
                {
                    roomCollection.Add(
                        new Chatroom(
                            result.GetInt32(result.GetOrdinal("ID")),
                            result.GetDateTime(result.GetOrdinal("ACTDATE")),
                            result.GetString(result.GetOrdinal("FLICODE")),
                            result.GetString(result.GetOrdinal("DPORT")))
                    );
                }

                actual = (roomCollection.Count > 0);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                target.CloseConnection();
            }

            //assert
            Assert.AreEqual(expect, actual);
        }
Esempio n. 2
0
        public void TestQueryDatareaderException()
        {
            bool expect = true;
            bool actual = true;
            IDatabaseAccess target = new OracleClientDataAccess(this._ConnectionString);
            IDataReader result;
            DataAccessCommand command = new DataAccessCommand();
            List<Chatroom> roomCollection;
            string errMessage = "";

            //act
            command.SqlCommand = @"
            SELECT *
              FROM TABLE
             WHERE ID=:ROOM_ID";
            command.AddParameter("ROOM_ID", 150376);
            try
            {
                result = target.QueryWithDataReader(command);
                roomCollection = new List<Chatroom>();
                while (result.Read())
                {
                    roomCollection.Add(
                        new Chatroom(
                            result.GetInt32(result.GetOrdinal("ROOM_ID")),
                            result.GetDateTime(result.GetOrdinal("ACTDATE")),
                            result.GetString(result.GetOrdinal("FLICODE")),
                            result.GetString(result.GetOrdinal("DPORT")))
                    );
                }
            }
            catch (CommandExecutionExeception ex)
            {
                errMessage = ex.DetailErrorMessage;
                actual = (errMessage != "");
            }
            finally
            {
                target.CloseConnection();
            }

            //assert
            Assert.AreEqual(expect, actual);
        }