Beispiel #1
0
        public virtual async Task Start(CancellationToken cancellationToken = default)
        {
            _received = new BusTestReceiveObserver(TestInactivityTimeout);
            _received.ConnectInactivityObserver(InactivityObserver);

            _consumed = new BusTestConsumeObserver(TestTimeout, InactivityToken);
            _consumed.ConnectInactivityObserver(InactivityObserver);

            _published = new BusTestPublishObserver(TestTimeout, TestInactivityTimeout, InactivityToken);
            _published.ConnectInactivityObserver(InactivityObserver);

            _sent = new BusTestSendObserver(TestTimeout, TestInactivityTimeout, InactivityToken);
            _sent.ConnectInactivityObserver(InactivityObserver);

            PreCreateBus?.Invoke(this);

            BusControl = CreateBus();

            ConnectObservers(BusControl);

            _busHandle = await BusControl.StartAsync(cancellationToken).ConfigureAwait(false);

            BusSendEndpoint = await GetSendEndpoint(BusControl.Address).ConfigureAwait(false);

            InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false);

            InputQueueSendEndpoint.ConnectSendObserver(_sent);

            BusControl.ConnectConsumeObserver(_consumed);
            BusControl.ConnectPublishObserver(_published);
            BusControl.ConnectReceiveObserver(_received);
            BusControl.ConnectSendObserver(_sent);
        }
Beispiel #2
0
        public virtual async Task Start()
        {
            _sent      = new TestSendObserver(TestTimeout);
            _consumed  = new BusTestConsumeObserver(TestTimeout);
            _published = new BusTestPublishObserver(TestTimeout);

            PreCreateBus?.Invoke(this);

            _bus = CreateBus();

            ConnectObservers(_bus);

            _busHandle = await _bus.StartAsync().ConfigureAwait(false);

            BusSendEndpoint = await GetSendEndpoint(_bus.Address).ConfigureAwait(false);

            InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false);

            _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent);

            _busConsumeObserver = _bus.ConnectConsumeObserver(_consumed);

            _busPublishObserver = _bus.ConnectPublishObserver(_published);

            _busSendObserver = _bus.ConnectSendObserver(_sent);
        }
        public void SetupInMemoryTestFixture()
        {
            _bus = CreateBus();

            _busHandle = _bus.Start();
            try
            {
                _busSendEndpoint = Await(() => _bus.GetSendEndpoint(_bus.Address));
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = Await(() => _bus.GetSendEndpoint(_inputQueueAddress));
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        _busHandle?.Stop(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus       = null;
                }

                throw;
            }
        }
        public void SetupAzureServiceBusTestFixture()
        {
            _bus = CreateBus();

            _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver());

            _busHandle = _bus.Start();
            try
            {
                _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result;
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result;
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        _bus.Stop(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus       = null;
                }

                throw;
            }
        }
        public void SetupAzureServiceBusTestFixture()
        {
            _bus = CreateBus();

            _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver());

            _busHandle = _bus.Start();
            try
            {
                Await(() => _busHandle.Ready);

                _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result;
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result;
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception ex)
            {
                Console.WriteLine("The bus creation failed: {0}", ex);

                _busHandle.Stop();

                throw;
            }
        }
Beispiel #6
0
        public async Task SetupHttpTestFixture()
        {
            _bus = CreateBus();

            _busHandle = await _bus.StartAsync(TestCancellationToken);

            try
            {
                _rootEndpoint = Await(() => _bus.GetSendEndpoint(_hostAddress));
                _rootEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        await _busHandle?.StopAsync(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus       = null;
                }

                throw;
            }
        }
        public BusTestScenario(TimeSpan timeout, IBusControl busControl)
        {
            _timeout    = timeout;
            _busControl = busControl;

            Received   = new ReceivedMessageList(timeout);
            _skipped   = new ReceivedMessageList(timeout);
            _published = new PublishedMessageList(timeout);

            _tokenSource      = new CancellationTokenSource(timeout);
            CancellationToken = _tokenSource.Token;

            _subjectSendEndpoint = _busControl.GetSendEndpoint(new Uri("loopback://localhost/input_queue")).Result;

            var testSendObserver = new TestSendObserver(timeout);

            Sent = testSendObserver.Messages;
            _subjectSendEndpoint.ConnectSendObserver(testSendObserver);

            var consumeObserver = new TestConsumeObserver(timeout);

            Received = consumeObserver.Messages;
            busControl.ConnectConsumeObserver(consumeObserver);

            _busHandle = _busControl.Start();
        }
        public BusTestScenario(TimeSpan timeout, IBusControl busControl)
        {
            _timeout = timeout;
            _busControl = busControl;

            Received = new ReceivedMessageList(timeout);
            _skipped = new ReceivedMessageList(timeout);
            _published = new PublishedMessageList(timeout);

            _tokenSource = new CancellationTokenSource(timeout);
            CancellationToken = _tokenSource.Token;

            _subjectSendEndpoint = _busControl.GetSendEndpoint(new Uri("loopback://localhost/input_queue")).Result;

            var testSendObserver = new TestSendObserver(timeout);
            Sent = testSendObserver.Messages;
            _subjectSendEndpoint.ConnectSendObserver(testSendObserver);

            var consumeObserver = new TestConsumeObserver(timeout);
            Received = consumeObserver.Messages;
            busControl.ConnectConsumeObserver(consumeObserver);

            _busHandle = _busControl.Start();
        }
 public ConnectHandle ConnectSendObserver(ISendObserver observer)
 {
     return(_endpoint.ConnectSendObserver(observer));
 }
Beispiel #10
0
 public ConnectHandle ConnectSendObserver(ISendObserver observer)
 => _sendEndpoint.ConnectSendObserver(observer);
        public async Task SetupAzureServiceBusTestFixture()
        {
            _bus = CreateBus();

            _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver());

            _busHandle = await _bus.StartAsync();
            try
            {
                _busSendEndpoint = await _bus.GetSendEndpoint(_bus.Address);
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = await _bus.GetSendEndpoint(_inputQueueAddress);
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        await _bus.StopAsync(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus = null;
                }

                throw;
            }
        }
        public void SetupAzureServiceBusTestFixture()
        {
            _bus = CreateBus();

            _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver());

            _busHandle = _bus.Start();
            try
            {
                Await(() => _busHandle.Ready);

                _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result;
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result;
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception ex)
            {
                Console.WriteLine("The bus creation failed: {0}", ex);

                _busHandle.Stop();

                throw;
            }
        }
        public void SetupInMemoryTestFixture()
        {
            _bus = CreateBus();

            _busHandle = _bus.Start();
            try
            {
                _busSendEndpoint = Await(() => _bus.GetSendEndpoint(_bus.Address));
                _busSendEndpoint.ConnectSendObserver(_sendObserver);

                _inputQueueSendEndpoint = Await(() => _bus.GetSendEndpoint(_inputQueueAddress));
                _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver);
            }
            catch (Exception)
            {
                try
                {
                    using (var tokenSource = new CancellationTokenSource(TestTimeout))
                    {
                        _busHandle?.Stop(tokenSource.Token);
                    }
                }
                finally
                {
                    _busHandle = null;
                    _bus = null;
                }

                throw;
            }
        }
Beispiel #14
0
 public ConnectHandle ConnectSendObserver(ISendObserver observer)
 {
     Used?.Invoke();
     return(_endpoint.ConnectSendObserver(observer));
 }