Пример #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);
        }
Пример #2
0
        public async Task ChargeManually_ShouldUpdateBalance(decimal delta)
        {
            // arrange
            await AccountHelpers.EnsureAccountState();

            // act
            await AccountHelpers.ChargeManually(delta);

            // assert
            (await AccountHelpers.GetAccount()).Balance.Should().Be(0 + delta);
        }
Пример #3
0
        public async Task EnsureAccountState_ShouldFixAccount()
        {
            // arrange

            // act
            var result = await AccountHelpers.EnsureAccountState(neededBalance : 13);

            // assert
            var account = await AccountHelpers.GetAccount();

            account.Should().BeEquivalentTo(new
            {
                ClientId   = AccountHelpers.ClientId,
                Id         = AccountHelpers.AccountId,
                Balance    = 13,
                IsDisabled = false,
            }, o => o.ExcludingMissingMembers());

            result.Should().BeEquivalentTo(account, o => o.Excluding(x => x.ModificationTimestamp));
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }