Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        //returns a sample to use with the netcoin fake repository
        //if no default account balance is given, the balance is the same as the customer id
        //if a default is given it is applied to every account
        //the customer names and IDs start on 1 and follows a pattern like this: CustomerId = 1, Name = 1Name
        //every customer gets two accounts with unique account IDs starting on 1
        public static NetcoinRepoRepresentation CreateSampleCustomersAndAccounts(int amountOfCustomers, decimal?defaultAccountBalance = null)
        {
            NetcoinRepoRepresentation retVal = new NetcoinRepoRepresentation();
            int accountNoTracker             = 1;

            for (int i = 1; i <= amountOfCustomers; i++)
            {
                Customer customer = new Customer()
                {
                    CustomerId = i,
                    Name       = $"{ i }Name",
                    Address    = $"{ i }Address",
                    Area       = $"{ i }Area",
                    LegalId    = $"{ i }LegalId",
                    PostalCode = $"{ i }PostalCode",
                    Accounts   = new List <Account>()
                };

                for (int n = 0; n < 2; n++)
                {
                    Account account;
                    if (defaultAccountBalance != null)
                    {
                        account = CreateAccountForSample(accountNoTracker, (decimal)defaultAccountBalance, customer);
                    }
                    else
                    {
                        account = CreateAccountForSample(accountNoTracker, Convert.ToDecimal(i), customer);
                    }

                    accountNoTracker++;
                    customer.Accounts.Add(account);
                    retVal.Accounts.Add(account);
                }

                retVal.Customers.Add(customer);
            }

            return(retVal);
        }
Ejemplo n.º 7
0
        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));
        }