Send() public method

public Send ( IEnumerable messages ) : System.Threading.Tasks.Task
messages IEnumerable
return System.Threading.Tasks.Task
Example #1
0
        public void WhenMultipleSubscribers_EachGetOwnMessage()
        {
            // arrange
            var client = CreateOutboundTransportMock();

            // create two subscriptions for "mytopic"
            this.subscriptionStore.AddSubscription(new Subscription("mytopic", "e1", "c1"));
            this.subscriptionStore.AddSubscription(new Subscription("mytopic", "e2", "c2"));

            var bus = new MessageBus(this.subscriptionManager, client.Object, NullLoggerFactory.Instance);
            var message = new Message(new object(), "mytopic");

            // act
            bus.Send(message);

            // assert
            // since multiple messages are to be sent, it should use the SendMultiple method
            client.Verify(b => b.Send(It.IsAny<TransportMessage>()), Times.Never);
            client.Verify(b =>
                b.SendMultiple(It.Is<IEnumerable<TransportMessage>>(msgs =>
                    msgs.Count() == 2 &&
                    msgs.Count(m => m.Headers[MessageHeaders.Endpoint] == "e1" &&
                                    m.Headers[MessageHeaders.Component] == "c1") == 1 &&
                    msgs.Count(m => m.Headers[MessageHeaders.Endpoint] == "e2" &&
                                    m.Headers[MessageHeaders.Component] == "c2") == 1)
                    ), Times.Once);
        }
Example #2
0
        public void WhenNoSubscribers_MessageIsNotSent()
        {
            // arrange
            var client = CreateOutboundTransportMock();
            var bus = new MessageBus(this.subscriptionManager, client.Object, NullLoggerFactory.Instance);
            var message = new Message(new object(), "topic");

            // act
            bus.Send(message);

            // assert
            client.Verify(b => b.Send(It.IsAny<TransportMessage>()), Times.Never);
        }