Example #1
0
 public CqrsModule(CqrsSettings settings, ILog log)
 {
     _settings            = settings;
     _log                 = log;
     _defaultRetryDelayMs = (long)_settings.RetryDelay.TotalMilliseconds;
     _contextNames        = _settings.ContextNames;
 }
Example #2
0
 public CqrsModule(CqrsSettings settings, ILog log, MarginTradingSettings marginTradingSettings)
 {
     _settings = settings;
     _marginTradingSettings = marginTradingSettings;
     _log = log;
     _defaultRetryDelayMs = (long)_settings.RetryDelay.TotalMilliseconds;
 }
 // todo: move to test-specific code
 private static IRegistration RegistrerBoundedContext(CqrsSettings sett)
 {
     return(Register.BoundedContext(sett.ContextNames.TradingEngine)
            //todo place specific command here
            .PublishingCommands(typeof(DepositCommand))//BeginClosePositionBalanceUpdateCommand))
            .To(sett.ContextNames.AccountsManagement)
            .With("Default"));
 }
Example #4
0
 // todo: move to test-specific code
 private static IRegistration RegisterBoundedContext(CqrsSettings settings)
 {
     return(Register.BoundedContext(settings.ContextNames.TradingEngine)
            .PublishingEvents(
                typeof(Backend.Contracts.Events.PositionClosedEvent))
            .With(EventsRoute)
            .PublishingCommands(typeof(DepositCommand))
            .To(settings.ContextNames.AccountsManagement)
            .With(DefaultRoute));
 }
 public CqrsModule(
     CqrsSettings settings,
     WorkflowSettings workflowSettings,
     BatchingSettings batchingSettings,
     string rabbitMqVirtualHost = null)
 {
     _settings            = settings;
     _workflowSettings    = workflowSettings;
     _batchingSettings    = batchingSettings;
     _rabbitMqVirtualHost = rabbitMqVirtualHost;
 }
Example #6
0
 public AcceptCashoutCommandsHandler(
     IChaosKitty chaosKitty,
     ICashoutsBatchRepository cashoutsBatchRepository,
     IClosedBatchedCashoutRepository closedBatchedCashoutRepository,
     IActiveCashoutsBatchIdRepository activeCashoutsBatchIdRepository,
     IBlockchainConfigurationsProvider blockchainConfigurationProvider,
     IBlockchainWalletsClient walletsClient,
     CqrsSettings cqrsSettings,
     bool disableDirectCrossClientCashouts)
 {
     _chaosKitty = chaosKitty;
     _cashoutsBatchRepository         = cashoutsBatchRepository;
     _closedBatchedCashoutRepository  = closedBatchedCashoutRepository;
     _activeCashoutsBatchIdRepository = activeCashoutsBatchIdRepository;
     _blockchainConfigurationProvider = blockchainConfigurationProvider ?? throw new ArgumentNullException(nameof(blockchainConfigurationProvider));
     _walletsClient = walletsClient ?? throw new ArgumentNullException(nameof(walletsClient));
     _cqrsSettings  = cqrsSettings;
     _disableDirectCrossClientCashouts = disableDirectCrossClientCashouts;
 }
Example #7
0
 public CqrsModule(IReloadingManager <AppSettings> settingsManager)
 {
     _settings = settingsManager.CurrentValue.BalancesService.Cqrs;
 }
 public CqrsModule(IReloadingManager <ApplicationSettings> settingsManager)
 {
     _settings = settingsManager.CurrentValue.AssetsService.Cqrs;
 }
 public WorkflowModule(
     IReloadingManager <AppSettings> appSettings)
 {
     _cqrsSettings = appSettings.CurrentValue.Cqrs;
     _neoAssetId   = appSettings.CurrentValue.NeoGasDistributor.NeoAssetId;
 }
Example #10
0
 /// <summary>
 /// Parse abstract message.
 /// </summary>
 /// <param name="json">input json.</param>
 /// <param name="type">Type.</param>
 /// <returns>object.</returns>
 public static object FromJson(this string json, Type type)
 {
     return(JsonConvert.DeserializeObject(json, type, CqrsSettings.JsonConfig()));
 }
Example #11
0
 /// <summary>
 /// Parse JSON.
 /// </summary>
 /// <param name="json">input json.</param>
 /// <typeparam name="T">Object Type.</typeparam>
 /// <returns>object.</returns>
 public static T FromJson <T>(this string json) => JsonConvert.DeserializeObject <T>(json, CqrsSettings.JsonConfig());
Example #12
0
 /// <summary>
 /// IMessage to JSON.
 /// </summary>
 /// <param name="entity">entity.</param>
 /// <returns>JSON.</returns>
 public static string ToJson(this object entity)
 {
     return(JsonConvert.SerializeObject(entity, CqrsSettings.JsonConfig()));
 }
 public CqrsModule(CqrsSettings settings, string rabbitMqVirtualHost = null)
 {
     _settings            = settings;
     _rabbitMqVirtualHost = rabbitMqVirtualHost;
 }
        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);
        }
