Ejemplo n.º 1
0
        private void TestClients(object listClients)
        {
            if (!(listClients is List <Client> castedListClients))
            {
                return;
            }
            foreach (var client in castedListClients)
            {
                var startBalance = client.AccountBalance;
                // Enrollment amount knowingly more than withdrawal amount to avoid exceptions
                var enrollmentAmount = Random.Next(1000, 2000);
                var withdrawalAmount = Random.Next(500, 900);
                var expectedBalance  = startBalance + enrollmentAmount - withdrawalAmount;

                lock (Locker)
                {
                    Task.Run(() => FinanceService.EnrollAsync(new ClientOperationDto()
                    {
                        Id = client.Id, TransactionAmount = enrollmentAmount
                    })).Wait();
                    Task.Run(() => FinanceService.WithdrawAsync(new ClientOperationDto()
                    {
                        Id = client.Id, TransactionAmount = withdrawalAmount
                    })).Wait();
                    var currentBalance = Task.Run(() => FinanceService.GetBalanceByIdAsync(client.Id)).Result;

                    if (expectedBalance != currentBalance)
                    {
                        IsErrors = true;
                        break;
                    }
                }
            }
        }