Exemplo n.º 1
0
        public async Task QueryTest()
        {
            this.Out("QueryTest Start.");
            for (var asyncType = 0; asyncType < 2; asyncType++)
            {
                for (var constructorType = 0; constructorType < 2; constructorType++)
                {
                    var db = (constructorType == 0)
                        ? this._dbDirect
                        : this._dbRef;

                    this.InitTables();

                    ResultTable rt  = null;
                    var         sql = "SELECT * FROM Test WHERE COL_STR LIKE '%B%' ORDER BY COL_STR ";
                    rt = (asyncType == 0)
                            ? db.Query(sql)
                            : await db.QueryAsync(sql);

                    Assert.AreEqual(4, rt.ColumnCount);
                    Assert.AreEqual(4, rt.RowCount);
                    Assert.AreEqual("COL_STR", rt.ColumnNames[0]);
                    Assert.AreEqual("COL_DEC", rt.ColumnNames[1]);
                    Assert.AreEqual("COL_INT", rt.ColumnNames[2]);
                    Assert.AreEqual("COL_DATETIME", rt.ColumnNames[3]);
                    Assert.AreEqual(0, rt.GetColumnIndex("COL_STR"));
                    Assert.AreEqual(1, rt.GetColumnIndex("COL_DEC"));
                    Assert.AreEqual(2, rt.GetColumnIndex("COL_INT"));
                    Assert.AreEqual(3, rt.GetColumnIndex("COL_DATETIME"));

                    Assert.AreEqual("ABC", rt.Rows[0]["COL_STR"]);
                    Assert.AreEqual((decimal)1, rt.Rows[0]["COL_DEC"]);
                    Assert.AreEqual(1, rt.Rows[0]["COL_INT"]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[0]["COL_DATETIME"]);
                    Assert.AreEqual("ABC", rt.Rows[0][0]);
                    Assert.AreEqual((decimal)1, rt.Rows[0][1]);
                    Assert.AreEqual(1, rt.Rows[0][2]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[0][3]);

                    Assert.AreEqual("ABC", rt.Rows[1]["COL_STR"]);
                    Assert.AreEqual((decimal)1, rt.Rows[1]["COL_DEC"]);
                    Assert.AreEqual(1, rt.Rows[1]["COL_INT"]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[1]["COL_DATETIME"]);
                    Assert.AreEqual("ABC", rt.Rows[1][0]);
                    Assert.AreEqual((decimal)1, rt.Rows[1][1]);
                    Assert.AreEqual(1, rt.Rows[1][2]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[1][3]);

                    Assert.AreEqual("ABC", rt.Rows[2]["COL_STR"]);
                    Assert.AreEqual((decimal)1, rt.Rows[2]["COL_DEC"]);
                    Assert.AreEqual(1, rt.Rows[2]["COL_INT"]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[2]["COL_DATETIME"]);
                    Assert.AreEqual("ABC", rt.Rows[2][0]);
                    Assert.AreEqual((decimal)1, rt.Rows[2][1]);
                    Assert.AreEqual(1, rt.Rows[2][2]);
                    Assert.AreEqual(DateTime.Parse("2001-01-01"), rt.Rows[2][3]);

                    Assert.AreEqual("BB", rt.Rows[3]["COL_STR"]);
                    Assert.AreEqual((decimal)12.345, rt.Rows[3]["COL_DEC"]);
                    Assert.AreEqual(12345, rt.Rows[3]["COL_INT"]);
                    Assert.AreEqual(DateTime.Parse("2016-12-13"), rt.Rows[3]["COL_DATETIME"]);
                    Assert.AreEqual("BB", rt.Rows[3][0]);
                    Assert.AreEqual((decimal)12.345, rt.Rows[3][1]);
                    Assert.AreEqual(12345, rt.Rows[3][2]);
                    Assert.AreEqual(DateTime.Parse("2016-12-13"), rt.Rows[3][3]);

                    sql = "SELECT * FROM Test WHERE COL_STR = 'NO-MATCH-ROW' ORDER BY COL_STR ";
                    rt  = (asyncType == 0)
                            ? db.Query(sql)
                            : await db.QueryAsync(sql);

                    Assert.IsFalse(rt == null);
                    Assert.AreEqual(4, rt.ColumnCount);
                    Assert.AreEqual(0, rt.RowCount);
                    Assert.AreEqual("COL_STR", rt.ColumnNames[0]);
                    Assert.AreEqual("COL_DEC", rt.ColumnNames[1]);
                    Assert.AreEqual("COL_INT", rt.ColumnNames[2]);
                    Assert.AreEqual("COL_DATETIME", rt.ColumnNames[3]);
                    Assert.AreEqual(0, rt.GetColumnIndex("COL_STR"));
                    Assert.AreEqual(1, rt.GetColumnIndex("COL_DEC"));
                    Assert.AreEqual(2, rt.GetColumnIndex("COL_INT"));
                    Assert.AreEqual(3, rt.GetColumnIndex("COL_DATETIME"));
                }
            }
            this.Out("QueryTest End.");
        }