Example #1
0
        public void StartReceivingUpdatesFromDb()
        {
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }

                IDataParameter parameter = _dbProviderFactory.CreateParameter();
                parameter.ParameterName = "iPayloadId";
                parameter.Value         = _lastPayloadId;
                parameter.DbType        = DbType.Decimal;
                parameter.Direction     = ParameterDirection.Input;

                OracleParameter resultSetParameter = _dbProviderFactory.CreateParameter() as OracleParameter;
                if (resultSetParameter != null)
                {
                    resultSetParameter.ParameterName = "oRefCur";
                    resultSetParameter.OracleDbType  = OracleDbType.RefCursor;
                    resultSetParameter.Direction     = ParameterDirection.Output;
                }

                _observableDbOperation = _observableDbOperationFactory.ObservableDbOperation(_connectionString,
                                                                                             _selectSql, _useOracleDependency, _traceSource, _dbProviderFactory, parameter, resultSetParameter);
            }

            _observableDbOperation.Queried += () =>
            {
                if (Queried != null)
                {
                    Queried();
                }
            };

            _observableDbOperation.Faulted += ex =>
            {
                if (Faulted != null)
                {
                    Faulted(ex);
                }
            };

            _observableDbOperation.Changed += () =>
            {
                _traceSource.TraceInformation("Starting receive loop again to process updates");
                _observableDbOperation.ExecuteReaderWithUpdates(ProcessRecord);
            };

            _traceSource.TraceVerbose("Executing receive reader, initial payload ID parameter={0}",
                                      _observableDbOperation.Parameters[0].Value);
            _observableDbOperation.ExecuteReaderWithUpdates(ProcessRecord);
            _traceSource.TraceInformation("OracleReceiver.GetLastPayloadId returned");
        }
Example #2
0
        public void Receiver_Dispose_Success()
        {
            IObservableDbOperationFactory FakeiDbOperationFactory = A.Fake <IObservableDbOperationFactory>();
            var fakeIdbProviderFactoryOperation = A.Fake <IDbProviderFactory>();

            var fakeIDataParameter = A.Fake <IDataParameter>();

            A.CallTo(() => fakeIDataParameter.Value).Returns((long)2);
            var                    fakeCallsTo    = A.CallTo(() => fakeIdbProviderFactoryOperation.CreateParameter()).Returns(fakeIDataParameter);
            IOracleReceiver        oracleReceiver = new OracleReceiver(string.Empty, true, new TraceSource("ss"), fakeIdbProviderFactoryOperation, A.Fake <IDbOperationFactory>(), FakeiDbOperationFactory);
            IObservableDbOperation fakDbOperation = A.Fake <IObservableDbOperation>();
            var                    fake           =
                A.CallTo(() => FakeiDbOperationFactory.ObservableDbOperation(string.Empty, string.Empty, true, new TraceSource("ss"),
                                                                             A.Fake <IDbProviderFactory>())).WithAnyArguments().Returns(fakDbOperation);

            var fakeIObservableDbOperationDispose = A.CallTo(() => fakDbOperation.Dispose());

            oracleReceiver.GetLastPayloadId();
            oracleReceiver.StartReceivingUpdatesFromDb();
            Thread.Sleep(100);
            oracleReceiver.Dispose();

            fakeIObservableDbOperationDispose.MustHaveHappened((Repeated.Exactly.Once));
        }