Esempio n. 1
0
        public void TestSelectCellCanReturnLongDataType()
        {
            var xQuery = new XQuerySqlite(SetUp.SqliteConnectionString);
            var result = xQuery.SelectCellAs <long>("select 100;");

            Assert.AreEqual(100L, result);
        }
Esempio n. 2
0
        public void TestSelectCellCanReturnDoubleDataType()
        {
            var xQuery = new XQuerySqlite(SetUp.SqliteConnectionString);
            var result = xQuery.SelectCellAs <double>("select 1.1;");

            Assert.AreEqual(1.1d, result);
        }
Esempio n. 3
0
        public void TestSelectCellCanReturnStringDataType()
        {
            var xQuery = new XQuerySqlite(SetUp.SqliteConnectionString);
            var result = xQuery.SelectCellAs <string>("select 'asd';");

            Assert.AreEqual("asd", result);
        }
Esempio n. 4
0
        public void TestSelectCellReturnsDefaultValueOnError()
        {
            const string defValue = "default";
            var          xQuery   = new XQuerySqlite(SetUp.SqliteConnectionString);
            var          result   = xQuery.SelectCellAs("select 1.1;", defValue);

            Assert.AreEqual(defValue, result);
        }
Esempio n. 5
0
        public void TestSelectCellReturnsValueIfNoErrors()
        {
            const string defValue    = "default";
            const string nonDefValue = "non default";
            var          xQuery      = new XQuerySqlite(SetUp.SqliteConnectionString);
            var          result      = xQuery.SelectCellAs($"select '{nonDefValue}';", defValue);

            Assert.AreEqual(nonDefValue, result);
        }
Esempio n. 6
0
        public void TestSelectCellThrowsDataExceptionOnEmptyResult()
        {
            const string sqlSelect = "select;";
            var          xQuery    = new XQuerySqlite(SetUp.SqliteConnectionString);

            Assert.Throws(Is.TypeOf <DataException>(), delegate
            {
                xQuery.SelectCellAs <long>(sqlSelect);
            });
        }
Esempio n. 7
0
        public void TestSelectCellThrowsFormatException()
        {
            const string sqlSelect = "select 1;";
            var          xQuery    = new XQuerySqlite(SetUp.SqliteConnectionString);

            Assert.Throws(Is.TypeOf <FormatException>(), delegate
            {
                xQuery.SelectCellAs <string>(sqlSelect);
            });
        }
Esempio n. 8
0
        public void TestConnectionIsOpenAfterSelect()
        {
            const string sqlSelect = "select 123;";
            var          xQuery    = new XQuerySqlite()
            {
                ConnectionString   = SetUp.SqliteConnectionString,
                KeepConnectionOpen = true
            };

            xQuery.SelectCellAs <long>(sqlSelect);
            Assert.IsTrue(xQuery.IsConnectionActive);
        }
Esempio n. 9
0
        public void TestConnectionIsBeingClosedByChangingKeepConnectionOpen()
        {
            const string select = "select 123;";
            var          xQuery = new XQuerySqlite()
            {
                ConnectionString   = SetUp.SqliteConnectionString,
                KeepConnectionOpen = true
            };

            xQuery.SelectCellAs <long>(select);
            xQuery.KeepConnectionOpen = false;
            Assert.IsFalse(xQuery.IsConnectionActive);
        }
Esempio n. 10
0
        public void TestSelectBinaryDataFromCell()
        {
            const string sqlCreateTable = "create table test (bin blob);";
            const string sqlInsertBin   = "insert into test (bin) values (@bin);";
            var          binData        = new byte[] { 1, 0, 1, 1, 0, 1, 1, 0 };

            var xQuery = new XQuerySqlite(SetUp.SqliteConnectionString);

            xQuery.BeginTransaction();
            xQuery.Create(sqlCreateTable);
            xQuery.InsertBinaryIntoCell(binData, sqlInsertBin, "@bin");
            var result = xQuery.SelectCellAs <byte[]>("select bin from test");

            Assert.AreEqual(binData, result);
        }
Esempio n. 11
0
        public void TestErrorIsLogged()
        {
            const string sqlSelect = "select 1, 2, 3;";
            var          xQuery    = new XQuerySqlite(SetUp.SqliteConnectionString);

            xQuery.OnError += XQuery_OnError;
            try
            {
                xQuery.SelectCellAs <long>(sqlSelect);
            }
            catch (Exception)
            {
                // ignored
            }

            Assert.IsNotEmpty(xQuery.LastErrorMessage);
        }
Esempio n. 12
0
        public void TestArithmeticOperationWithSelectCell()
        {
            var xQuery = new XQuerySqlite(SetUp.SqliteConnectionString);

            Assert.AreEqual(30, xQuery.SelectCellAs <long>("select 10+20;"));
        }