Ejemplo n.º 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);
            }
        }
        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);
            }
        }
        public async Task GetWalletInfoNewWalletSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                //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);
            }
        }
        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);
            }
        }
Ejemplo n.º 5
0
        public async Task ThrowIfWalletAlreadyExists()
        {
            var contextOptions = new DbContextOptionsBuilder <CasinoContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowIfWalletAlreadyExists")
                                 .Options;

            var user = new User()
            {
                Id = "test-user-id", IsDeleted = false
            };
            var wallet = new Wallet()
            {
                Id = "test-wallet", User = user
            };

            using (var context = new CasinoContext(contextOptions))
            {
                context.Wallets.Add(wallet);
                context.SaveChanges();

                var walletService = new WalletService(context);
                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>
                    (async() => await walletService.CreateWallet("test-user-id", 1));
            }
        }
Ejemplo n.º 6
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";
            }
        }
Ejemplo n.º 7
0
        public async Task CreateWalletIfNoneFound()
        {
            var contextOptions = new DbContextOptionsBuilder <CasinoContext>()
                                 .UseInMemoryDatabase(databaseName: "CreateWalletIfNoneFound")
                                 .Options;

            var user = new User()
            {
                Id = "test-user-id", IsDeleted = false
            };

            var currency = new Currency()
            {
                Id = 1, Name = "Test-currency"
            };

            using (var context = new CasinoContext(contextOptions))
            {
                context.Users.Add(user);
                context.Currencies.Add(currency);
                context.SaveChanges();

                var walletService = new WalletService(context);

                var result = await walletService.CreateWallet("test-user-id", 1);

                Assert.IsNotNull(result);
                Assert.AreEqual("test-user-id", result.UserId);
                Assert.AreEqual(1, result.CurrencyId);
            }
        }
Ejemplo n.º 8
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 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);
            }
        }
Ejemplo n.º 10
0
        public async Task CreateWalletSuccessTest()
        {
            try
            {
                //Arrange
                var walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);

                //Act
                string password = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

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

                Assert.IsNotNull(wallet, "Wallet must not be null");
                Assert.AreEqual(6, password.Length, "Password must be 6 characters long");
                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(BankType.BrankoBank, wallet.BankType, $"BankType must be '{BankType.BrankoBank}'");
                Assert.AreEqual("1234", wallet.PIN, "PIN must be '1234'");
                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(false, wallet.IsBlocked, "Wallet must be unblocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
            finally
            {
            }
        }
Ejemplo n.º 11
0
        public async Task FailCreateWalletTest4()
        {
            WalletService walletService = new WalletService(CoreUnitOfWork, BankRoutingService, FeeService, Configuration);
            string        walletPass    = await walletService.CreateWallet("1203977780011", "Pera", "Peric", 1, "360123456", "1234");

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.CreateWallet("1203977780011", "Pera", "Peric", 1, "360123456", "1234"), $"Wallet already exists");
        }
        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);
            }
        }
Ejemplo n.º 13
0
        public async Task SuccessGetWalletInfoTest()
        {
            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
                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, false);
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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 CreateWallet_WalletUnSuccessfullySavedInDb_ShouldReturnSuccess()
        {
            var sut = new WalletService(Mapper, _walletRepoMock.Object, _emailServiceMock.Object);

            var result = await sut.CreateWallet(Fixture.Create <AddWalletDto>(), Guid.NewGuid().ToString());

            result.Succedeed.Should().BeFalse();
        }
        public void CreateWallet_ThrowsWalletException_ReturnsFalse()
        {
            // Arrange
            var createWalletDetails = new CreateWalletDetails {
                Name = "Wallet One", Password = "******"
            };

            _walletManager
            .Setup(callTo => callTo.CreateWallet(createWalletDetails.Password, createWalletDetails.Name, createWalletDetails.Password, It.IsAny <Mnemonic>()))
            .Throws(new WalletException("Something went wrong"));

            // Act
            var created = _walletService.CreateWallet(createWalletDetails);

            // Assert
            Assert.That(created, Is.False);
        }
        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);
            }
        }
Ejemplo n.º 19
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            var accountservice = new AccountService();
            var userId         = Guid.Parse(accountservice.GetGuid(user.Email));
            var walletService  = new WalletService(userId);

            var wallet = new WalletCreate
            {
                WalletBalance = 50000
            };

            if (!walletService.CreateWallet(wallet))
            {
                return(InternalServerError(new Exception("Error creating Wallet.")));
            }

            var currencyService = new CurrencyService();
            var currencies      = currencyService.GetCurrencies();

            foreach (var currency in currencies)
            {
                var holdingService = new HoldingService(userId);

                var holding =
                    new HoldingCreate()
                {
                    CryptoHoldingBalance = 0,
                    CurrencyId           = currency.CurrencyId,
                    WalletId             = walletService.GetWalletId()
                };

                if (!holdingService.CreateHolding(holding))
                {
                    return(InternalServerError(new Exception($"Error creating entry for Holding: {holding.CurrencyId}")));
                }
            }

            return(Ok());
        }
        public async Task FailWalletTransferTest3()
        {
            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");

                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Transfer(jmbg1, password1, 1000m, jmbg2), $"Not enough funds on wallet #{jmbg1}.");
            }
            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);
            }
        }
Ejemplo n.º 22
0
        public async Task ThrowIfUserNotFound()
        {
            var contextOptions = new DbContextOptionsBuilder <CasinoContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowIfUserNotFound")
                                 .Options;

            using (var context = new CasinoContext(contextOptions))
            {
                var walletService = new WalletService(context);
                await Assert.ThrowsExceptionAsync <EntityNotFoundException>
                    (async() => await walletService.CreateWallet("test-user-id", 1));
            }
        }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
0
        public async Task FailGetWalletInfoTest3()
        {
            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");

                //Assert
                await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await walletService.GetWalletInfo(jmbg, null));
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
0
        public async Task UnblockWalletAlreadyBlockedFailTest()
        {
            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.UnblockWallet("0605996781029", Configuration["AdminPassword"]), $"Wallet '0605996781029' is not blocked");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Ejemplo n.º 27
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);
            }
        }
        public async Task FailWalletWithdrawTest3()
        {
            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");

                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.Withdraw(jmbg, password, 1000m), $"Not enough funds on wallet.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Ejemplo n.º 29
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);
            }
        }
        public async Task FailGetWalletTransactionsByDateTest1()
        {
            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");

                //Assert
                await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await walletService.GetWalletTransactionsByDate(jmbg, "1234", DateTime.Now), "Invalid password");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }