Exemplo n.º 1
0
        public async Task BlockWallet()
        {
            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.BlockWallet("2609992760000");

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

                Assert.AreNotEqual(null, wallet, "Wallet must not be null");
                Assert.AreEqual(true, wallet.IsBlocked, "Wallet is not blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task <IActionResult> ManageWallet(WalletManagementVM walletManagementVM)
        {
            try
            {
                if (walletManagementVM.Action == "Block")
                {
                    await WalletService.BlockWallet(walletManagementVM.WalletJMBG, walletManagementVM.AdminPASS);

                    ModelState.Clear();
                    ViewData["SuccessMessage"] = "Wallet successfully blocked.";
                    ViewData["Success"]        = "True";
                    return(View());
                }
                else
                {
                    await WalletService.UnblockWallet(walletManagementVM.WalletJMBG, walletManagementVM.AdminPASS);

                    ModelState.Clear();
                    ViewData["SuccessMessage"] = "Wallet successfully unblocked.";
                    ViewData["Success"]        = "True";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message;
                ViewData["Success"]      = "False";
                return(View());
            }
        }
Exemplo n.º 3
0
        public async Task SuccessGetWalletInfoTest2()
        {
            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.BlockWallet(jmbg, Configuration["AdminPASS"]);

                //Act
                var walletInfoDTO = await walletService.GetWalletInfo(jmbg, password);

                //Assert

                Assert.AreEqual(walletInfoDTO.JMBG, jmbg);
                Assert.AreEqual(walletInfoDTO.FirstName, "TestIme");
                Assert.AreEqual(walletInfoDTO.LastName, "TestPrezime");
                Assert.AreEqual(walletInfoDTO.Bank, BankType.FirstBank);
                Assert.AreEqual(walletInfoDTO.BankAccountNumber, "360123456789999874");
                Assert.AreEqual(walletInfoDTO.Balance, 0m);
                Assert.AreEqual(walletInfoDTO.IsBlocked, true);
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task SuccessGetWalletTransactionsByDateTest2()
        {
            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);

                await walletService.BlockWallet(jmbg, Configuration["AdminPASS"]);

                //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 Transfer_SecondWalletBlocked_Fail()
        {
            try
            {
                //Arrange
                WalletService walletService = new WalletService(_coreUnitOfWork,
                                                                new RakicRaiffeisenBrosBankService(),
                                                                new PassService(TestConfigurations.PassMin, TestConfigurations.PassMin),
                                                                "7",
                                                                new TransferFactory(TestConfigurations.PercentageComissionStartingAmount,
                                                                                    TestConfigurations.FixedComission,
                                                                                    TestConfigurations.PercentageComission),
                                                                TestConfigurations.MaxWithdraw, TestConfigurations.MaxDeposit);

                await walletService.BlockWallet("2609992760005");

                var result = await walletService.Transfer(
                    "2609992760004", "2609992760005", "111111", 1000);

                Assert.Fail("Expected error not thrown");
            }
            catch (WalletServiceException ex)
            {
                Assert.IsTrue(ex is WalletServiceException);
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> BlockWallet(string pass, string jmbg)
        {
            if (!AdminRoleHelper.IsAdmin(pass))
            {
                TempData["Error"] = "U are not admin!";
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                var wallet = await WalletService.BlockWallet(jmbg);

                TempData["Success"] = "Wallet is successfully blocked!";
                return(RedirectToAction("AdminPanel", new { pass = 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 <IActionResult> AdministerWallet(WalletAdministrationVM walletAdministrationVM)
        {
            try
            {
                if (walletAdministrationVM.Action == "Block")
                {
                    await WalletService.BlockWallet(walletAdministrationVM.Jmbg, walletAdministrationVM.AdminPassword);

                    ModelState.Clear();
                    ViewData["SuccessMessage"] = "Wallet has been blocked successfully";
                }
                else if (walletAdministrationVM.Action == "Unblock")
                {
                    await WalletService.UnblockWallet(walletAdministrationVM.Jmbg, walletAdministrationVM.AdminPassword);

                    ModelState.Clear();
                    ViewData["SuccessMessage"] = "Wallet has been unblocked successfully";
                }
                else
                {
                    throw new ArgumentException("Unknown action");
                }
                ViewData["IsSuccessful"] = "yes";
                return(View());
            }
            catch (Exception ex)
            {
                ViewData["IsSuccessful"] = "no";
                ViewData["ErrorMessage"] = ex.Message;

                return(View());
            }
        }
Exemplo n.º 8
0
        public async Task BlockWalletAlreadyBlockedFailTest()
        {
            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.BlockWallet("0605996781029", Configuration["AdminPassword"]);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.BlockWallet("0605996781029", Configuration["AdminPassword"]), $"Wallet '0605996781029' is already blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Exemplo n.º 9
0
        public async Task BlockWalletSuccessTest()
        {
            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.BlockWallet("0605996781029", Configuration["AdminPassword"]);

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

                Assert.AreEqual(true, wallet.IsBlocked, $"Wallet {wallet.Jmbg} must be blocked.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task SuccessBlockWalletTest()
        {
            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.BlockWallet(jmbg, Configuration["AdminPASS"]);

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

                Assert.AreEqual(true, wallet.IsBlocked, "Wallet must be blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task FailUnblockWalletTest()
        {
            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


                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await walletService.BlockWallet(jmbg, "123456"), $"Invalid admin pass");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task FailBlockWalletTest3()
        {
            try
            {
                string jmbg = "2904992785075";
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);

                //Act


                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.BlockWallet(jmbg, Configuration["AdminPASS"]), $"Wallet doesn't exist");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Exemplo n.º 13
0
        public async Task BlockWalletWrongAdminPasswordFailTest()
        {
            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 <ArgumentException>(async() => await walletService.BlockWallet("0605996781029", "654321"), $"Wrong admin password.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Exemplo n.º 14
0
        public async Task BlockWalletWalletDoesntExistFailTest()
        {
            try
            {
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);

                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await walletService.BlockWallet("0605996781029", Configuration["AdminPassword"]), $"No wallet for entered jmbg '{"0605996781029"}'.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }