public void BankAccountRepositoryAddNewItemSaveItem() { //Arrange var unitOfWork = new MainBCUnitOfWork(); var customerRepository = new CustomerRepository(unitOfWork); var bankAccountRepository = new BankAccountRepository(unitOfWork); var customer = customerRepository.Get(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45")); var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01"); var newBankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber); //Act bankAccountRepository.Add(newBankAccount); try { unitOfWork.Commit(); } catch (DbUpdateException ex) { var entry = ex.Entries.First(); } }
public void AddBankAccount() { // Arrange _dbContext.Customers.Add(new Customer { Name = Guid.NewGuid().ToString(), Surname = Guid.NewGuid().ToString(), DateCreated = DateTime.UtcNow }); _dbContext.SaveChanges(); var bankAccountRepository = new BankAccountRepository(_dbContext); bankAccountRepository.Add(new BankAccount { CustomerId = 1 }).GetAwaiter().GetResult(); _dbContext.SaveChanges(); // Act var bankAccount = _dbContext.BankAccounts.First(b => b.CustomerId == 1); // Assert Assert.NotNull(bankAccount); Assert.Equal(0, bankAccount.Balance); }
public void CustomerService_Customer_WithBankAccount() { // Arrange var customerService = new CustomerService(new CustomerRepository(_dbContext), new BankAccountRepository(_dbContext), new TransactionRepository(_dbContext)); var name = Guid.NewGuid().ToString(); var surname = Guid.NewGuid().ToString(); _dbContext.Customers.Add(new Customer { Name = name, Surname = surname, DateCreated = DateTime.UtcNow }); _dbContext.SaveChanges(); var bankAccountRepository = new BankAccountRepository(_dbContext); bankAccountRepository.Add(new BankAccount { CustomerId = 1 }).GetAwaiter().GetResult(); _dbContext.SaveChanges(); // Act var customer = customerService.GetCustomer(1).GetAwaiter().GetResult(); // Assert Assert.NotNull(customer); Assert.Equal(name, customer.Name); Assert.Equal(surname, customer.Surname); Assert.True(1 == customer.BankAccounts.Count()); }
public void BankAccountRepositoryAddNewItemSaveItem() { //Arrange var unitOfWork = new MainBCUnitOfWork(); var customerRepository = new CustomerRepository(unitOfWork); var bankAccountRepository = new BankAccountRepository(unitOfWork); var customer = customerRepository.Get(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45")); var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01"); var newBankAccount = BankAccountFactory.CreateBankAccount(customer,bankAccountNumber); //Act bankAccountRepository.Add(newBankAccount); try { unitOfWork.Commit(); } catch (DbUpdateException ex) { var entry = ex.Entries.First(); } }
public void Add(BankAccount account) { if (account is null) { throw new ArgumentNullException($"The {nameof(account)} has null reference"); } if (IsExists(account)) { throw new NotImplementedException($"The {nameof(account)} already exists"); } _bankAccountRepository.Add(account); }
public void BankAccountRepositoryRemoveItemDeleteIt() { //Arrange var unitOfWork = new MainBcUnitOfWork(); var customerRepository = new CustomerRepository(unitOfWork); var bankAccountRepository = new BankAccountRepository(unitOfWork); var customer = customerRepository.Get(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45")); var bankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"); var newBankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber); bankAccountRepository.Add(newBankAccount); unitOfWork.Commit(); //Act bankAccountRepository.Remove(newBankAccount); unitOfWork.Commit(); }
public void BankAccountRepositoryAddNewItemSaveItem() { //Arrange var unitOfWork = new MainBCUnitOfWork(); IBankAccountRepository bankAccountRepository = new BankAccountRepository(unitOfWork); Guid customerId = new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45"); var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01"); BankAccount newBankAccount = BankAccountFactory.CreateBankAccount(customerId,bankAccountNumber); newBankAccount.Id = IdentityGenerator.NewSequentialGuid(); //Act bankAccountRepository.Add(newBankAccount); bankAccountRepository.UnitOfWork.Commit(); //Assert var inserted = bankAccountRepository.Get(newBankAccount.Id); Assert.IsNotNull(inserted); }
public ActionResult Create([Bind(Include = "AccountType_ID")] BankAccount bankAccount) { Random rnd = new Random(); string iban = "HR"; for (int i = 0; i < 19; i++) { int random = rnd.Next(0, 9); iban += random.ToString(); } bankAccount.IBAN = iban; bankAccount.MoneyAmount = 0; bankAccount.User_ID = User.Identity.GetUser_ID(); if (ModelState.IsValid) { BankAccountRepository.Add(bankAccount); return(RedirectToAction("Index")); } ViewBag.AccountType_ID = new SelectList(AccountTypeRepository.GetList(), "ID", "Type", bankAccount.AccountType_ID); ViewBag.User_ID = new SelectList(UserRepository.GetList(), "ID", "UserName", bankAccount.User_ID); return(View(bankAccount)); }
public void Add(BankAccount bankAccount) { _bankAccountRepository.Add(bankAccount); }
public void BankAccountRepositoryRemoveItemDeleteIt() { //Arrange var unitOfWork = new MainBCUnitOfWork(); IBankAccountRepository bankAccountRepository = new BankAccountRepository(unitOfWork); Guid customerId = new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45"); var bankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"); BankAccount newBankAccount = BankAccountFactory.CreateBankAccount(customerId, bankAccountNumber); newBankAccount.Id = IdentityGenerator.NewSequentialGuid(); bankAccountRepository.Add(newBankAccount); bankAccountRepository.UnitOfWork.Commit(); //Act bankAccountRepository.Remove(newBankAccount); bankAccountRepository.UnitOfWork.Commit(); var result = bankAccountRepository.Get(newBankAccount.Id); //Assert Assert.IsNull(result); }