public void ReadScalerDbNullReturnsNullObject()
        {
            DBNull scalerReturn = DBNull.Value;

            MockDatabaseFactory.SetScalerReturnValue(scalerReturn);
            var query       = new SQLQueryScaler <string>(sqlString);
            var returnValue = queryRunner.RunScalerQuery <string>(query);

            Assert.IsNull(returnValue);
            VerifyLogging(sqlString);
            Assert.AreEqual(sqlString, MockDatabaseFactory.DbCommand.Object.CommandText);
            MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1));
            MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Open(), Times.Exactly(1));
            MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Close(), Times.Exactly(1));
            MockDatabaseFactory.DbCommand.Verify(dbc => dbc.ExecuteScalarAsync(It.IsAny <System.Threading.CancellationToken>()), Times.Exactly(1));
        }
        public void Setup()
        {
            MockDatabaseFactory.DbParameter   = MockDatabaseFactory.CreateDbParameter();
            MockDatabaseFactory.Parameters    = MockDatabaseFactory.CreateParameterCollection();
            MockDatabaseFactory.DbConnection  = MockDatabaseFactory.CreateDbConnection();
            MockDatabaseFactory.DbCommand     = MockDatabaseFactory.CreateDbCommand();
            MockDatabaseFactory.DbTransaction = MockDatabaseFactory.CreateDbTransaction();
            MockDatabaseFactory.SetScalerReturnValue(scalerStringValue);

            queryRunner            = new QueryRunner(connectionString, provider, new MockDatabaseFactory());
            queryRunner.LogMessage = new Action <string, System.Diagnostics.TraceEventType>((message, level) =>
            {
                logMessage = message;
                logLevel   = level;
            });
            queryRunner.DebugLoggingEnabled = true;
            logMessage = string.Empty;
            logLevel   = System.Diagnostics.TraceEventType.Start;
        }
        public void ReadScalerIntReturnedAsIntAsync()
        {
            int scalerReturn = 555;

            MockDatabaseFactory.SetScalerReturnValue(scalerReturn);
            var query = new SQLQueryScaler <int>(sqlString);
            var task  = queryRunner.RunScalerQueryAsync <int>(query);

            task.Wait();
            var returnValue = task.Result;

            Assert.AreEqual(scalerReturn, returnValue);
            VerifyLogging(sqlString);
            Assert.AreEqual(sqlString, MockDatabaseFactory.DbCommand.Object.CommandText);
            MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1));
            MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Open(), Times.Exactly(1));
            MockDatabaseFactory.DbConnection.Verify(dbc => dbc.Close(), Times.Exactly(1));
            MockDatabaseFactory.DbCommand.Verify(dbc => dbc.ExecuteScalarAsync(It.IsAny <System.Threading.CancellationToken>()), Times.Exactly(1));
        }