示例#1
0
        public async Task WalletTransferMoreThanMaximumDepositFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password1     = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                string password2 = await walletService.CreateWallet("ime", "prezime", "0605996781028", (short)BankType.BrankoBank, "1234", "123456789876543210");

                string password3 = await walletService.CreateWallet("ime", "prezime", "0605996781027", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password1, 750000M);

                await walletService.Deposit("0605996781027", password3, 750000M);

                await walletService.Transfer("0605996781029", password1, "0605996781028", 300000);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Transfer("0605996781029", password1, "0605996781028", 300000), $"Transaction would exceed wallet (0605996781028) monthly deposit limit ({Configuration["MaximalDeposit"]} RSD).");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#2
0
        public async Task SuccessWalletDepositTest()
        {
            try
            {
                string jmbg = "2904992785075";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password      = await walletService.CreateWallet(jmbg, "TestIme", "TestPrezime", (short)BankType.FirstBank, "360123456789999874", "1234");

                //Act
                await walletService.Deposit(jmbg, password, 1000m);

                //Assert
                Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById(jmbg);

                Assert.AreEqual(1000m, wallet.Balance, "Balance must be 1000");
                Assert.AreNotEqual(0, wallet.Transactions.Count(), "Transaction count must be different than 0");
                Assert.AreEqual(TransactionType.Deposit, wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Type);
                Assert.AreEqual(1000m, wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Amount, $"Transaction amount must be 10000.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task DepositSuccess()
        {
            try
            {
                //Arrange
                WalletService walletService = new WalletService(_coreUnitOfWork,
                                                                new RakicRaiffeisenBrosBankService(),
                                                                new PassService(TestConfigurations.PassMin, TestConfigurations.PassMin),
                                                                TestConfigurations.NumberOfDaysBeforeComission,
                                                                new TransferFactory(TestConfigurations.PercentageComissionStartingAmount,
                                                                                    TestConfigurations.FixedComission,
                                                                                    TestConfigurations.PercentageComission),
                                                                TestConfigurations.MaxWithdraw, TestConfigurations.MaxDeposit);


                var result = await walletService.Deposit(
                    "2609992760002", "111111", 20000);

                var wallet = await _coreUnitOfWork.WalletRepository.GetById(result.Id);

                Assert.AreEqual(20000, wallet.Balance, "Balance doesn't match");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task DepositFromWalletFail_TooMuchMoney()
        {
            try
            {
                //Arrange
                WalletService walletService = new WalletService(_coreUnitOfWork,
                                                                new RakicRaiffeisenBrosBankService(),
                                                                new PassService(TestConfigurations.PassMin, TestConfigurations.PassMin),
                                                                TestConfigurations.NumberOfDaysBeforeComission,
                                                                new TransferFactory(TestConfigurations.PercentageComissionStartingAmount,
                                                                                    TestConfigurations.FixedComission,
                                                                                    TestConfigurations.PercentageComission),
                                                                TestConfigurations.MaxWithdraw, TestConfigurations.MaxDeposit);

                var result = await walletService.Deposit(
                    "2609992760002", "111111", 1000001);

                Assert.Fail("Expected error not thrown");
            }
            catch (WalletServiceException ex)
            {
                Assert.IsTrue(ex is WalletServiceException);
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#5
0
        private static void DepositExample()
        {
            var walletService = new WalletService(_merchantAuthInfo);

            try
            {
                var response = walletService.Deposit(new DepositRequest
                {
                    Amount        = 100,
                    TransactionId = Guid.NewGuid().ToString(),
                    Currency      = "TRY",
                    UserId        = "111450",
                    Token         = "private token"
                });

                if (response.StatusCode == StatusCodes.Success)
                {
                    var result = response.Data;

                    Console.WriteLine($"{nameof(result.TransactionId)}: {result.TransactionId}, {nameof(result.Balance)}: {result.Balance}");
                }
            }
            catch (CantConnectToServerException ex)
            {
                Console.WriteLine(ex);
            }
        }
        public async Task SuccessGetWalletTransactionsByDateTest()
        {
            try
            {
                string jmbg = "2904992785075";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password      = await walletService.CreateWallet(jmbg, "TestIme", "TestPrezime", (short)BankType.FirstBank, "360123456789999874", "1234");

                await walletService.Deposit(jmbg, password, 1000m);

                //Act
                var walletTransactionsDTO = await walletService.GetWalletTransactionsByDate(jmbg, password, DateTime.Now);

                //Assert
                Wallet wallet = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes(w => w.JMBG == jmbg,
                                                                                                    w => w.Transactions.Where(t => t.TransactionDateTime.Date == DateTime.Now.Date));

                Assert.AreEqual(walletTransactionsDTO.JMBG, wallet.JMBG);
                Assert.AreEqual(walletTransactionsDTO.Balance, wallet.Balance);
                Assert.AreEqual(walletTransactionsDTO.Transactions.Count, 1);
                Assert.AreEqual(walletTransactionsDTO.Transactions.Count, wallet.Transactions.Count);
                Assert.AreEqual(walletTransactionsDTO.Transactions.First().Type, TransactionType.Deposit);
                Assert.AreEqual(walletTransactionsDTO.Transactions.First().Amount, 1000m);
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task FailWalletTransferTest5()
        {
            try
            {
                string jmbg1 = "2904992785075";
                string jmbg2 = "2904990785034";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password1     = await walletService.CreateWallet(jmbg1, "TestIme1", "TestPrezime1", (short)BankType.FirstBank, "360123456789999874", "1234");

                string password2 = await walletService.CreateWallet(jmbg2, "TestIme2", "TestPrezime2", (short)BankType.FirstBank, "360123456789999889", "1224");

                await walletService.Deposit(jmbg1, password1, 2000m);

                Wallet wallet2 = await CoreUnitOfWork.WalletRepository.GetById(jmbg2);

                wallet2.Block();

                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Transfer(jmbg1, password1, 2000000m, jmbg2), $"Forbidden transfer to blocked wallet #{jmbg2}");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#8
0
        private async Task TryWalletDeposit_OnBlockedWallet()
        {
            //Arrange
            WalletService walletService = new WalletService(_coreUnitOfWork,
                                                            new RakicRaiffeisenBrosBankService(),
                                                            new PassService(TestConfigurations.PassMin, TestConfigurations.PassMin),
                                                            TestConfigurations.NumberOfDaysBeforeComission,
                                                            new TransferFactory(TestConfigurations.PercentageComissionStartingAmount,
                                                                                TestConfigurations.FixedComission,
                                                                                TestConfigurations.PercentageComission),
                                                            TestConfigurations.MaxWithdraw, TestConfigurations.MaxDeposit);

            try
            {
                var result = await walletService.Deposit(
                    "2609992760000", "111111", 1000);

                Assert.Fail("Expected error not thrown");
            }
            catch (WalletServiceException ex)
            {
                var wallet = await walletService.GetWallet("2609992760000", "111111");

                Assert.AreEqual(20000, wallet.Balance, "Balance doesn't match");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task WalletWithdrawWalletBlockedFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password, 750000M);

                Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById("0605996781029");

                wallet.Block();
                await CoreUnitOfWork.WalletRepository.Update(wallet);

                await CoreUnitOfWork.SaveChangesAsync();

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Withdraw("0605996781029", password, 500000M), $"Wallet '{0605996781029}' is blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task WalletDepositSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                //Act
                await walletService.Deposit("0605996781029", password, 100000M);

                //Assert
                Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById("0605996781029");

                Assert.AreEqual(100000M, wallet.Balance, "Wallet balance must be 100000");
                Assert.AreEqual(1, wallet.Transactions.Count(), $"A transaction must exist on the wallet.");
                Assert.AreEqual(TransactionType.Deposit, wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Type, $"A transaction of type {TransactionType.Deposit} must exist on the wallet.");
                Assert.AreEqual(100000M, wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Amount, $"Deposit transaction amount must be 100000.");
                Assert.AreEqual(BankType.BrankoBank.ToString(), wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Source, $"Source of the transaction should be {BankType.BrankoBank}.");
                Assert.AreEqual("0605996781029", wallet.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Deposit).Destination, $"Destination of the transaction should be 0605996781029.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#11
0
        public async Task WalletTransferWithFeeSuccessTest()
        {
            try
            {
                //Arrange
                Configuration["FirstTransactionFreeEachMonth"] = "False";
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password1     = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                string password2 = await walletService.CreateWallet("ime", "prezime", "0605996781028", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password1, 101000M);

                //Act
                await walletService.Transfer("0605996781029", password1, "0605996781028", 100000M);

                //Assert
                Wallet walletSource = await CoreUnitOfWork.WalletRepository.GetById("0605996781029");

                Wallet walletDesitnation = await CoreUnitOfWork.WalletRepository.GetById("0605996781028");

                Assert.AreEqual(0, walletSource.Balance, "Wallet balance must be 0");
                Assert.AreEqual(TransactionType.TransferPayOut, walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Type, $"A transaction of type {TransactionType.TransferPayOut} must exist on the wallet.");
                Assert.AreEqual(100000M, walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Amount, $"{TransactionType.TransferPayOut} transaction amount must be 100000.");
                Assert.AreEqual("0605996781029", walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Source, $"Source of the transaction should be '0605996781029'.");
                Assert.AreEqual("0605996781028", walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Destination, $"Destination of the transaction should be '0605996781028'.");

                Assert.AreEqual(TransactionType.FeePayOut, walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Type, $"A transaction of type {TransactionType.FeePayOut} must exist on the wallet.");
                Assert.AreEqual(1000M, walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Amount, $"{TransactionType.FeePayOut} transaction amount must be 1000.");
                Assert.AreEqual("0605996781029", walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Source, $"Source of the transaction should be '0605996781029'.");
                Assert.AreEqual("System", walletSource.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Destination, $"Destination of the transaction should be 'System'.");

                Assert.AreEqual(100000M, walletDesitnation.Balance, "Wallet balance must be 100000");
                Assert.AreEqual(TransactionType.TransferPayIn, walletDesitnation.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayIn).Type, $"A transaction of type {TransactionType.TransferPayIn} must exist on the wallet.");
                Assert.AreEqual(100000M, walletDesitnation.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayIn).Amount, $"{TransactionType.TransferPayIn} transaction amount must be 100000.");
                Assert.AreEqual("0605996781029", walletDesitnation.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayIn).Source, $"Source of the transaction should be '0605996781029'.");
                Assert.AreEqual("0605996781028", walletDesitnation.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayIn).Destination, $"Destination of the transaction should be '0605996781028'.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
            finally
            {
                Configuration["FirstTransactionFreeEachMonth"] = "True";
            }
        }
        public async Task <IActionResult> Deposit(WalletDepositVM walletDepositVM)
        {
            try
            {
                await WalletService.Deposit(walletDepositVM.JMBG, walletDepositVM.PASS, walletDepositVM.Amount);

                ModelState.Clear();
                ViewData["Success"] = "True";
                return(View());
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message;
                ViewData["Success"]      = "False";
                return(View());
            }
        }
        public async Task GetWalletInfoWithDepositAndWithdrawSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password, 100000M);

                await walletService.Withdraw("0605996781029", password, 50000M);

                //Act
                WalletInfoDTO wallet = await walletService.GetWalletInfo("0605996781029", password);


                //Assert

                Assert.IsNotNull(wallet, "Wallet must not be null");
                Assert.AreEqual("ime", wallet.FirstName, "FirstName must be 'ime'");
                Assert.AreEqual("prezime", wallet.LastName, "LastName must be 'prezime'");
                Assert.AreEqual("0605996781029", wallet.Jmbg, "Jmbg must be '0605996781029'");
                Assert.AreEqual((short)BankType.BrankoBank, wallet.BankType, $"BankType must be '{BankType.BrankoBank}'");
                Assert.AreEqual("123456789876543210", wallet.BankAccount, "BankAccount must be '123456789876543210'");
                Assert.AreEqual(50000M, wallet.Balance, "Balance must be 0 RSD");
                Assert.AreEqual(100000M, wallet.UsedDepositThisMonth, "UsedDepositThisMonth must be 0 RSD");
                Assert.AreEqual(50000M, wallet.UsedWithdrawThisMonth, "UsedWithdrawThisMonth must be 0 RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalDeposit"]), wallet.MaximalDeposit, $"MaximalDeposit must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalWithdraw"]), wallet.MaximalWithdraw, $"MaximalWithdraw must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(2, wallet.TransactionDTOs.Count, "There must be two transactions on the wallet");

                Assert.AreNotEqual(null, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit), $"Tranasction of type {TransactionType.Deposit} must exist on the wallet");
                Assert.AreEqual(100000M, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Amount, $"Deposit transaction amount must be 100000.");
                Assert.AreEqual(BankType.BrankoBank.ToString(), wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Source, $"Source of the transaction should be {BankType.BrankoBank}.");
                Assert.AreEqual("0605996781029", wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Destination, $"Destination of the transaction should be 0605996781029.");

                Assert.AreNotEqual(null, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw), $"Tranasction of type {TransactionType.Withdraw} must exist on the wallet");
                Assert.AreEqual(50000M, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Amount, $"Withdraw transaction amount must be 50000.");
                Assert.AreEqual(BankType.BrankoBank.ToString(), wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Destination, $"Source of the transaction should be {BankType.BrankoBank}.");
                Assert.AreEqual("0605996781029", wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Source, $"Destination of the transaction should be 0605996781029.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task <IActionResult> Deposit(WalletDepositVM walletDepositVM)
        {
            try
            {
                await WalletService.Deposit(walletDepositVM.Jmbg, walletDepositVM.Password, walletDepositVM.Amount);

                ModelState.Clear();
                ViewData["IsSuccessful"] = "yes";
                return(View());
            }
            catch (Exception ex)
            {
                ViewData["IsSuccessful"] = "no";
                ViewData["ErrorMessage"] = ex.Message;

                return(View());
            }
        }
        public async Task SuccessWalletTransferWithFeeTest()
        {
            try
            {
                Configuration["IsFirstTransferFreeInMonth"]       = "False";
                Configuration["DaysAfterWalletCreationWithNoFee"] = "0";
                string jmbg1 = "2904992785075";
                string jmbg2 = "2904990785034";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password1     = await walletService.CreateWallet(jmbg1, "TestIme1", "TestPrezime1", (short)BankType.FirstBank, "360123456789999874", "1234");

                string password2 = await walletService.CreateWallet(jmbg2, "TestIme2", "TestPrezime2", (short)BankType.FirstBank, "360123456789999889", "1224");

                await walletService.Deposit(jmbg1, password1, 2000m);

                //Act

                await walletService.Transfer(jmbg1, password1, 500m, jmbg2);

                //Assert
                Wallet wallet1 = await CoreUnitOfWork.WalletRepository.GetById(jmbg1);

                Wallet wallet2 = await CoreUnitOfWork.WalletRepository.GetById(jmbg2);

                Assert.AreEqual(1400m, wallet1.Balance, "Balance must be 1400");
                Assert.AreEqual(500m, wallet2.Balance, "Balance must be 500");

                Assert.AreNotEqual(0, wallet1.Transactions.Count(), "Transaction count must be different than 0");
                Assert.AreNotEqual(0, wallet2.Transactions.Count(), "Transaction count must be different than 0");

                Assert.AreEqual(TransactionType.TransferPayOut, wallet1.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Type);
                Assert.AreEqual(TransactionType.TransferPayIn, wallet2.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayIn).Type);

                Assert.AreEqual(TransactionType.FeePayOut, wallet1.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Type);
                Assert.AreEqual(100m, wallet1.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.FeePayOut).Amount, $"Transaction transfer fee amount must be 100.");

                Assert.AreEqual(500m, wallet1.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.TransferPayOut).Amount, $"Transaction amount must be 500.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#16
0
        public async Task WalletTransferDestinationAccountDoesntExistFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password, 750000M);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await walletService.Transfer("0605996781029", password, "0605996781028", 500000), $"No wallet for entered jmbg '{"0605996781028"}' and password pair.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#17
0
        public async Task WalletTransferSourceAndDestinationJmbgSameFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password, 500000M);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await walletService.Transfer("0605996781029", password, "0605996781029", 500000), $"Source and destination Jmbg must be different.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task FailWalletTransferTest1()
        {
            try
            {
                string jmbg1 = "2904992785075";
                string jmbg2 = "2904990785034";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password1     = await walletService.CreateWallet(jmbg1, "TestIme1", "TestPrezime1", (short)BankType.FirstBank, "360123456789999874", "1234");

                string password2 = await walletService.CreateWallet(jmbg2, "TestIme2", "TestPrezime2", (short)BankType.FirstBank, "360123456789999889", "1224");

                await walletService.Deposit(jmbg1, password1, 2000m);

                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Transfer(jmbg1, password1, 2000000m, jmbg2), $"Exceeded monthly withdraw and deposit limit ({Configuration["MaxDeposit"]} RSD).");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#19
0
        public async Task WalletTransferDestinationWalletBlockedFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password1     = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                string password2 = await walletService.CreateWallet("ime", "prezime", "0605996781028", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password1, 500000M);

                await walletService.BlockWallet("0605996781028", Configuration["AdminPassword"]);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Transfer("0605996781029", password1, "0605996781028", 500000), $"Wallet '{0605996781029}' is blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task FailWalletWithdrawTest4()
        {
            try
            {
                string jmbg = "2904992785075";
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
                string password      = await walletService.CreateWallet(jmbg, "TestIme", "TestPrezime", (short)BankType.FirstBank, "360123456789999874", "1234");

                await walletService.Deposit(jmbg, password, 1000m);

                Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById(jmbg);

                wallet.Block();
                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Withdraw(jmbg, password, 1000m), $"Forbidden withdraw on blocked wallet.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#21
0
        public async Task <IActionResult> Deposit(string jmbg, string pass, decimal amount)
        {
            try
            {
                var wallet = await WalletService.Deposit(jmbg, pass, amount);

                TempData["Success"] = "Money is successfully added!";
                return(RedirectToAction("WalletInfo", new { jmbg = wallet.JMBG, pass = wallet.PASS }));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, ex.Message);
                if (ex is EstimationPracticeException e)
                {
                    TempData["Error"] = e.EstimationPracticeExceptionMessage;
                }
                else
                {
                    TempData["Error"] = BasicErrorMessage;
                }

                return(View());
            }
        }
        public async Task WalletDepositNotEnoughFundsInBankFailTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Deposit("0605996781029", password, 1100000M), "Bank account doesn't have enoguh funds!");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
示例#23
0
        public async Task FailWalletDepositTest2()
        {
            try
            {
                string jmbg = "2904992785075";
                string pass = "******";
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Deposit(jmbg, pass, 1000m), $"Wallet doesn't exist");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
 public JsonResult Deposit([FromServices] WalletService walletService, [FromQuery] long userId, [FromQuery] int currencyId, [FromQuery] decimal sum)
 {
     walletService.Deposit(userId, currencyId, sum);
     return(new JsonResult("Ok"));
 }
        public async Task WalletDepositWalletDoesntExistFailTest()
        {
            try
            {
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await walletService.Deposit("0605996781029", "1234", 1100000M), $"No wallet for entered jmbg '{"0605996781029"}' and password pair.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }