コード例 #1
0
        public async Task GivenMessage_ShouldNotCreateConnectionTwice()
        {
            var          basicPropertiesMock = new Mock <IBasicProperties>();
            var          batchMock           = new Mock <IBasicPublishBatch>();
            var          routingMock         = new Mock <IRouting>();
            var          messageMock         = new Mock <IPublisherMessage>();
            var          publisherMock       = new Mock <IPublisher>();
            var          bytes         = Array.Empty <byte>();
            const string exchange      = "exchange";
            const string routingKey    = "exchange";
            const string correlationId = "correlationId";
            var          headersMock   = new Mock <IDictionary <string, object> >();

            _channelMock.Setup(x => x.CreateBasicPublishBatch())
            .Returns(batchMock.Object)
            .Verifiable();
            _channelMock.Setup(x => x.CreateBasicProperties())
            .Returns(basicPropertiesMock.Object)
            .Verifiable();
            _channelMock.Setup(x => x.ConfirmSelect())
            .Verifiable();
            _channelMock.Setup(x => x.WaitForConfirms(It.IsAny <TimeSpan>()))
            .Returns(true)
            .Verifiable();

            routingMock.SetupGet(x => x.ExchangeName).Returns(exchange).Verifiable();
            routingMock.SetupGet(x => x.RoutingKey).Returns(routingKey).Verifiable();
            messageMock.SetupGet(x => x.Routing)
            .Returns(routingMock.Object)
            .Verifiable();
            messageMock.Setup(x => x.CancellationToken)
            .Returns(CancellationToken.None)
            .Verifiable();
            messageMock.Setup(x => x.Serialize())
            .Returns(bytes)
            .Verifiable();
            messageMock.Setup(x => x.GetHeaders())
            .Returns(headersMock.Object)
            .Verifiable();
            messageMock.SetupGet(x => x.CorrelationId)
            .Returns(correlationId)
            .Verifiable();


            batchMock.Setup(x =>
#pragma warning disable 618
                            // New Add method is an extension and can not be overriden
                            x.Add(
#pragma warning restore 618
                                exchange,
                                routingKey,
                                false,
                                basicPropertiesMock.Object,
                                bytes))
            .Verifiable();
            batchMock.Setup(x => x.Publish())
            .Verifiable();

            var batching = new PublisherMessageBatching(publisherMock.Object, messageMock.Object);

            await _publisher.PublishAsync(batching, CancellationToken.None);

            await _publisher.PublishAsync(batching, CancellationToken.None);

            _channelMock.VerifyAll();
            messageMock.VerifyAll();
            batchMock.VerifyAll();
            _connectionMock.Verify(x => x.CreateModel(), Times.Exactly(2));
        }
コード例 #2
0
 public async Task ExecuteAsync(IPublisherMessageBatching batching,
                                Func <IPublisherMessageBatching, CancellationToken, Task> _, CancellationToken cancellationToken)
 {
     await _publisher.PublishAsync(batching, cancellationToken);
 }