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); }
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(); }
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)); }
static void Main(string[] args) { BankAccount accountJohn = new BankAccount(1, "John", "Doe", 100.0m, 0, new BaseAccountType(), new DefaultBonusPointsCalculator()); BankAccount accountJimmy = new BankAccount(2, "Jimmy", "McNulty", 0.0m, 10, new GoldAccountType(), new DefaultBonusPointsCalculator()); BankAccount accountJane = new BankAccount(3, "Jane", "Doe", 200.0m, 15, new BaseAccountType(), new DefaultBonusPointsCalculator()); BankAccount accountKima = new BankAccount(4, "Kima", "Greggs", 10.0m, 15, new PlatinumAccountType(), new DefaultBonusPointsCalculator()); BankAccount accountOmar = new BankAccount(5, "Omar", "Little", 1000.0m, 20, new PlatinumAccountType(), new DefaultBonusPointsCalculator()); Console.WriteLine("Create new bank account service\n"); BankAccountService bankAccountService = new BankAccountService(new BinaryFileStorage("accounts.dat")); Console.WriteLine("Open \"Jimmy McNulty\" account\n"); bankAccountService.OpenAccount(accountJimmy); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.WriteLine("Open \"Jane Doe\" account\n"); bankAccountService.OpenAccount(accountJane); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.WriteLine("Deposit 500$ into \"Jimmy McNulty\" account:\n"); bankAccountService.Deposit(accountJimmy, 500.0m); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.WriteLine("Withdraw 18$ from \"Jane Doe\" account:\n"); bankAccountService.Withdraw(accountJane, 18.0m); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.WriteLine("Close \"Jimmy McNulty\" account:\n"); bankAccountService.CloseAccount(accountJimmy); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.WriteLine("Close \"Jane Doe\" account:\n"); bankAccountService.CloseAccount(accountJane); Console.WriteLine("List of accounts:\n"); bankAccountService.ShowAccounts(); Console.ReadLine(); }
public void Deposit(DepositRequest depositRequest) { _bankAccountService.Deposit(depositRequest.AccountId, depositRequest.Amount, ""); }