private static Mock <IBlockEventsHandler> BlockEventsHandlerCreateMock(Action <string, object, MessageHeaders, IMessagePublisher> callBack)
        {
            Mock <IBlockEventsHandler> blockEventsHandler = new Mock <IBlockEventsHandler>();

            blockEventsHandler.Setup(x => x.HandleAsync(It.IsAny <string>(), It.IsAny <BlockHeaderReadEvent>(), It.IsAny <MessageHeaders>(), It.IsAny <IMessagePublisher>()))
            .ReturnsAsync(MessageHandlingResult.Success())
            .Callback(callBack)
            .Verifiable();
            blockEventsHandler.Setup(x => x.HandleAsync(It.IsAny <string>(), It.IsAny <BlockNotFoundEvent>(), It.IsAny <MessageHeaders>(), It.IsAny <IMessagePublisher>()))
            .ReturnsAsync(MessageHandlingResult.Success())
            .Callback(callBack)
            .Verifiable();
            blockEventsHandler.Setup(x => x.HandleAsync(It.IsAny <string>(), It.IsAny <TransferAmountTransactionsBatchEvent>(), It.IsAny <MessageHeaders>(), It.IsAny <IMessagePublisher>()))
            .ReturnsAsync(MessageHandlingResult.Success())
            .Callback(callBack)
            .Verifiable();
            blockEventsHandler.Setup(x => x.HandleAsync(It.IsAny <string>(), It.IsAny <TransferCoinsTransactionsBatchEvent>(), It.IsAny <MessageHeaders>(), It.IsAny <IMessagePublisher>()))
            .ReturnsAsync(MessageHandlingResult.Success())
            .Callback(callBack)
            .Verifiable();
            blockEventsHandler.Setup(x => x.HandleAsync(It.IsAny <string>(), It.IsAny <LastIrreversibleBlockUpdatedEvent>(), It.IsAny <MessageHeaders>(), It.IsAny <IMessagePublisher>()))
            .ReturnsAsync(MessageHandlingResult.Success())
            .Callback(callBack)
            .Verifiable();

            return(blockEventsHandler);
        }
Ejemplo n.º 2
0
        public async Task Test_that_handler_with_state_invoked_without_filters()
        {
            // Arrange

            var          messageId     = Guid.NewGuid();
            const string state         = "state";
            const string correlationId = "correlationId";
            const string exchange      = "exchange";
            const string routingKey    = "routingKey";
            const int    retryCount    = 123;

            var options = new MessageSubscriptionOptions <TestMessage, string>(routingKey);

            options.WithHandler <TestMessageHandlerWithState>();
            options.WithState(state);

            var subscription = new MessageSubscription <TestMessage, string>(options, Array.Empty <IMessageFilter>());

            _testHandlerWithStateImplMock
            .Setup(x => x.HandleAsync
                   (
                       It.IsAny <string>(),
                       It.IsAny <TestMessage>(),
                       It.IsAny <MessageHeaders>(),
                       It.IsAny <IMessagePublisher>()
                   ))
            .Returns <string, TestMessage, MessageHeaders, IMessagePublisher>((s, m, h, p) => Task.FromResult(MessageHandlingResult.Success()));

            // Action

            var result = await subscription.InvokeHandlerAsync
                         (
                _serviceProvider,
                new TestMessage
            {
                Id = messageId
            },
                new MessageHeaders(correlationId),
                new MessageHandlingContext(exchange, retryCount, routingKey),
                _messagePublisherMock.Object
                         );

            // Assert

            Assert.AreEqual(MessageHandlingResult.Success(), result);

            _testHandlerWithStateImplMock.Verify
            (
                x => x.HandleAsync
                (
                    It.Is <string>(s => s == state),
                    It.Is <TestMessage>(m => m.Id == messageId),
                    It.IsNotNull <MessageHeaders>(),
                    It.IsNotNull <IMessagePublisher>()
                ),
                times: Times.Once
            );
        }
        public async Task <MessageHandlingResult> HandleAsync(ReadBlockCommand command, MessageHeaders headers, IMessagePublisher replyPublisher)
        {
            var blockListener = new BlockListener
                                (
                replyPublisher,
                _rawObjectRepository,
                _transactionsBatchSize,
                _maxTransactionsSavingParallelism,
                _transferModel
                                );

            using (blockListener)
            {
                await _blockReader.ReadBlockAsync(command.BlockNumber, blockListener);

                await blockListener.FlushAsync();
            }

            return(MessageHandlingResult.Success());
        }
