public async Task Handle(ActiveBatchIdRevokedEvent evt, ICommandSender sender) { var batch = await _cashoutsBatchRepository.GetAsync(evt.BatchId); var outputs = batch.Cashouts .GroupBy(x => x.ToAddress) .Select(x => { return(new BlockchainOperationsExecutor.Contract.OperationOutput { Address = x.Key, Amount = x.Sum(y => y.Amount) }); }).ToArray(); sender.SendCommand ( new BlockchainOperationsExecutor.Contract.Commands.StartOneToManyOutputsExecutionCommand { OperationId = batch.BatchId, AssetId = batch.AssetId, FromAddress = batch.HotWalletAddress, // For the cashout all amount should be transfered to the destination address, // so the fee shouldn't be included in the amount. IncludeFee = false, Outputs = outputs }, BlockchainOperationsExecutor.Contract.BlockchainOperationsExecutorBoundedContext.Name ); _chaosKitty.Meow(evt.BatchId); }
public async Task Batch_ActiveBatchIdRevokedEvent_Outputs_Aggregated() { Mock <IChaosKitty> chaosKittyMock = new Mock <IChaosKitty>(); Mock <ICashoutsBatchReadOnlyRepository> cashoutsBatchReadOnlyRepository = new Mock <ICashoutsBatchReadOnlyRepository>(); Mock <ICommandSender> commandSender = new Mock <ICommandSender>(); Guid batchId = Guid.NewGuid(); var cashoutAggregate = CashoutsBatchAggregate.Start( batchId, "Icon", "ICX", "ICX", "hx...", 21, TimeSpan.FromDays(1)); cashoutAggregate.AddCashout(new BatchedCashoutValueType(Guid.NewGuid(), Guid.NewGuid(), "hx1...", 1, 1, DateTime.UtcNow)); cashoutAggregate.AddCashout(new BatchedCashoutValueType(Guid.NewGuid(), Guid.NewGuid(), "hx1...", 2, 1, DateTime.UtcNow)); cashoutAggregate.AddCashout(new BatchedCashoutValueType(Guid.NewGuid(), Guid.NewGuid(), "hx2...", 2, 1, DateTime.UtcNow)); cashoutsBatchReadOnlyRepository.Setup(x => x.GetAsync(batchId)).ReturnsAsync(cashoutAggregate); var batchSaga = new BatchSaga(chaosKittyMock.Object, cashoutsBatchReadOnlyRepository.Object); ActiveBatchIdRevokedEvent @event = new ActiveBatchIdRevokedEvent() { BatchId = batchId }; await batchSaga.Handle(@event, commandSender.Object); commandSender.Verify(x => x.SendCommand <StartOneToManyOutputsExecutionCommand>( It.Is <StartOneToManyOutputsExecutionCommand>(y => CheckStartOneToManyOutputsExecutionCommand(y)), It.IsAny <string>(), It.IsAny <uint>())); }