Esempio n. 1
0
        private T WithConnection <T>(Func <DbConnection, T> func)
        {
            var connection = _commandFactory.CreateConnection();
            T   result;

            var wasOpenedManually = false;

            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                    wasOpenedManually = true;
                }

                result = func(connection);
            }
            finally
            {
                if (wasOpenedManually)
                {
                    connection.Dispose();
                }
            }

            return(result);
        }
Esempio n. 2
0
        public void SetUp()
        {
            _commandFactory = Substitute.For <IDbCommandFactory>();
            _logger         = Substitute.For <ISqlCommandLogger>();
            _executor       = new DbCommandExecutor(_logger, _commandFactory);

            _command    = new TestDbCommand();
            _connection = new TestDbConnection();

            _command.StubScalarResult = 1;
            _command.StubDataReader   = new TestDbDataReader()
            {
                ResultSet = new ResultSet(new[] { new Row(new[] { new ColumnValue("Id", 1), }), })
            };
            _commandFactory.CreateConnection().Returns(_connection);
        }
        public void SetUp()
        {
            _commandFactory = Substitute.For<IDbCommandFactory>();
            _logger = Substitute.For<ISqlCommandLogger>();
            _executor = new DbCommandExecutor(_logger, _commandFactory);

            _command = new TestDbCommand();
            _connection = new TestDbConnection();

            _command.StubScalarResult = 1;
            _command.StubDataReader = new TestDbDataReader() { ResultSet = new ResultSet(new[] { new Row(new[] { new ColumnValue("Id", 1), }), }) };
            _commandFactory.CreateConnection().Returns(_connection);
        }