Example #1
0
        public async Task CalculateTransferFeeFixedFeeSuccessTest()
        {
            try
            {
                //Arrange
                Configuration["FirstTransactionFreeEachMonth"] = "False";
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                //Act
                decimal fee1 = await walletService.CalculateTransferFee("0605996781029", password, 1);

                decimal fee2 = await walletService.CalculateTransferFee("0605996781029", password, 5000);

                decimal fee3 = await walletService.CalculateTransferFee("0605996781029", password, 9999);

                //Assert
                Assert.AreEqual(100, fee1, "Fee1 must be 100.00 RSD.");
                Assert.AreEqual(100, fee2, "Fee2 must be 100.00 RSD.");
                Assert.AreEqual(100, fee3, "Fee3 must be 100.00 RSD.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
            finally
            {
                Configuration["FirstTransactionFreeEachMonth"] = "True";
            }
        }
Example #2
0
        public async Task CalculateTransferFeeFirstTransferInMonthNoFeeSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

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

                //Act
                decimal fee1 = await walletService.CalculateTransferFee("0605996781029", password, 10000);

                var date  = new SqlParameter("@LastTransferDateTime", $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
                var query = DbContext.Database
                            .ExecuteSqlRaw("UPDATE Wallets SET LastTransferDateTime = @LastTransferDateTime", date);
                DbContext.Entry(wallet).Reload();

                decimal fee2 = await walletService.CalculateTransferFee("0605996781029", password, 100000);

                //Assert
                Assert.AreEqual(0, fee1, "Fee1 must be 0.00 RSD.");
                Assert.AreEqual(1000, fee2, "Fee2 must be 1000.00 RSD.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
        public async Task <IActionResult> CalculateFee([FromBody] CalculateFeeVM calculateFeeVM)
        {
            try
            {
                decimal fee = await WalletService.CalculateTransferFee(calculateFeeVM.JMBG, calculateFeeVM.PASS, calculateFeeVM.Amount);

                return(Ok(fee));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { errorMessage = ex.Message }));
            }
        }
Example #4
0
        public async Task CalulateTransferFeeLessThanOrEqualToZeroAmountFailTest()
        {
            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.CalculateTransferFee("0605996781029", password, 0M), "Amount must be higher than 0 RSD.");;
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Example #5
0
        public async Task CalulateTransferFeeWrongPasswordFailTest()
        {
            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.CalculateTransferFee("0605996781029", "12345", 1100000M), $"No wallet for entered jmbg '{"0605996781029"}' and password pair.");;
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Example #6
0
        public async Task CalulateTransferFeeNoWalletFailTest()
        {
            try
            {
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);

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