Ejemplo n.º 4
0
        public async Task Test_that_handler_invoked_with_two_filter()
        {
            // Arrange

            var          messageId     = Guid.NewGuid();
            const string correlationId = "correlationId";
            const string exchange      = "exchange";
            const string routingKey    = "routingKey";
            const int    retryCount    = 123;

            var options = new MessageSubscriptionOptions <TestMessage>(routingKey);

            options.WithHandler <TestMessageHandler>();

            var filterMock = new Mock <IMessageFilter>();

            filterMock
            .Setup(x => x.HandleMessageAsync(It.IsNotNull <MessageFilteringContext>()))
            .Returns <MessageFilteringContext>(context => context.InvokeNextAsync());

            var globalFilters = new List <IMessageFilter>
            {
                filterMock.Object,
                filterMock.Object
            };

            var subscription = new MessageSubscription <TestMessage>(options, globalFilters);

            _testHandlerImplMock
            .Setup(x => x.HandleAsync
                   (
                       It.IsAny <TestMessage>(),
                       It.IsAny <MessageHeaders>(),
                       It.IsAny <IMessagePublisher>()
                   ))
            .Returns <TestMessage, MessageHeaders, IMessagePublisher>((m, h, p) => Task.FromResult(MessageHandlingResult.Success()));

            // Action

            var result = await subscription.InvokeHandlerAsync
                         (
                _serviceProvider,
                new TestMessage
            {
                Id = messageId
            },
                new MessageHeaders(correlationId),
                new MessageHandlingContext(exchange, retryCount, routingKey),
                _messagePublisherMock.Object
                         );

            // Assert

            Assert.AreEqual(MessageHandlingResult.Success(), result);

            _testHandlerImplMock.Verify
            (
                x => x.HandleAsync
                (
                    It.Is <TestMessage>(m => m.Id == messageId),
                    It.IsNotNull <MessageHeaders>(),
                    It.IsNotNull <IMessagePublisher>()
                ),
                times: Times.Once
            );
            filterMock.Verify(x => x.HandleMessageAsync(It.IsNotNull <MessageFilteringContext>()), Times.Exactly(2));
        }
Ejemplo n.º 5
0
 public Task <MessageHandlingResult> HandleAsync(string integrationName, LastIrreversibleBlockUpdatedEvent evt, MessageHeaders headers, IMessagePublisher replyPublisher)
 {
     return(Task.FromResult(MessageHandlingResult.Success()));
 }
Ejemplo n.º 6
0
 public Task <MessageHandlingResult> HandleAsync(string state, TransferCoinsTransactionsBatchEvent message, MessageHeaders headers,
                                                 IMessagePublisher replyPublisher)
 {
     return(Task.FromResult(MessageHandlingResult.Success()));
 }
Ejemplo n.º 7
0
 public Task <MessageHandlingResult> HandleAsync(string integrationName, BlockNotFoundEvent evt, MessageHeaders headers, IMessagePublisher replyPublisher)
 {
     return(Task.FromResult(MessageHandlingResult.Success()));
 }
Ejemplo n.º 8
0
        public void SetUp()
        {
            _testHandlerImplMock          = new Mock <ITestMessageHandlerImplementation>();
            _testHandlerWithStateImplMock = new Mock <ITestMessageHandlerWithStateImplementation>();

            _testHandlerImplMock
            .Setup(x => x.HandleAsync
                   (
                       It.IsAny <TestMessage>(),
                       It.IsAny <MessageHeaders>(),
                       It.IsAny <IMessagePublisher>()
                   ))
            .Returns <TestMessage, MessageHeaders, IMessagePublisher>((m, h, p) => Task.FromResult(MessageHandlingResult.Success()));

            _testHandlerWithStateImplMock
            .Setup(x => x.HandleAsync
                   (
                       It.IsAny <string>(),
                       It.IsAny <TestMessage>(),
                       It.IsAny <MessageHeaders>(),
                       It.IsAny <IMessagePublisher>()
                   ))
            .Returns <string, TestMessage, MessageHeaders, IMessagePublisher>((s, m, h, p) => Task.FromResult(MessageHandlingResult.Success()));

            var services = new ServiceCollection();

            services.AddSingleton(LogFactory.Create().AddUnbufferedConsole());
            services.AddTransient <TestMessageHandler>();
            services.AddTransient <TestMessageHandlerWithState>();
            services.AddTransient(c => _testHandlerImplMock.Object);
            services.AddTransient(c => _testHandlerWithStateImplMock.Object);

            _serviceProvider = services.BuildServiceProvider();
        }