コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public async Task BlockWallet(string jmbg, string adminPass)
        {
            if (string.IsNullOrEmpty(jmbg))
            {
                throw new ArgumentNullException($"{nameof(jmbg)}");
            }
            if (string.IsNullOrEmpty(adminPass))
            {
                throw new ArgumentNullException($"{nameof(adminPass)}");
            }
            if (adminPass != AdminPASS)
            {
                throw new ArgumentException($"Operation {nameof(BlockWallet)}  is forbidden: Invalid AdminPASS");
            }
            Wallet wallet = await CoreUnitOfWork.WalletRepository.GetById(jmbg);

            if (wallet == null)
            {
                throw new InvalidOperationException($"{nameof(Wallet)} with JMBG = {jmbg} doesn't exist");
            }

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

            await CoreUnitOfWork.SaveChangesAsync();
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public async Task <WalletDTO> BlockWallet(int walletId)
        {
            Wallet wallet = await _unitOfWork.WalletRepository.GetById(walletId);

            if (wallet == null)
            {
                throw new ArgumentException($"Wallet with {walletId} doesn't exist");
            }
            wallet.Block();
            await _unitOfWork.WalletRepository.Update(wallet);

            await _unitOfWork.SaveChangesAsync();

            return(new WalletDTO(wallet));
        }
コード例 #5
0
        public async Task BlockWallet(string jmbg, string adminPassword)
        {
            if (adminPassword != Configuration["AdminPassword"])
            {
                throw new ArgumentException($"Wrong admin password.");
            }

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

            if (wallet == null)
            {
                throw new ArgumentException($"No wallet for entered jmbg '{jmbg}'.");
            }

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

            await CoreUnitOfWork.SaveChangesAsync();
        }
コード例 #6
0
        public async Task FailWalletDepositTest3()
        {
            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");

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

                wallet.Block();
                //Act
                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Deposit(jmbg, password, 1000m), $"Forbidden deposit on blocked wallet.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
コード例 #7
0
        public async Task GetWalletInfoBlockedWalletSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

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

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

                await CoreUnitOfWork.SaveChangesAsync();

                //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(0, wallet.Balance, "Balance must be 0 RSD");
                Assert.AreEqual(0, wallet.UsedDepositThisMonth, "UsedDepositThisMonth must be 0 RSD");
                Assert.AreEqual(0, 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(0, wallet.TransactionDTOs.Count, "There must be no transactions on the wallet");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }