public void TransferTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer1 = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var customer2 = new Customer { FirstName = "Legend", LastName = "Baddo" }; var account1 = sut.GetAccountById(sut.CreateAccount(10000, customer1.Id)); var account2 = sut.GetAccountById(sut.CreateCurrentAccount(10000, customer2.Id)); sut.Transfer(account1, account2.AccountNumber, 5000, "Test"); var expected1 = 5000; var expected2 = 15000; //Act var actual1 = sut.GetBalance(account1); var actual2 = sut.GetBalance(account2); //Assert Assert.Equal(expected1, actual1); Assert.Equal(expected2, actual2); } }
/// <summary> /// Removes the instance /// </summary> public static void RemoveInstance() { context = null; IAccountInstance = null; IUserInstance = null; IAuthInstance = null; }
/// <summary> /// Creates new instance of dependency classes /// </summary> public static void AddInstance() { //var options = new DbContextOptionsBuilder<LegendBankContext>().UseSqlite(@"Data Source=C:\Users\hp\Documents\Projects\LegendBankBeta\LegendBankBeta.Lib.Data\LegendBank.db").Options; context = new LegendBankContext(); IAccountInstance = new AccountRepository(context); IUserInstance = new UserRepository(context); IAuthInstance = new AuthRepository(context, IUserInstance); }
public Deposit(IAuthRepository authRepository, IUserRepository userRepository, IAccountRepository accountRepository, LegendBankContext context) { InitializeComponent(); _authRepository = authRepository; _userRepository = userRepository; _accountRepository = accountRepository; _context = context; }
public DashBoard(IAuthRepository authRepository, IUserRepository userRepository, IAccountRepository accountRepository, LegendBankContext context) { InitializeComponent(); _authRepository = authRepository; _userRepository = userRepository; _accountRepository = accountRepository; _context = context; changeDetails(); }
public void CreateCustomerTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new UserRepository(context); //Act var actual = sut.CreateCustomer("Ayobami", "Baddo"); //Assert Assert.IsType <string>(actual); } }
public void RegisterWithExistingEmail() { //Arrange var options = new DbContextOptionsBuilder<LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new UserRepository(context); var auth = new AuthRepository(context, sut); var details = new string[] { "Ayobami", "Baddo", "*****@*****.**", "Legend", "Boss", "*****@*****.**" }; var password1 = Utilities.GenerateHash("abcde"); var password2 = Utilities.GenerateHash("12345"); auth.Register(details[0], details[1], details[2], password1[0], password1[1]); //Act & Assert Assert.Throws<ArgumentException>(() => auth.Register(details[3], details[4], details[2], password2[0], password2[1])); } }
public void DepositNegativeTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var account = sut.GetAccountById(sut.CreateAccount(10000, customer.Id)); //Act & Assert Assert.Throws <InvalidOperationException>(() => sut.Deposit(account, -2000)); } }
public void GetAccountByIdTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; //Act & Assert var actual = sut.GetAccountById(sut.CreateCurrentAccount(10000, customer.Id)); Assert.IsType <Account>(actual); } }
public void RegisterTest() { //Arrange var options = new DbContextOptionsBuilder<LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new UserRepository(context); var auth = new AuthRepository(context, sut); var details = new string[] { "Ayobami", "Baddo", "*****@*****.**" }; var password = Utilities.GenerateHash("hgfiyghgr"); //Act var actual = sut.GetCustomerById(auth.Register(details[0], details[1], details[2], password[0], password[1])); //Assert Assert.IsType<Customer>(actual); } }
public void CreateAccountTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var expected = "Savings Account"; //Act var actual = sut.GetAccountById(sut.CreateAccount(10000, customer.Id)).AccountType; //Assert Assert.Equal(expected, actual); } }
public void TransferMoreThanMinimunAmountTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer1 = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var customer2 = new Customer { FirstName = "Legend", LastName = "Baddo" }; var account1 = sut.GetAccountById(sut.CreateAccount(10000, customer1.Id)); var account2 = sut.GetAccountById(sut.CreateCurrentAccount(10000, customer2.Id)); //Act & Assert Assert.Throws <InvalidOperationException>(() => sut.Transfer(account1, account2.AccountNumber, 9100, "Test")); } }
public void CreateUserTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new UserRepository(context); var customer = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var email = "*****@*****.**"; var password = Utilities.GenerateHash("hgfiyghgr"); //Act var actual = sut.CreateUser(email, password[0], password[1], customer.Id); //Assert Assert.IsType <string>(actual); } }
public void LoginTest() { //Arrange var options = new DbContextOptionsBuilder<LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new UserRepository(context); var auth = new AuthRepository(context, sut); var details = new string[] { "Ayobami", "Baddo", "*****@*****.**", "Legend", "Boss", "*****@*****.**" }; var password1 = Utilities.GenerateHash("abcde"); var password2 = Utilities.GenerateHash("12345"); auth.Register(details[0], details[1], details[2], password1[0], password1[1]); auth.Register(details[3], details[4], details[5], password2[0], password2[1]); //Act var login = auth.Login("*****@*****.**", "abcde"); //Assert Assert.True(login); } }
public void WithdrawTest() { //Arrange var options = new DbContextOptionsBuilder <LegendBankContext>().UseInMemoryDatabase("TestDatabase").Options; using (var context = new LegendBankContext(options)) { var sut = new AccountRepository(context); var customer = new Customer { FirstName = "Ayobami", LastName = "Baddo" }; var account = sut.GetAccountById(sut.CreateAccount(40000, customer.Id)); sut.Withdraw(account, 20000); var expected = 20000; //Act var actual = sut.GetBalance(account); //Assert Assert.Equal(expected, actual); } }
public AccountRepository(LegendBankContext context) { _context = context; }
public UserRepository(LegendBankContext context) { _context = context; }
public AuthRepository(LegendBankContext context, IUserRepository userRepository) { _context = context; userRepo = userRepository; }