public void CanLinkTo() { const string consumerTag = "_consumertag_"; var connectionFactory = A.Fake <IAmqpConnectionFactory>(); var propertyBuilder = A.Fake <IAmqpPropertyBuilder>(); var messageBuilder = A.Fake <IAmqpMessageBuilder>(); var targetBlock = A.Fake <ITargetBlock <IMessage> >(); var connection = A.Fake <IConnection>(); var channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => channel.BasicConsume( A <string> .Ignored, A <bool> .Ignored, A <string> .Ignored, A <bool> .Ignored, A <bool> .Ignored, A <IDictionary <string, object> > .Ignored, A <IBasicConsumer> .Ignored)).Returns(consumerTag); var sut = new AsyncAmqpBasicConsumer <object>( connectionFactory, propertyBuilder, messageBuilder, false, "test"); IPublishingTag tag = sut.LinkTo(targetBlock); tag.Id.Should().Be(consumerTag, because: "Id is equal consumer tag."); }
public void CanBuildWithoutPublishers() { var registry = A.Fake <IPublisherRegistry>(); var sut = new AmqpPublishingBuilder(); IPublishingTag publishingTag = sut.Build(registry); A.CallTo(() => registry.RegisterPublisher <int>(A <IPublisher> .Ignored)).MustNotHaveHappened(); }
public void CanRegisterPublisher() { IPublisher publisher = A.Fake <IPublisher>(); var sut = new Bus(); IPublishingTag tag = sut.RegisterPublisher <int>(publisher); tag.Should().NotBeNull(); A.CallTo(() => publisher.LinkTo(A <ITargetBlock <IMessage> > .Ignored)).MustHaveHappenedOnceExactly(); }
public void CanBuildWithPublishers() { var registry = A.Fake <IPublisherRegistry>(); var sut = new AmqpPublishingBuilder(); sut.ReactOn <string>("test1"); sut.ReactOn <string>("test2"); IPublishingTag publishingTag = sut.Build(registry); A.CallTo(() => registry.RegisterPublisher <string>(A <IPublisher> .Ignored)).MustHaveHappenedTwiceExactly(); }
public void CanCheckIsRegistered() { IPublishingTag publishingTag = A.Fake <IPublishingTag>(); IPublisher publisher = A.Fake <IPublisher>(); A.CallTo(() => publisher.LinkTo(A <ITargetBlock <IMessage> > .Ignored)).Returns(publishingTag); var sut = new Bus(); IPublishingTag tag = sut.RegisterPublisher <int>(publisher); sut.IsRegistered(tag).Should().BeTrue(); }
public IPublishingTag RegisterPublisher <T>(IPublisher publisher) { var dispatcher = this.dispatchers.GetOrAdd(typeof(T), new MessageDispatcher()); var inboxQueue = this.CreateInboxWithDispatcher <T>(dispatcher); IPublishingTag tag = publisher.LinkTo(inboxQueue); tag = this.publishers.AddOrUpdate(tag.Id, tag, (id, t) => t); return(tag); }
public void Unregister(IPublishingTag tag) { this.logService.Info("Unregistering a publisher."); tag.Dispose(); this.publishers.TryRemove(tag.Id, out var publisher); }
public bool IsRegistered(IPublishingTag tag) { return(publishers.ContainsKey(tag.Id)); }
public void Unregister(IPublishingTag tag) { tag.Dispose(); this.publishers.TryRemove(tag.Id, out var publisher); }