public void CustomerSearchTest() { NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5); _repository.GetCustomers().AddRange(representation.Customers); CustomerService sut = new CustomerService(_repository); var result = sut.SearchAfterCustomerWithAreaOrName("Name"); Assert.Equal(_repository.GetCustomers().Count, result.Count); }
public void CustomerSearchByCustomerId() { NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetCustomers().AddRange(representation.Customers); CustomerService sut = new CustomerService(fakeProvider); var result = sut.GetCustomerByCustomerId("1"); Assert.Equal(1, result.CustomerId); }
public void FakeRepositoryAndSampleCreationWorksForTests() { NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetCustomers().AddRange(representation.Customers); fakeProvider.GetAccounts().AddRange(representation.Accounts); Assert.True(fakeProvider.GetCustomers().Count == 5); Assert.True(fakeProvider.GetAccounts().Count == 10); }
public void CetCustomerByCustomerId() { NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetCustomers().AddRange(representation.Customers); BankSystem sut = new BankSystem(fakeProvider); sut.Initialize(); var result1 = sut.GetCustomerById("1"); Assert.Throws <NullReferenceException>(() => sut.GetCustomerById("0")); Assert.Equal(1, result1.CustomerId); }
public void DeleteAccountValidatesAndRemoves() { //Assemble var setupData = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(1, 100M); _repository.GetAccounts().AddRange(setupData.Accounts); Account account1 = setupData.Accounts[0]; Account account2 = setupData.Accounts[1]; AccountService sut = new AccountService(_repository); //Act & assert Assert.False(sut.RemoveAccount(account1)); account1.Balance = 0M; Assert.True(sut.RemoveAccount(account1)); Assert.False(sut.RemoveAccount(account2)); Assert.True(setupData.Customers[0].Accounts.Count == 1 && _repository.GetAccounts().Count == 1); }
public void RemoveCustomerValidatesAndRemoves() { //Assemble var setupData = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(1, 100M); _repository.GetAccounts().AddRange(setupData.Accounts); _repository.GetCustomers().AddRange(setupData.Customers); Customer customer = setupData.Customers[0]; CustomerService sut = new CustomerService(_repository); //Act & assert Assert.False(sut.RemoveCustomer(customer)); customer.Accounts.ElementAt(0).Balance = 0M; customer.Accounts.ElementAt(1).Balance = 0M; Assert.True(sut.RemoveCustomer(customer)); Assert.True(_repository.GetCustomers().Count == 0); Assert.True(_repository.GetAccounts().Count == 0); }
public void DepositToAccount() { //Assemble NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5, 0M); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetAccounts().AddRange(representation.Accounts); AccountService sut = new AccountService(fakeProvider); BankSystem bank = new BankSystem(fakeProvider); bank.Initialize(); //Act sut.Deposit(2, 100M); //Act & assert Assert.True(fakeProvider.GetAccounts().Single(x => x.AccountId == 2).Balance == 100); Assert.Throws <ArgumentOutOfRangeException>(() => sut.Withdraw(1, -1M)); Assert.Throws <NullReferenceException>(() => sut.Withdraw(100, 1M)); }
public void WithdrawFromAccount() { //Assemble NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5, 100M); _repository.GetAccounts().AddRange(representation.Accounts); BankSystem sut = new BankSystem(_repository); sut.Initialize(); //Act sut.WithdrawFromAccount(2, 100M); //Act & assert Assert.True(_repository.GetAccounts().Single(x => x.AccountId == 2).Balance == 0); sut.WithdrawFromAccount(1, 101M); sut.WithdrawFromAccount(1, -1M); sut.WithdrawFromAccount(100, 1M); //Assert.Throws<InvalidOperationException>(() => sut.WithdrawFromAccount(1, 101M)); //Assert.Throws<ArgumentOutOfRangeException>(() => sut.WithdrawFromAccount(1, -1M)); //Assert.Throws<NullReferenceException>(() => sut.WithdrawFromAccount(100, 1M)); }