Example #1
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);

            _busSendObserver        = BusSendEndpoint.ConnectSendObserver(_sent);
            _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent);

            _busConsumeObserver = _bus.ConnectConsumeObserver(_consumed);

            _busPublishObserver = _bus.ConnectPublishObserver(_published);
        }
Example #2
0
        public async Task Should_not_complete_the_handler()
        {
            await _notSupported;

            await BusSendEndpoint.Send(new PongMessage((await _ping).Message.CorrelationId));

            Assert.That(async() => await _response, Throws.TypeOf <TaskCanceledException>());
        }
Example #3
0
        public async Task Should_receive_the_interface_proxy()
        {
            Task <ConsumeContext <IMessageA> > handler = SubscribeHandler <IMessageA>();

            await BusSendEndpoint.Send <IMessageA>(new {});

            await handler;
        }
Example #4
0
        public async Task Should_receive_the_proper_message_type()
        {
            Task <ConsumeContext <MessageA> > handler = SubscribeHandler <MessageA>();

            object message = new MessageA();
            await BusSendEndpoint.Send(message, typeof(MessageA));

            await handler;
        }
Example #5
0
        public async Task Should_receive_the_proper_message_as_a_with_request_id()
        {
            Task <ConsumeContext <MessageA> > handler = SubscribeHandler <MessageA>(x => x.RequestId.HasValue);

            var message = new MessageA();
            await BusSendEndpoint.Send(message, Pipe.New <SendContext>(x => x.UseExecute(c => c.RequestId = NewId.NextGuid())));

            await handler;
        }
Example #6
0
        public async Task Should_receive_the_proper_message_as_a()
        {
            Task <ConsumeContext <MessageA> > handler = SubscribeHandler <MessageA>();

            var message = new MessageA();
            await BusSendEndpoint.Send(message);

            await handler;
        }
Example #7
0
        public async Task Should_receive_the_interface_of_the_message()
        {
            Task <ConsumeContext <IMessageA> > handler = SubscribeHandler <IMessageA>();

            var message = new MessageA();
            await BusSendEndpoint.Send(message);

            await handler;
        }
Example #8
0
        public void A_reactive_query_is_observing_a_bus_message()
        {
            _observable = Bus.AsObservable <PingMessage>();

            _thatJustHappened = GetTask <PingMessage>();
            _subscription     = _observable.Subscribe(m => _thatJustHappened.TrySetResult(m));

            BusSendEndpoint.Send(new PingMessage());
        }
        public async Task Should_deliver_the_message_to_an_interested_consumer()
        {
            Task <ConsumeContext <FirstMessageContract> > first = SubscribeHandler <FirstMessageContract>();

            var message = new SomeMessageContract("Joe", 27);

            await BusSendEndpoint.Send(message);

            await first;
        }
Example #10
0
        public async Task Should_not_complete_the_handler()
        {
            var(_, notSupported) = await _request;

            Response <PingNotSupported> message = await notSupported;

            await BusSendEndpoint.Send(new PongMessage((await _ping).Message.CorrelationId));

            var(completed, _) = await _request;

            Assert.That(async() => await completed, Throws.TypeOf <TaskCanceledException>());
        }
Example #11
0
            public async Task Should_be_received()
            {
                Task <ConsumeContext <A> > receivedA = SubscribeHandler <A>();

                var message = new A {
                    Id = Guid.NewGuid()
                };
                await BusSendEndpoint.Send(message);

                ConsumeContext <A> received = await receivedA;

                Assert.AreEqual(message.Id, received.Message.Id);
            }
Example #12
0
        public async Task Should_receive_the_proper_message_without_type()
        {
            Task <ConsumeContext <MessageA> > handler = SubscribeHandler <MessageA>();

            var requestId = NewId.NextGuid();

            object message = new MessageA();
            await BusSendEndpoint.Send(message, context => context.RequestId = requestId);

            ConsumeContext <MessageA> consumeContext = await handler;

            consumeContext.RequestId.ShouldBe(requestId);
        }
Example #13
0
        public async Task Should_receive_the_proper_message_as_a_with_request_id()
        {
            Task <ConsumeContext <MessageA> > handler = SubscribeHandler <MessageA>(x => x.RequestId.HasValue);

            var requestId = NewId.NextGuid();

            var message = new MessageA();
            await BusSendEndpoint.Send(message, c => c.RequestId = requestId);

            ConsumeContext <MessageA> consumeContext = await handler;

            consumeContext.RequestId.ShouldBe(requestId);
        }
Example #14
0
        public async Task An_exception_should_be_thrown()
        {
            var message = new InitiateSimpleSaga(_sagaId);

            await BusSendEndpoint.Send(message);


            try
            {
                await BusSendEndpoint.Send(message);
            }
            catch (SagaException sex)
            {
                Assert.AreEqual(sex.MessageType, typeof(InitiateSimpleSaga));
            }
        }