static void Main(string[] args)
        {
            BankAccountStorage storage = new BankAccountStorage("BankAccountStorage.bin");

            BankAccountService service = new BankAccountService();

            BankAccount account1 = new BankAccount("454545nn45", "Ivan", "Petrov", 596.30m, 0.15, BancAccountType.Gold);
            BankAccount account2 = new BankAccount("56dj8533d2", "Sergei", "Sidorov", 0m, 0, BancAccountType.Base);
            BankAccount account3 = new BankAccount("45jnd45snn", "Elena", "Ivanova", 100m, 1, BancAccountType.Platinum);

            List <BankAccount> bankAccounts = new List <BankAccount>()
            {
                account1, account2, account3
            };

            ListInput(bankAccounts);

            service.WriteAccounts(storage, bankAccounts);

            service.WithdrawMoney(100m, bankAccounts[0]);
            service.DepositMoney(10m, bankAccounts[1]);
            service.CloseAccount(bankAccounts[2]);
            ListInput(bankAccounts);

            bankAccounts = service.ReadAccounts(storage);
            ListInput(bankAccounts);

            Console.ReadLine();
        }
        public ActionResult CheckBalance([FromRoute] string account)
        {
            try
            {
                var accounts = new List <BankAccount>();
                if (string.IsNullOrWhiteSpace(account))
                {
                    accounts.AddRange(BankAccountService.GetByUser(CurrentLoginInfo.User.Id));
                }
                else
                {
                    var accountEntity = BankAccountService.Get(account);
                    if (CurrentLoginInfo.User.Role.HasFlag(UserRole.Customer) && !BankAccountService.IsOwnedByUser(account, CurrentLoginInfo.User))
                    {
                        return(Forbid());
                    }
                    accounts.Add(accountEntity);
                }

                return(Ok(accounts.Select(x => new {
                    account = x.AccountName,
                    currency = x.Currency.Name,
                    balance = x.Balance
                })));
            }
            catch (Exception ex) when(ex is ArgumentException || ex is BusinessException)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                Logger.LogError("Error while checking balance: " + ex.Message, ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
        public void AddTest()
        {
            IBankAccountRepository repo = new BankAccountRepository();

            BankAccountService newServi = new BankAccountService(repo);

            var getNewData = new BankAccount()
            {
                AccountNumber = "1233-22",
                BankCode      = 237,
                ClientName    = "Jão Teste",
                Cpf_Cnpj      = "105.369.147-10",
                AgencyNumber  = "1458-8",
                OpeningDate   = Convert.ToDateTime("02-02-2020"),
                Status        = "ativo"
            };

            newServi.Add(getNewData);
            //_bankRepository.SaveChanges();

            if (getNewData.Id == 0)
            {
                Assert.Fail("Não foi possivel inserir no banco de dados");
            }
            else
            {
                Assert.IsTrue(getNewData.Id != 0, "Inserido no banco!");
            }
        }
        public ActionResult WithdrawMoney([FromRoute] string account, dynamic body)
        {
            try
            {
                if (!BankAccountService.IsOwnedByUser(account, CurrentLoginInfo.User))
                {
                    return(Forbid());
                }

                string  currency = body.currency ?? body.Currency;
                decimal money    = body.money ?? body.Money ?? body.amount ?? body.Amount;
                string  message  = body.message ?? body.Message ?? body.note ?? body.Note;

                var(transactionId, exchangeRate, delta, newBalance) = TransactionService.Withdraw(account, currency, money, message);
                return(Ok(new { transaction = transactionId, rate = exchangeRate, delta = delta, balance = newBalance }));
            }
            catch (Exception ex) when(ex is ArgumentException || ex is BusinessException)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                Logger.LogError("Error while checking balance: " + ex.Message, ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
Exemple #5
0
        public void BankAccountService_Tests()
        {
            IEnumerable <BankAccount> accs = CustomMapper <BankAccountDTO, BankAccount> .Map(_bankAccounts);

            IRepository <BankAccount> repository = new BankAccountMemoryRepository();

            foreach (var item in accs)
            {
                repository.Create(item);
            }
            IUnitOfWork         unitOfWork = new UnitOfWork(repository);
            IBankAccountService service    = new BankAccountService(unitOfWork);

            BankAccountDTO bankAccount = service.Get(8);

            service.Deposit(bankAccount.Id, 200m);

            Assert.AreEqual(8, bankAccount.Id);
            bankAccount = service.Get(8);
            Assert.AreEqual(700.50m, bankAccount.Balance);
            Assert.AreEqual(20, bankAccount.BonusPoints);

            service.Withdraw(8, 500.50m);
            bankAccount = service.Get(8);
            Assert.AreEqual(200m, bankAccount.Balance);
        }
Exemple #6
0
        public void Delete_Bank_Account_Where_User_Is_Not_Owner_Should_Throw_DaGet_Unauthorized_Exception()
        {
            var dbName          = DataBaseHelper.Instance.NewDataBase();
            var user            = DataBaseHelper.Instance.UseNewUser(dbName);
            var bankAccountType = DataBaseHelper.Instance.UseNewBankAccountType(dbName);
            var bankAccount     = DataBaseHelper.Instance.UseNewBankAccount(dbName, user.Id, bankAccountType.Id);

            var bankAccountService = new BankAccountService();

            using (var context = DataBaseHelper.Instance.CreateContext(dbName))
            {
                var userBankAccount = context.UserBankAccounts.SingleOrDefault(uba =>
                                                                               uba.BankAccountId.Equals(bankAccount.Id) && uba.UserId.Equals(user.Id));
                userBankAccount.IsOwner    = false;
                userBankAccount.IsReadOnly = false;
                context.Update(userBankAccount);

                context.Commit();
            }

            using (var context = DataBaseHelper.Instance.CreateContext(dbName))
            {
                Assert.Throws <DaGetUnauthorizedException>(() =>
                                                           bankAccountService.DeleteBankAccountById(context, user.UserName, bankAccount.Id));
            }
        }
        public BankAccountVerifyResult VerifyAccount(BankAccountVerification bv)
        {
            BankAccount     acct = unitOfWork.BankAccounts.Get(bv.BankAccountId);
            ApplicationUser user = accountManager.GetUserByIdAsync(acct.UserId).Result;

            BankAccountVerifyResult result = new BankAccountVerifyResult();

            var options = new BankAccountVerifyOptions
            {
                AmountOne = bv.Deposit1,
                AmountTwo = bv.Deposit2,
            };

            var service = new BankAccountService();
            CustomerBankAccount bankAccount = service.Verify(
                user.StripeIdCustomer,
                acct.StripeIdBankAccount,
                options
                );


            result.IsVerified = bankAccount.Status == StripeStatuses.verified ? true : false;

            return(result);
        }
 public AccountPage(BankAccountService bankAccountService, BudgetService budgetService)
 {
     InitializeComponent();
     this.bankAccountService = bankAccountService;
     this.budgetService      = budgetService;
     LoadData();
 }
 public Options(IBankDataService bankService, BankAccountService dataService, List<Guid> loginIds, Guid userId)
 {
     BankService = bankService;
     DataService = dataService;
     LoginIds = loginIds;
     UserId = userId;
 }
Exemple #10
0
        static void CreateBankAccount()
        {
            IBankDAO           bankDAO = new InMemoryBankDAO();
            BankAccountService service = new BankAccountService(bankDAO);
            BankAccountManager manager = new BankAccountManager(service);


            Console.Write("Enter UserId: ");
            var userId = Console.ReadLine();

            Console.Write("Enter Account Type: ");
            var accountType = int.Parse(Console.ReadLine());

            Console.Write("Enter balance: ");
            var balance = decimal.Parse(Console.ReadLine());

            var newBankAccount = new BankAccount()
            {
                AccountType = (BankAccountType)accountType,
                Owner       = new BankAppUser()
                {
                    EntityId = userId
                },
                Balance = balance
            };

            manager.CreateAccount(newBankAccount);
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            var bookStorage = new BookListStorage(@"H:\BookStorage.txt");
            var bookService = new BookListService(bookStorage);
            var newBook     = new Book()
            {
                Author = "Author", Cost = 20, ISBN = "346632436562", Name = "Book name", PagesNumber = 246, PublicationYear = 2000, Publisher = "Publisher name"
            };

            Console.WriteLine(bookService.AddBook(newBook));
            var booksList = bookService.GetAllBooks();

            newBook = new Book()
            {
                Author = "Author2", Cost = 20, ISBN = "123632436562", Name = "Book name 2", PagesNumber = 246, PublicationYear = 2000, Publisher = "Publisher name 2"
            };
            Console.WriteLine(bookService.AddBook(newBook));
            booksList = bookService.SortBooksByTag(SearchTags.ISBN);
            var searchingResult = bookService.FindBooksByTag(SearchTags.ISBN, "123632436562");

            var bankAccountStorage = new BankAccountsRepository(@"H:\BankAccountStorage.txt");
            var bankAccountService = new BankAccountService(bankAccountStorage);
            var newBankAccount     = new BankAccount(1, "FirstName", "LastName", 20, 0, false, BankAccountTypes.Standart, 10);

            Console.WriteLine(bankAccountService.AddAccount(newBankAccount));
            newBankAccount = new BankAccount(2, "FirstName2", "LastName2", 22, 3, false, BankAccountTypes.Gold, 20);
            Console.WriteLine(bankAccountService.AddAccount(newBankAccount));
            var bankAccountsList = bankAccountService.GetAllBankAccounts();

            bankAccountService.TopUpInAnAccount(30, bankAccountsList.ToList()[0].AccountId);
            bankAccountService.DebitTheAccount(10, bankAccountsList.ToList()[1].AccountId);

            Console.ReadKey();
        }
Exemple #12
0
 private async Task DeleteItemsAsync(IEnumerable <BankAccountModel> models)
 {
     foreach (var model in models)
     {
         await BankAccountService.DeleteBankAccountAsync(model);
     }
 }
Exemple #13
0
        public void Deposit_CorrectValuesPassed_AddsMoneyCorrectly()
        {
            var repositoryMock            = new Mock <IAccountRepository>();
            var unitOfWorkMock            = Mock.Of <IUnitOfWork>();
            var accountIdGeneratorMock    = Mock.Of <IAccountIdGeneratorService>();
            var bonusPointsCalculatorMock = Mock.Of <IBonusPointsCalculatorService>();

            repositoryMock.Setup(repository => repository.Update(It.Is <BankAccountDto>(dto => dto.Balance == 1000)));
            repositoryMock.Setup(repository => repository.GetAccountById(It.IsAny <string>()))
            .Returns(new BankAccountDto
            {
                FirstName   = string.Empty,
                LastName    = string.Empty,
                Id          = string.Empty,
                AccountType = "PlatinumAccount"
            });

            var service = new BankAccountService(
                repositoryMock.Object,
                unitOfWorkMock,
                accountIdGeneratorMock,
                bonusPointsCalculatorMock);

            service.Deposit(string.Empty, 1000);

            repositoryMock.Verify();
        }
Exemple #14
0
        public void CreateAccount_CorrectValuesPassed_AddsAnAccountToTheRepository()
        {
            var repositoryMock            = new Mock <IAccountRepository>();
            var unitOfWorkMock            = Mock.Of <IUnitOfWork>();
            var accountIdGeneratorMock    = new Mock <IAccountIdGeneratorService>();
            var bonusPointsCalculatorMock = Mock.Of <IBonusPointsCalculatorService>();

            repositoryMock.Setup(repository => repository.Add(
                                     It.Is <BankAccountDto>(dto => dto.FirstName == "1" &&
                                                            dto.LastName == "2" &&
                                                            dto.Id == string.Empty)));
            accountIdGeneratorMock.Setup(generatorService => generatorService.GenerateId(
                                             It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(string.Empty);

            var service = new BankAccountService(
                repositoryMock.Object,
                unitOfWorkMock,
                accountIdGeneratorMock.Object,
                bonusPointsCalculatorMock);

            service.OpenAccount("1", "2", AccountType.Platinum);

            repositoryMock.Verify();
        }
Exemple #15
0
        public void BankAccountRepository_UpdateAccountTest(string firstName, string lastName, string email, string expectedAccountNumber)
        {
            var repositoryMock = new Mock <IBankAccountRepository>();

            repositoryMock.Setup(repository => repository.GetAccount(It.IsAny <string>())).Returns(
                new DtoAccount
            {
                AccountNumber  = expectedAccountNumber,
                AccountType    = "BaseBankAccount",
                Balance        = 100,
                Bonus          = 100,
                OwnerFirstName = firstName,
                OwnerLastName  = lastName
            });
            var accountNumberGeneratorMock = new Mock <IAccountNumberGenerator>(MockBehavior.Strict);

            accountNumberGeneratorMock.Setup(service => service.CreateNumber(new List <BankAccount>())).Returns(expectedAccountNumber);
            var bankAccountService = new BankAccountService(repositoryMock.Object);

            string actualAccountNumber = bankAccountService.CreateAccount(
                AccountType.Base,
                accountNumberGeneratorMock.Object,
                firstName,
                lastName,
                email);

            bankAccountService.Deposit(actualAccountNumber, 100m);
            bankAccountService.Withdraw(actualAccountNumber, 10m);

            repositoryMock.Verify(
                repository => repository.UpdateAccount(It.Is <DtoAccount>(account => account.AccountNumber == expectedAccountNumber)),
                Times.Exactly(2));
        }
Exemple #16
0
 public AddDBEntries(ILoggerFactory loggerFactory, IOptions <SimAppSettings> appSettings)
 {
     this.appSettings = appSettings;
     this.logger      = loggerFactory.CreateLogger <AddDBEntries>();
     this.bankService = new BankAccountService(loggerFactory, appSettings);
     this.cardService = new CardService(loggerFactory, appSettings);
 }
Exemple #17
0
 public ApplicationBankAccountService(
     IBankAccountRepository bankRepository,
     BankAccountService bankAccountService)
 {
     _bankRepository     = bankRepository;
     _bankAccountService = bankAccountService;
 }
Exemple #18
0
        public BankAccountServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new BankAccountService(this.StripeClient);

            this.createOptions = new BankAccountCreateOptions
            {
                Source = "btok_123",
            };

            this.updateOptions = new BankAccountUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new BankAccountListOptions
            {
                Limit = 1,
            };

            this.verifyOptions = new BankAccountVerifyOptions
            {
                Amounts = new List <long>
                {
                    32,
                    45,
                }
            };
        }
Exemple #19
0
        public listing_cards_on_customer()
        {
            var customerService    = new StripeCustomerService(Cache.ApiKey);
            var bankAccountService = new BankAccountService(Cache.ApiKey);
            var cardService        = new StripeCardService(Cache.ApiKey);

            var CustomerCreateOptions = new StripeCustomerCreateOptions
            {
                Email       = "*****@*****.**",
                SourceToken = "tok_visa",
            };
            var Customer = customerService.Create(CustomerCreateOptions);

            var BankAccountCreateOptions = new BankAccountCreateOptions
            {
                SourceBankAccount = new SourceBankAccount()
                {
                    RoutingNumber     = "110000000",
                    AccountNumber     = "000123456789",
                    Country           = "US",
                    Currency          = "usd",
                    AccountHolderName = "Jenny Rosen",
                    AccountHolderType = BankAccountHolderType.Individual,
                }
            };
            var BankAccount = bankAccountService.Create(Customer.Id, BankAccountCreateOptions);

            ListCards = cardService.List(Customer.Id);
        }
        public void DoSomething()
        {
            var repository  = new BankAccountRepository();
            var bankService = new BankAccountService(repository);

            var account1 = CreateAccount();
            var account2 = CreateAccount();
            var account3 = CreateAccount();
            var account4 = CreateAccount();

            account1.Deposite(1700);
            account2.Deposite(1700);
            account3.Deposite(1700);
            account4.Deposite(1700);

            bankService.Add(account1);
            bankService.Add(account2);
            bankService.Add(account3);
            bankService.Add(account4);
            Console.WriteLine(bankService);

            account1.Withdraw(150);
            account2.Status = Status.Close;
            bankService.Remove(account3);

            Console.WriteLine(bankService);
        }
Exemple #21
0
 public ABSAController(ILoggerFactory loggerFactory, IOptions <SimAppSettings> appSettings)
 {
     this.appSettings = appSettings;
     this.logger      = loggerFactory.CreateLogger <ABSAController>();
     this.bankService = new BankAccountService(loggerFactory, appSettings);
     this.bCode       = BankCode.ABSA;
 }
        public void UpdateBalanceDaily_Sucess_35days()
        {
            /// Arrange
            var days           = 35;
            var initialBalance = 200;

            var userAccount = new UserAccount {
                Balance       = initialBalance,
                MonthlyIncome = 30,
                UpdatedAt     = DateTime.Now.AddDays(-days)
            };

            var expectedUserAccount = new UserAccount {
                Balance       = calculateBalance(initialBalance, days),
                MonthlyIncome = calculateIncome(initialBalance, days),
            };

            UserAccountRepositoryMock.Setup(x => x.GetWhere(It.IsAny <Expression <Func <UserAccount, bool> > >()))
            .Returns(
                new UserAccount [] { userAccount });

            var bankAccountService =
                new BankAccountService(UserAccountRepositoryMock.Object);

            /// Act
            var result = bankAccountService.UpdateBalanceDaily();

            /// Assert
            result.Should().BeTrue();
            expectedUserAccount.Balance.Should().Be(userAccount.Balance);
            expectedUserAccount.MonthlyIncome.Should().Be(userAccount.MonthlyIncome);
            UserAccountRepositoryMock.Verify(x => x.Update(It.IsAny <UserAccount>()), Times.Once);
        }
Exemple #23
0
 public AutoInvoiceProdcutPage(InvoiceService invoiceService, BankAccountService bankAccountService)
 {
     InitializeComponent();
     this.invoiceService     = invoiceService;
     this.bankAccountService = bankAccountService;
     SetDataSource();
 }
Exemple #24
0
        public void TestBank()
        {
            Console.WriteLine("*****Test Account Service*****");
            Console.WriteLine("Create service!");
            BankAccount        jo        = new BankAccount(1, "Jo", "Pinkman", 100m, Status.Gold);
            BinaryStorage      storage   = new BinaryStorage();
            BallExchenger      exchenger = new BallExchenger();
            BankAccountService service   = new BankAccountService(jo, storage, exchenger);

            Console.WriteLine("Add more money!");
            Console.WriteLine($"{jo.Cash} - money have Jo!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo!");
            service.PutMoneyIntoTheAccount(1000m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine("Withdraw money!");
            service.WithdrawFromTheAccount(500m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine("Withdraw more money!");
            service.WithdrawFromTheAccount(1000m);
            Console.WriteLine($"{jo.Cash} - money have Jo now!");
            Console.WriteLine($"{jo.BonusBalls} - bonus balls have Jo now!");
            Console.WriteLine($"Lets try to freeze Jo!");
            service.FreezeTheAccount();
            Console.WriteLine("*****End of test Bank's Service*****");
        }
Exemple #25
0
 public ApplicationBankAccountService(
     BankAccountService bankAccountService,
     IBankAccountRepository bankRepository)
 {
     _bankAccountService = bankAccountService;
     _bankRepository     = bankRepository;
 }
        public void CreateBankAccountServiceTest()
        {
            IRepository <int, IBankAccount> repo = repoMock.Object;

            IBankAccountService bankAccountService = new BankAccountService(repo);

            Assert.Empty(dataStore);
        }
Exemple #27
0
        public static void Main(string[] args)
        {
            BankAccountService service = new BankAccountService(new FakeRepository(), new BankAccountsFactory());

            service.CreateAccount(AccountType.BaseAccount, 1, new Client("Brahinets", "Ilia", "Andreevich"), 0, 0);

            Console.ReadKey();
        }
Exemple #28
0
        public void DoSomething()
        {
            var account     = new BankAccountBuilder();
            var bankService = new BankAccountService();

            AddAccountsToService(bankService, account);
            Console.WriteLine(bankService.ToString());
        }
 public InvoicePage(InvoiceService invoiceService, ShopService shopService, BankAccountService bankAccountService)
 {
     InitializeComponent();
     this.invoiceService     = invoiceService;
     this.shopService        = shopService;
     this.bankAccountService = bankAccountService;
     SetupAdditionalData();
 }
Exemple #30
0
        public void Debit()
        {
            int        debitAmount       = 100;
            int        bankAccountAmount = 100;
            BaseEntity notifications     = new BaseEntity();
            int        result            = BankAccountService.Debit(debitAmount, bankAccountAmount, notifications);

            Assert.AreEqual(200, result);
        }
        public void BLL_GetAccountByIdExecute_Test(string lastName, string firstName, string accountID,
                                                   decimal invoiceAmount, double bonusScores)
        {
            var             mock    = new Mock <IRepository>();
            IAccountService service = new BankAccountService(mock.Object);

            service.GetAccountByID(accountID);
            mock.Verify(a => a.FindAccountByID(accountID));
        }
        public OpenpayAPI( string api_key, string merchant_id,bool production = false)
        {
            this.httpClient = new OpenpayHttpClient(api_key, merchant_id, production);
            CustomerService = new CustomerService(this.httpClient);
            CardService = new CardService(this.httpClient);
            BankAccountService = new BankAccountService(this.httpClient);
            ChargeService = new ChargeService(this.httpClient);
            PayoutService = new PayoutService(this.httpClient);
            TransferService = new TransferService(this.httpClient);
            FeeService = new FeeService(this.httpClient);
            PlanService = new PlanService(this.httpClient);
            SubscriptionService = new SubscriptionService(this.httpClient);
			OpenpayFeesService = new OpenpayFeesService(this.httpClient);
			WebhooksService = new WebhookService (this.httpClient);
        }
Exemple #33
0
 public BankController()
 {
     Service = new BankAccountService(AppSession);
     BankService = new PlaidService();
 }
Exemple #34
0
 public BudgetsController()
 {
     Service = new BankAccountService(AppSession);
 }
Exemple #35
0
 public DropboxController()
 {
     Service = new UserRoleService(AppSession);
     BankDataService = new BankAccountService(AppSession);
 }