public async Task Test_that_read_block_command_is_processed()
        {
            //ARRANGE
            var countdown = new CountdownEvent(2);
            Mock <IBlockReader> blockReader = null;
            var blockEventsHandlerMock      = BlockEventsHandlerCreateMock((intName, evt, headers, messagePublisher) =>
            {
            });

            var(client, apiFactory, testServer) = PrepareClient <AppSettings>(
                serverOptions =>
            {
                CreateMocks(
                    out blockReader,
                    out var blockProvider);

                serverOptions.IntegrationName = _integrationName;
                serverOptions.UseTransferAmountTransactionsModel();
                blockReader
                .Setup(x => x.ReadBlockAsync(2, It.IsAny <IBlockListener>()))
                .Returns(Task.CompletedTask)
                .Callback(() => { countdown.Signal(); });

                blockReader
                .Setup(x => x.ReadBlockAsync(1, It.IsAny <IBlockListener>()))
                .Returns(Task.CompletedTask)
                .Callback(() => { countdown.Signal(); });
                blockProvider.Setup(x => x.GetLastAsync()).ReturnsAsync(new LastIrreversibleBlockUpdatedEvent(1, "1"));
                ConfigureFactories(serverOptions, blockReader, blockProvider);
            },
                clientOptions =>
            {
                clientOptions.BlockEventsHandlerFactory =
                    (context) => blockEventsHandlerMock.Object;
                clientOptions.RabbitVhost        = _rabbitMqSettings.Vhost;
                clientOptions.RabbitMqConnString = _rabbitMqSettings.GetConnectionString();
                clientOptions.AddIntegration(_integrationName);
            });

            //ACT
            using (testServer)
                using (client)
                {
                    client.Initialize();

                    var apiBlocksReader = apiFactory.Create(_integrationName);

                    await apiBlocksReader.SendAsync(new ReadBlockCommand(1), null);

                    await apiBlocksReader.SendAsync(new ReadBlockCommand(2), null);

                    countdown.Wait(Waiting.Timeout);
                }

            //ASSERT

            blockReader.Verify(x => x.ReadBlockAsync(1, It.IsNotNull <IBlockListener>()), Times.AtLeastOnce);
            blockReader.Verify(x => x.ReadBlockAsync(2, It.IsNotNull <IBlockListener>()), Times.AtLeastOnce);
            blockReader.Verify(x => x.ReadBlockAsync(It.IsNotIn(1, 2), It.IsNotNull <IBlockListener>()), Times.Never);
        }
Ejemplo n.º 2
0
        private RabbitMqEndpoint InitializeRabbitMqEndpoint(ServiceProvider serviceProvider)
        {
            var endpoint = new RabbitMqEndpoint(
                serviceProvider,
                serviceProvider.GetRequiredService <ILogFactory>(),
                new Uri(_rabbitMqSettings.GetConnectionString()),
                _rabbitMqSettings.Vhost);

            endpoint.Initialize();
            endpoint.DeclareExchange(ExchangeName);

            return(endpoint);
        }
        public async Task GlobalSetup()
        {
            LaunchSettingsReader.Read();

            _rabbitMqSettings    = RabbitMqSettingsReader.Read();
            _rabbitMqInitializer = new RabbitMqVhostInitializer(_rabbitMqSettings);

            await _rabbitMqInitializer.InitializeAsync();

            _settingsMock = new SettingsMock(_pathToSettings);

            var prepareSettings = new AppSettings
            {
                Db = new DbSettings
                {
                    AzureDataConnString = "empty",
                    LogsConnString      = "empty",
                    MaxTransactionsSavingParallelism = 4
                },
                RabbitMq = new RabbitMqSettings
                {
                    ConnString             = _rabbitMqSettings.GetConnectionString(),
                    MessageConsumersCount  = 1,
                    MessageProcessorsCount = 1,
                    TransactionsBatchSize  = 2
                },
                LastIrreversibleBlockMonitoringPeriod = TimeSpan.FromSeconds(5),
                NodeUrl                 = "http://localhost:7777/api",
                NodeUser                = "******",
                NodePassword            = "******",
                MonitoringServiceClient = new MonitoringServiceClientSettings
                {
                    MonitoringServiceUrl = "http://localhost:5431"
                }
            };

            _settingsMock.PrepareSettings(prepareSettings);
        }