Example #15
0
        public RiskControlSagaTests()
        {
            _logFactory          = LogFactory.Create().AddUnbufferedConsole();
            _chaosKittyMock      = new Mock <IChaosKitty>();
            _eventsPublisherMock = new Mock <IEventPublisher>();
            _commandSender       = new Mock <ICommandSender>();
            _cashoutRiskControlRepositoryMock = new Mock <ICashoutRiskControlRepository>();
            _batchRepositoryMock = new Mock <ICashoutsBatchRepository>();
            _closedBatchedCashoutsRepositoryMock = new Mock <IClosedBatchedCashoutRepository>();
            _activeCashoutsBatchIdRepositoryMock = new Mock <IActiveCashoutsBatchIdRepository>();
            _assetsServiceMock = new Mock <IAssetsServiceWithCache>();
            _walletsClientMock = new Mock <IBlockchainWalletsClient>();
            _cqrsSettings      = new CqrsSettings
            {
                RabbitConnectionString = "fake-connection-string",
                RetryDelay             = TimeSpan.FromSeconds(30)
            };
            _blockchainConfigurationProvider = new BlockchainConfigurationsProvider
                                               (
                _logFactory,
                new Dictionary <string, BlockchainConfiguration>
            {
                { "Bitcoin", new BlockchainConfiguration("HotWallet", false, null) }
            }
                                               );

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

            _aggregate = null;

            _cashoutRiskControlRepositoryMock
            .Setup(x => x.GetOrAddAsync(
                       It.IsAny <Guid>(),
                       It.IsAny <Func <CashoutRiskControlAggregate> >()))
            .ReturnsAsync((Guid opId, Func <CashoutRiskControlAggregate> factory) => _aggregate ?? (_aggregate = factory()));

            _cashoutRiskControlRepositoryMock
            .Setup(x => x.SaveAsync(It.IsAny <CashoutRiskControlAggregate>()))
            .Callback((CashoutRiskControlAggregate agg) => _aggregate = agg)
            .Returns(Task.CompletedTask);

            _cashoutRiskControlRepositoryMock
            .Setup(x => x.TryGetAsync(It.IsAny <Guid>()))
            .ReturnsAsync((Guid opId) => opId == _aggregate?.OperationId ? _aggregate : null);

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

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

            _startCashoutCommandsHandler = new StartCashoutCommandsHandler(_logFactory, _blockchainConfigurationProvider, _assetsServiceMock.Object, new Mock <IHttpClientFactory>().Object);

            _notifyCashoutFailedCommandsHandler = new NotifyCashoutFailedCommandsHandler();

            _acceptCashoutCommandsHandler = new AcceptCashoutCommandsHandler(
                _chaosKittyMock.Object,
                _batchRepositoryMock.Object,
                _closedBatchedCashoutsRepositoryMock.Object,
                _activeCashoutsBatchIdRepositoryMock.Object,
                _blockchainConfigurationProvider,
                _walletsClientMock.Object,
                _cqrsSettings,
                false);

            _saga = new RiskControlSaga(_chaosKittyMock.Object, _cashoutRiskControlRepositoryMock.Object);

            _eventsPublisherMock.Setup(x => x.PublishEvent(It.IsAny <ValidationStartedEvent>()))
            .Callback((object evt) => _saga.Handle((ValidationStartedEvent)evt, _commandSender.Object));

            _eventsPublisherMock.Setup(x => x.PublishEvent(It.IsAny <OperationAcceptedEvent>()))
            .Callback((object evt) => _saga.Handle((OperationAcceptedEvent)evt, _commandSender.Object));

            _eventsPublisherMock.Setup(x => x.PublishEvent(It.IsAny <OperationRejectedEvent>()))
            .Callback((object evt) => _saga.Handle((OperationRejectedEvent)evt, _commandSender.Object));

            _commandSender
            .Setup(x => x.SendCommand(
                       It.IsAny <AcceptCashoutCommand>(),
                       It.Is <string>(v => v == BlockchainCashoutProcessorBoundedContext.Name),
                       It.IsAny <uint>()))
            .Callback((AcceptCashoutCommand cmd, string bc, uint _) => _acceptCashoutCommandsHandler.Handle(cmd, _eventsPublisherMock.Object));

            _commandSender
            .Setup(x => x.SendCommand(
                       It.IsAny <NotifyCashoutFailedCommand>(),
                       It.Is <string>(v => v == BlockchainCashoutProcessorBoundedContext.Name),
                       It.IsAny <uint>()))
            .Callback((NotifyCashoutFailedCommand cmd, string bc, uint _) => _notifyCashoutFailedCommandsHandler.Handle(cmd, _eventsPublisherMock.Object));
        }
Example #16
0
 public CqrsTestModule(CqrsSettings settings, string host)
 {
     _settings = settings;
     _host     = host;
 }
 public CqrsModule(IReloadingManager <AppSettings> settingsManager)
 {
     _settings = settingsManager.CurrentValue.PostProcessingService.Cqrs;
 }
 public CqrsModule(IReloadingManager <AppSettings> settings)
 {
     _settings    = settings.CurrentValue.BlockchainRiskControlJob.Cqrs;
     _appSettings = settings;
 }
Example #19
0
 public CqrsModule(CqrsSettings settings)
 {
     _settings = settings;
 }