Exemplo n.º 1
0
        public async Task IfNotEnoughBalance_ShouldFailWithdraw()
        {
            // arrange
            await AccountHelpers.EnsureAccountState(neededBalance : 123);

            (await AccountHelpers.GetAccount()).Balance.Should().Be(123);

            // act
            var operationId = await ClientUtil.AccountsApi.BeginWithdraw(AccountHelpers.AccountId,
                                                                         new AccountChargeRequest
            {
                OperationId = Guid.NewGuid().ToString(),
                AmountDelta = 124,
                Reason      = "integration tests: withdraw",
            });

            var eventTask = await Task.WhenAny(
                RabbitUtil.WaitForMessage <WithdrawalSucceededEvent>(m => m.OperationId == operationId),
                RabbitUtil.WaitForMessage <WithdrawalFailedEvent>(m => m.OperationId == operationId));

            eventTask.GetType().GetGenericArguments().First().Should().Be <WithdrawalFailedEvent>();
            //eventTask.Should().BeOfType<Task<WithdrawalFailedEvent>>();

            // assert
            (await AccountHelpers.GetAccount()).Balance.Should().Be(123);
        }
        public static async Task ChargeManually(decimal delta)
        {
            var operationId = await ClientUtil.AccountsApi.BeginChargeManually(AccountId,
                                                                               new AccountChargeManuallyRequest
            {
                OperationId   = Guid.NewGuid().ToString(),
                AmountDelta   = delta,
                Reason        = "integration tests",
                ReasonType    = AccountBalanceChangeReasonTypeContract.Manual,
                EventSourceId = Guid.NewGuid().ToString(),
            });

            await RabbitUtil.WaitForMessage <AccountChangedEvent>(m => m.BalanceChange.Id == operationId);
        }
Exemplo n.º 3
0
        public async Task IfEnoughBalance_ShouldWithdraw()
        {
            // arrange
            await AccountHelpers.EnsureAccountState(neededBalance : 123M);

            // act
            var operationId = await ClientUtil.AccountsApi.BeginWithdraw(AccountHelpers.AccountId,
                                                                         new AccountChargeRequest
            {
                OperationId = Guid.NewGuid().ToString(),
                AmountDelta = 123M,
                Reason      = "integration tests: withdraw",
            });

            await Task.WhenAll(
                RabbitUtil.WaitForMessage <AccountChangedEvent>(m => m.BalanceChange.Id == operationId),
                RabbitUtil.WaitForMessage <WithdrawalSucceededEvent>(m => m.OperationId == operationId));

            // assert
            (await AccountHelpers.GetAccount()).Balance.Should().Be(0);
        }
Exemplo n.º 4
0
        public async Task PositionClose_ShouldUpdateBalance(decimal delta)
        {
            // arrange
            await AccountHelpers.EnsureAccountState();

            var operationId = Guid.NewGuid().ToString();

            // act
            //todo use specific command
            CqrsUtil.SendEventToAccountManagement(new Backend.Contracts.Events.PositionClosedEvent(
                                                      accountId: AccountHelpers.AccountId,
                                                      clientId: AccountHelpers.ClientId,
                                                      positionId: operationId,
                                                      assetPairId: "testAssetPair",
                                                      balanceDelta: delta));

            await RabbitUtil.WaitForMessage <AccountChangedEvent>(m =>
                                                                  m.BalanceChange.Id == operationId + "-update-balance");

            // assert
            (await AccountHelpers.GetAccount()).Balance.Should().Be(0 + delta);
        }
Exemplo n.º 5
0
        public async Task Deposit_Success()
        {
            // arrange
            await AccountHelpers.EnsureAccountState();

            // act
            var operationId = await ClientUtil.AccountsApi.BeginDeposit(AccountHelpers.AccountId,
                                                                        new AccountChargeRequest
            {
                OperationId = Guid.NewGuid().ToString(),
                AmountDelta = 123,
                Reason      = "integration tests: deposit",
            });

            var messagesReceivedTask = Task.WhenAll(
                RabbitUtil.WaitForMessage <AccountChangedEvent>(m => m.BalanceChange.Id == operationId),
                RabbitUtil.WaitForMessage <DepositSucceededEvent>(m => m.OperationId == operationId));

            await messagesReceivedTask;

            // assert
            (await AccountHelpers.GetAccount()).Balance.Should().Be(123);
        }