Exemplo n.º 1
0
        public WaitForBatchExpirationCommandsHandlerTests()
        {
            _expirationMonitoringPeriod = TimeSpan.FromMinutes(2);

            _eventsPublisherMock = new Mock <IEventPublisher>();
            _batchRepositoryMock = new Mock <ICashoutsBatchRepository>();

            _handler = new WaitForBatchExpirationCommandsHandler
                       (
                new SilentChaosKitty(),
                _expirationMonitoringPeriod,
                _batchRepositoryMock.Object
                       );

            _batch = CashoutsBatchAggregate.Start
                     (
                CashoutsBatchAggregate.GetNextId(),
                "Bitcoin",
                "LykkeBTC",
                "BTC",
                "HotWallet",
                10,
                TimeSpan.FromMinutes(10)
                     );

            _batchRepositoryMock
            .Setup(x => x.GetAsync(It.Is <Guid>(p => p == _batch.BatchId)))
            .ReturnsAsync(() => _batch);
        }
        public StartCashoutCommandsHandlerTests()
        {
            var logFactory = LogFactory.Create().AddUnbufferedConsole();

            _eventsPublisherMock = new Mock <IEventPublisher>();
            _batchRepositoryMock = new Mock <ICashoutsBatchRepository>();
            _closedBatchedCashoutsRepositoryMock = new Mock <IClosedBatchedCashoutRepository>();

            var activeCashoutsBatchIdRepositoryMock = new Mock <IActiveCashoutsBatchIdRepository>();
            var assetsServiceMock = new Mock <IAssetsServiceWithCache>();
            var walletsClient     = new Mock <IBlockchainWalletsClient>();

            _cqrsSettings = new CqrsSettings
            {
                RabbitConnectionString = "fake-connection-string",
                RetryDelay             = TimeSpan.FromSeconds(30)
            };

            _countTreshold = 10;

            var ageThreshold = TimeSpan.FromMinutes(10);

            var blockchainConfigurationProvider = new BlockchainConfigurationsProvider
                                                  (
                logFactory,
                new Dictionary <string, BlockchainConfiguration>
            {
                {
                    "Bitcoin",
                    new BlockchainConfiguration
                    (
                        "HotWallet",
                        false,
                        new CashoutsAggregationConfiguration
                        (
                            ageThreshold,
                            _countTreshold
                        ))
                }
            }
                                                  );

            _handler = new AcceptCashoutCommandsHandler
                       (
                new SilentChaosKitty(),
                _batchRepositoryMock.Object,
                _closedBatchedCashoutsRepositoryMock.Object,
                activeCashoutsBatchIdRepositoryMock.Object,
                blockchainConfigurationProvider,
                walletsClient.Object,
                _cqrsSettings,
                false
                       );

            var activeCashoutsBatchId = ActiveCashoutBatchId.Create(CashoutsBatchAggregate.GetNextId());

            _batch = CashoutsBatchAggregate.Start
                     (
                activeCashoutsBatchId.BatchId,
                "Bitcoin",
                "LykkeBTC",
                "BTC",
                "HotWallet",
                10,
                TimeSpan.FromMinutes(10)
                     );

            var asset = new Asset
            {
                Id = "LykkeBTC",
                BlockchainIntegrationLayerId      = "Bitcoin",
                BlockchainIntegrationLayerAssetId = "BTC"
            };

            _batchRepositoryMock
            .Setup
            (
                x => x.GetOrAddAsync
                (
                    It.Is <Guid>(p => p == _batch.BatchId),
                    It.IsAny <Func <CashoutsBatchAggregate> >()
                )
            )
            .ReturnsAsync(() => _batch);

            _closedBatchedCashoutsRepositoryMock
            .Setup(x => x.IsCashoutClosedAsync(It.Is <Guid>(p => p == _batch.BatchId)))
            .ReturnsAsync(false);

            activeCashoutsBatchIdRepositoryMock
            .Setup
            (
                x => x.GetActiveOrNextBatchId
                (
                    It.Is <string>(p => p == "Bitcoin"),
                    It.Is <string>(p => p == "BTC"),
                    It.Is <string>(p => p == "HotWallet"),
                    It.Is <Func <Guid> >(p => p == CashoutsBatchAggregate.GetNextId)
                )
            )
            .ReturnsAsync(() => activeCashoutsBatchId);

            assetsServiceMock
            .Setup
            (
                x => x.TryGetAssetAsync
                (
                    It.Is <string>(p => p == "LykkeBTC"),
                    It.IsAny <CancellationToken>()
                )
            )
            .ReturnsAsync(() => asset);

            walletsClient
            .Setup
            (
                x => x.TryGetClientIdAsync
                (
                    It.Is <string>(p => p == "Bitcoin"),
                    It.IsAny <string>()
                )
            )
            .ReturnsAsync((Guid?)null);
        }