Пример #1
0
        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.");
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }
Пример #4
0
        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();
        }
Пример #5
0
        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();
        }
Пример #6
0
        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);
        }
Пример #7
0
 public void Unregister(IPublishingTag tag)
 {
     this.logService.Info("Unregistering a publisher.");
     tag.Dispose();
     this.publishers.TryRemove(tag.Id, out var publisher);
 }
Пример #8
0
 public bool IsRegistered(IPublishingTag tag)
 {
     return(publishers.ContainsKey(tag.Id));
 }
Пример #9
0
 public void Unregister(IPublishingTag tag)
 {
     tag.Dispose();
     this.publishers.TryRemove(tag.Id, out var publisher);
 }