public SqlReplayer(
            Func <QueryCriteria, IDataReader> dataRetriever,
            Func <QueryCriteria, Tuple <object> > scalarDataRetriever,
            Func <QueryCriteria, int?> nonQueryRowCountDataRetriever)
        {
            if (dataRetriever == null)
            {
                throw new ArgumentNullException(nameof(dataRetriever));
            }
            if (scalarDataRetriever == null)
            {
                throw new ArgumentNullException(nameof(scalarDataRetriever));
            }
            if (nonQueryRowCountDataRetriever == null)
            {
                throw new ArgumentNullException(nameof(nonQueryRowCountDataRetriever));
            }

            _dataRetriever                 = dataRetriever;
            _scalarDataRetriever           = scalarDataRetriever;
            _nonQueryRowCountDataRetriever = nonQueryRowCountDataRetriever;

            _connectionStore  = new Store <ConnectionId, IDbConnection>(() => new ConnectionId(Guid.NewGuid()));
            _commandStore     = new Store <CommandId, IDbCommand>(() => new CommandId(Guid.NewGuid()));
            _transactionStore = new Store <TransactionId, IDbTransaction>(() => new TransactionId(Guid.NewGuid()));
            _parameterStore   = new Store <ParameterId, IDbDataParameter>(() => new ParameterId(Guid.NewGuid()));
            _readerStore      = new Store <DataReaderId, IDataReader>(() => new DataReaderId(Guid.NewGuid()));

            // Parameters are not disposed of individually (unlike connections, commands, transactions and readers) - instead, the parameters in
            // the parameter store must be removed when the command that created them is disposed. The information to do that is recorded here.
            _parametersToTidy = new ConcurrentParameterToCommandLookup();
        }
Example #2
0
        public SqlProxy(
            Func <IDbConnection> connectionGenerator,
            Action <QueryCriteria> queryRecorder,
            Action <QueryCriteria> scalarQueryRecorder,
            Action <QueryCriteria> nonQueryRowCountRecorder)
        {
            if (connectionGenerator == null)
            {
                throw new ArgumentNullException(nameof(connectionGenerator));
            }
            if (queryRecorder == null)
            {
                throw new ArgumentNullException(nameof(queryRecorder));
            }
            if (scalarQueryRecorder == null)
            {
                throw new ArgumentNullException(nameof(scalarQueryRecorder));
            }
            if (nonQueryRowCountRecorder == null)
            {
                throw new ArgumentNullException(nameof(nonQueryRowCountRecorder));
            }

            _connectionGenerator      = connectionGenerator;
            _queryRecorder            = queryRecorder;
            _scalarQueryRecorder      = scalarQueryRecorder;
            _nonQueryRowCountRecorder = nonQueryRowCountRecorder;

            _connectionStore  = new Store <ConnectionId, IDbConnection>(() => new ConnectionId(Guid.NewGuid()));
            _commandStore     = new Store <CommandId, IDbCommand>(() => new CommandId(Guid.NewGuid()));
            _transactionStore = new Store <TransactionId, IDbTransaction>(() => new TransactionId(Guid.NewGuid()));
            _parameterStore   = new Store <ParameterId, IDbDataParameter>(() => new ParameterId(Guid.NewGuid()));
            _readerStore      = new Store <DataReaderId, IDataReader>(() => new DataReaderId(Guid.NewGuid()));

            // Parameters are not disposed of individually (unlike connections, commands, transactions and readers) - instead, the parameters in
            // the parameter store must be removed when the command that created them is disposed. The information to do that is recorded here.
            _parametersToTidy = new ConcurrentParameterToCommandLookup();
        }