Example #1
0
        public UserDTO AddBankAccount(UserDTO userDTO)
        {
            if (userDTO != null)
            {
                //check if exists the customer for this bank account
                var associatedCustomer = _customerRepository.Get(bankAccountDTO.CustomerId);

                if (associatedCustomer != null) // if the customer exist
                {
                    //Create a new bank account  number
                    var accountNumber = CalculateNewBankAccountNumber();

                    //Create account from factory
                    var account = BankAccountFactory.CreateBankAccount(associatedCustomer, accountNumber);

                    //save bank account
                    SaveBankAccount(account);

                    //return dto
                    var adapter = TypeAdapterFactory.CreateAdapter();
                    return(adapter.Adapt <BankAccount, BankAccountDTO>(account));
                }
                else //the customer for this bank account not exist, cannot create a new bank account
                {
                    LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotCreateBankAccountForNonExistingCustomer);
                    return(null);
                }
            }
            else // if bank account is null or customer identifier  is empty, cannot create a new bank account
            {
                LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotAddNullBankAccountOrInvalidCustomer);
                return(null);
            }
        }
        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();
            }
        }
Example #3
0
        public BankAccountDTO AddBankAccount(BankAccountDTO bankAccountDTO)
        {
            if (bankAccountDTO == null || bankAccountDTO.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotAddNullBankAccountOrInvalidCustomer));
            }

            //check if exists the customer for this bank account
            var associatedCustomer = _customerRepository.Get(bankAccountDTO.CustomerId);

            if (associatedCustomer != null) // if the customer exist
            {
                //Create a new bank account  number
                var accountNumber = CalculateNewBankAccountNumber();

                //Create account from factory
                var account = BankAccountFactory.CreateBankAccount(associatedCustomer, accountNumber);

                //save bank account
                SaveBankAccount(account);

                return(account.ProjectedAs <BankAccountDTO>());
            }
            else //the customer for this bank account not exist, cannot create a new bank account
            {
                throw new InvalidOperationException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotCreateBankAccountForNonExistingCustomer));
            }
        }
        public void PerformTransferCreateActivities()
        {
            //Arrange
            var customer = GetCustomer();

            var source = BankAccountFactory.CreateBankAccount(
                customer,
                new BankAccountNumber("1111", "2222", "3333333333", "01"));

            source.DepositMoney(1000, "initial load");

            var target = BankAccountFactory.CreateBankAccount(
                customer,
                new BankAccountNumber("1111", "2222", "12312321322", "01"));

            //Act

            var activities = source.BankAccountActivity.Count;

            var bankTransferService = new BankTransferService();

            bankTransferService.PerformTransfer(50, source, target);

            //Assert
            Assert.IsNotNull(source.BankAccountActivity);
            Assert.AreEqual(++activities, source.BankAccountActivity.Count);
        }
        public void BankAccountDepositAndWithdrawSetBalance()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            Assert.AreEqual(bankAccount.Balance, 0);

            bankAccount.DepositMoney(1000, activityReason);
            Assert.AreEqual(bankAccount.Balance, 1000);

            bankAccount.WithdrawMoney(250, activityReason);
            Assert.AreEqual(bankAccount.Balance, 750);
        }
        public void BankAccountWithdrawMoneyAnotateActivity()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var    bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            string activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            //Act
            bankAccount.DepositMoney(1000, activityReason);
            bankAccount.WithdrawMoney(1000, activityReason);

            //Assert
            Assert.True(bankAccount.Balance == 0);
            Assert.NotNull(bankAccount.BankAccountActivity);
            Assert.True(bankAccount.BankAccountActivity.Any());
            Assert.True(bankAccount.BankAccountActivity.Last().Amount == -1000);
            Assert.True(bankAccount.BankAccountActivity.Last().ActivityDescription == activityReason);
        }
        public void BankAccountFactoryCreateValidBankAccount()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));


            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");

            BankAccount bankAccount = null;

            //Act
            bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            var validationContext = new ValidationContext(bankAccount, null, null);
            var validationResults = customer.Validate(validationContext);

            //Assert
            Assert.NotNull(bankAccount);
            Assert.True(bankAccount.BankAccountNumber == bankAccountNumber);
            Assert.False(bankAccount.Locked);
            Assert.True(bankAccount.CustomerId == customer.Id);

            Assert.False(validationResults.Any());
        }
        public void BankAccountLockSetLocked()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            //Act
            bankAccount.Lock();

            //Assert
            Assert.IsTrue(bankAccount.Locked);
        }
        public void BankAccountDepositMaxDecimalThrowOverflowBalance()
        {
            //Arrange
            var country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla Castro",
                "+3422",
                "company",
                country,
                new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            customer.GenerateNewIdentity();

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            bankAccount.DepositMoney(1, activityReason);
            bankAccount.DepositMoney(Decimal.MaxValue, activityReason);
        }
Example #10
0
        public void BankAccountCannotWithDrawMoneyIfBalanceIsLessThanAmountAccount()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var bankAccount       = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            //Act
            bankAccount.WithdrawMoney(200, "the reason..");
        }
Example #11
0
        public void BankAccountCannotDepositMoneyLessThanZero()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var    bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            string activityReason    = "reason";

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccount = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            bankAccount.DepositMoney(-100, activityReason);
        }
        public void PerformTransferThrowExceptionIfSourceCantWithdrawedWithExceedAmoung()
        {
            //Arrange
            var customer = GetCustomer();

            var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01"));

            source.DepositMoney(1000, "initial load");

            var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "12312321322", "01"));


            //Act
            var bankTransferService = new BankTransferService();

            bankTransferService.PerformTransfer(2000, source, target);
        }
        public void PerformTransferThrowExceptionIfTargetBankAccountNumberIsEqualToSourceBankAccountNumber()
        {
            //Arrange
            var customer = GetCustomer();

            var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01"));

            source.DepositMoney(1000, "initial load");
            source.Lock();

            var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01"));


            //Act
            var bankTransferService = new BankTransferService();

            bankTransferService.PerformTransfer(10, source, target);
        }
Example #14
0
        public void PerformTransferThrowExceptionIfTargetIsLockedAccount()
        {
            //Arrange
            var customer = GetCustomer();

            var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01"));

            source.DepositMoney(1000, "initial load");

            var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "12312321322", "01"));

            target.Lock();

            //Act
            var       bankTransferService = new BankTransferService();
            Exception ex = Assert.Throws <InvalidOperationException>(() => bankTransferService.PerformTransfer(10, source, target));

            Assert.IsType <InvalidOperationException>(ex);
        }
        public void PerformTransferThrowExceptionIfSourceCantWithdrawedWithExceedAmoung()
        {
            //Arrange
            var customer = GetCustomer();

            var source = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "3333333333", "01"));

            source.DepositMoney(1000, "initial load");

            var target = BankAccountFactory.CreateBankAccount(customer, new BankAccountNumber("1111", "2222", "12312321322", "01"));


            //Act
            var bankTransferService = new BankTransferService();

            Exception ex = Assert.Throws <InvalidOperationException>(() => bankTransferService.PerformTransfer(2000, source, target));

            Assert.IsType(typeof(InvalidOperationException), ex);
        }
Example #16
0
        public void BankAccountCannotDepositMoneyInLockedAccount()
        {
            //Arrange
            Country country = new Country("Spain", "es-ES");

            country.GenerateNewIdentity();

            var customer = CustomerFactory.CreateCustomer("Unai", "Zorrilla Castro", "+3422", "company", country, new Address("city", "zipcode", "AddressLine1", "AddressLine2"));

            var bankAccountNumber = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var bankAccount       = BankAccountFactory.CreateBankAccount(customer, bankAccountNumber);

            bankAccount.Lock();

            //Act
            Exception ex = Assert.Throws <InvalidOperationException>(() => bankAccount.DepositMoney(200, "the reason.."));

            Assert.IsType <InvalidOperationException>(ex);
        }
        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();
        }
Example #18
0
        public static void Initialize(MainBCUnitOfWork context)
        {
            ////Demo data
            context.Database.EnsureCreated();

            // Seed the database
            if (context.Countries.Any())
            {
                return;
            }

            //Countries
            var spain = new Country("Spain", "ES");

            spain.GenerateNewIdentity();
            context.Countries.Add(spain);

            var us = new Country("U.S.", "US");

            us.GenerateNewIdentity();
            context.Countries.Add(us);

            var uk = new Country("U.K.", "GB");

            uk.GenerateNewIdentity();
            context.Countries.Add(uk);

            var canada = new Country("Canada", "CA");

            canada.GenerateNewIdentity();
            context.Countries.Add(canada);

            var italy = new Country("Italy", "IT");

            italy.GenerateNewIdentity();
            context.Countries.Add(italy);

            var france = new Country("France", "FR");

            france.GenerateNewIdentity();
            context.Countries.Add(france);

            var argentina = new Country("Argentina", "AR");

            argentina.GenerateNewIdentity();
            context.Countries.Add(argentina);

            var russia = new Country("Russian Federation", "RUS");

            russia.GenerateNewIdentity();
            context.Countries.Add(russia);

            var israel = new Country("Israel", "IS");

            israel.GenerateNewIdentity();
            context.Countries.Add(israel);

            var brazil = new Country("Brazil", "BZ");

            brazil.GenerateNewIdentity();
            context.Countries.Add(brazil);

            ////
            //Customers

            //Cesar de la Torre
            var customer1 = CustomerFactory.CreateCustomer("Cesar", "De la Torre", "+34 1234567", "Microsoft", spain, new Address("Madrid", "28700", "Calle Club Deportivo 1", "Parque Empresarial La Finca, Edif. 1"));

            customer1.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer1);

            //Unai Zorrilla
            var customer2 = CustomerFactory.CreateCustomer("Unai", "Zorrilla", "+34 1234567", "Plain Concepts", spain, new Address("Madrid", "12345", "Calle Plain", "Barrio San Chinarro"));

            customer2.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer2);

            //Miguel Angel
            var customer3 = CustomerFactory.CreateCustomer("Miguel Angel", "Ramos", "+1 1234567", "Microsoft", us, new Address("Redmond", "12345", "One Microsoft Way", "Building X"));

            customer3.SetTheCountryReference(us.Id);
            context.Customers.Add(customer3);

            //Eric Evans
            var customer4 = CustomerFactory.CreateCustomer("Eric", "Evans", "+1 1234567", "Domain Language", us, new Address("City", "12345", "DDD Street", "Building X"));

            customer4.SetTheCountryReference(us.Id);
            context.Customers.Add(customer4);

            //César Castro
            var customer5 = CustomerFactory.CreateCustomer("César", "Castro", "+34 1234567", "Freelance", spain, new Address("Madrid", "12345", "Calle de Madrid", "Barrio de Madrid"));

            customer5.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer4);

            ////
            //Bank Accounts

            //Account 001
            var bankAccountNumber001 = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var newBankAccount001    = BankAccountFactory.CreateBankAccount(customer1, bankAccountNumber001);

            newBankAccount001.DepositMoney(System.Convert.ToDecimal(5000), "Initial Balance");
            context.BankAccounts.Add(newBankAccount001);

            //Account 002
            var bankAccountNumber002 = new BankAccountNumber("1111", "2222", "3333333333", "02");
            var newBankAccount002    = BankAccountFactory.CreateBankAccount(customer2, bankAccountNumber002);

            newBankAccount002.DepositMoney(System.Convert.ToDecimal(3000), "Initial Balance");
            context.BankAccounts.Add(newBankAccount002);

            //Account 003
            var bankAccountNumber003 = new BankAccountNumber("1111", "2222", "3333333333", "02");
            var newBankAccount003    = BankAccountFactory.CreateBankAccount(customer5, bankAccountNumber003);

            newBankAccount003.DepositMoney(System.Convert.ToDecimal(10000), "Initial Balance");
            context.BankAccounts.Add(newBankAccount003);

            context.SaveChanges();
        }
Example #19
0
        protected override void Seed(MainBcUnitOfWork context)
        {
            //NOTE: Each time you change the content of this method, ALL the records will be added to the database!!
            //If you change this method, it is better to delete de whole database first.

            ////Demo data

            //Countries
            var spain = new Country("Spain", "ES");

            spain.GenerateNewIdentity();
            context.Countries.Add(spain);

            var us = new Country("U.S.", "US");

            us.GenerateNewIdentity();
            context.Countries.Add(us);

            var uk = new Country("U.K.", "GB");

            uk.GenerateNewIdentity();
            context.Countries.Add(uk);

            var canada = new Country("Canada", "CA");

            canada.GenerateNewIdentity();
            context.Countries.Add(canada);

            var italy = new Country("Italy", "IT");

            italy.GenerateNewIdentity();
            context.Countries.Add(italy);

            var france = new Country("France", "FR");

            france.GenerateNewIdentity();
            context.Countries.Add(france);

            var argentina = new Country("Argentina", "AR");

            argentina.GenerateNewIdentity();
            context.Countries.Add(argentina);

            var russia = new Country("Russian Federation", "RUS");

            russia.GenerateNewIdentity();
            context.Countries.Add(russia);

            var israel = new Country("Israel", "IS");

            israel.GenerateNewIdentity();
            context.Countries.Add(israel);

            var brazil = new Country("Brazil", "BZ");

            brazil.GenerateNewIdentity();
            context.Countries.Add(brazil);

            ////
            //Customers

            //Cesar de la Torre
            var customer1 = CustomerFactory.CreateCustomer(
                "Cesar",
                "De la Torre",
                "+34 1234567",
                "Microsoft",
                spain,
                new Address("Madrid", "28700", "Calle Club Deportivo 1", "Parque Empresarial La Finca, Edif. 1"));

            customer1.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer1);

            //Unai Zorrilla
            var customer2 = CustomerFactory.CreateCustomer(
                "Unai",
                "Zorrilla",
                "+34 1234567",
                "Plain Concepts",
                spain,
                new Address("Madrid", "12345", "Calle Plain", "Barrio San Chinarro"));

            customer2.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer2);

            //Miguel Angel
            var customer3 = CustomerFactory.CreateCustomer(
                "Miguel Angel",
                "Ramos",
                "+1 1234567",
                "Microsoft",
                us,
                new Address("Redmond", "12345", "One Microsoft Way", "Building X"));

            customer3.SetTheCountryReference(us.Id);
            context.Customers.Add(customer3);

            //Eric Evans
            var customer4 = CustomerFactory.CreateCustomer(
                "Eric",
                "Evans",
                "+1 1234567",
                "Domain Language",
                us,
                new Address("City", "12345", "DDD Street", "Building X"));

            customer4.SetTheCountryReference(us.Id);
            context.Customers.Add(customer4);

            ////
            //Bank Accounts

            //Account 001
            var bankAccountNumber001 = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var newBankAccount001    = BankAccountFactory.CreateBankAccount(customer1, bankAccountNumber001);

            newBankAccount001.DepositMoney(Convert.ToDecimal(5000), "Initial Balance");
            context.BankAccounts.Add(newBankAccount001);

            //Account 002
            var bankAccountNumber002 = new BankAccountNumber("1111", "2222", "3333333333", "02");
            var newBankAccount002    = BankAccountFactory.CreateBankAccount(customer2, bankAccountNumber002);

            newBankAccount002.DepositMoney(Convert.ToDecimal(3000), "Initial Balance");
            context.BankAccounts.Add(newBankAccount002);
        }
        protected override void Seed(MainBCUnitOfWork unitOfWork)
        {
            /*
             * Countries agg
             */

            var spainCountry = new Country("Spain", "es-ES");

            spainCountry.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            var usaCountry = new Country("EEUU", "en-US");

            usaCountry.ChangeCurrentIdentity(new Guid("C3C82D06-6A07-41FB-B7EA-903EC456BFC5"));

            unitOfWork.Countries.Add(spainCountry);
            unitOfWork.Countries.Add(usaCountry);

            /*
             * Customers agg
             */

            var customerJhon = CustomerFactory.CreateCustomer("Jhon", "Jhon", "+34617", "company", spainCountry, new Address("Madrid", "280181", "Paseo de La finca", ""));

            customerJhon.ChangeCurrentIdentity(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45"));


            var customerMay = CustomerFactory.CreateCustomer("May", "Garcia", "+34617", "company", usaCountry, new Address("Seatle", "3332", "Alaskan Way", ""));

            customerMay.ChangeCurrentIdentity(new Guid("0CD6618A-9C8E-4D79-9C6B-4AA69CF18AE6"));


            unitOfWork.Customers.Add(customerJhon);
            unitOfWork.Customers.Add(customerMay);


            /*
             * Product agg
             */
            var book = new Book("The book title", "Any book description", "Krassis Press", "ABC");

            book.ChangeUnitPrice(40M);
            book.IncrementStock(2);

            book.ChangeCurrentIdentity(new Guid("44668EBF-7B54-4431-8D61-C1298DB50857"));

            var software = new Software("the new SO", "the software description", "XXXX0000--111");

            software.ChangeUnitPrice(100M);
            software.IncrementStock(3);
            software.ChangeCurrentIdentity(new Guid("D7E5C537-6A0C-4E19-B41E-3653F4998085"));

            unitOfWork.Products.Add(book);
            unitOfWork.Products.Add(software);

            /*
             * Orders agg
             */

            var orderA = OrderFactory.CreateOrder(customerJhon, "shipping name", "shipping city", "shipping address", "shipping zip code");

            orderA.ChangeCurrentIdentity(new Guid("3135513C-63FD-43E6-9697-6C6E5D8CE55B"));
            orderA.OrderDate = DateTime.Now;

            orderA.AddNewOrderLine(book.Id, 1, 40, 0);

            var orderB = OrderFactory.CreateOrder(customerMay, "shipping name", "shipping city", "shipping address", "shipping zip code");

            orderB.GenerateNewIdentity();
            orderB.OrderDate = DateTime.Now;

            orderB.AddNewOrderLine(software.Id, 3, 12, 0);

            unitOfWork.Orders.Add(orderA);
            unitOfWork.Orders.Add(orderB);

            /*
             * Bank Account agg
             */

            var         bankAccountNumberJhon = new BankAccountNumber("1111", "2222", "3333333333", "01");
            BankAccount bankAccountJhon       = BankAccountFactory.CreateBankAccount(customerJhon, bankAccountNumberJhon);

            bankAccountJhon.ChangeCurrentIdentity(new Guid("0343C0B0-7C40-444A-B044-B463F36A1A1F"));
            bankAccountJhon.DepositMoney(1000, "Open BankAccount");

            var         bankAccountNumberMay = new BankAccountNumber("4444", "5555", "3333333333", "02");
            BankAccount bankAccountMay       = BankAccountFactory.CreateBankAccount(customerMay, bankAccountNumberMay);

            bankAccountMay.GenerateNewIdentity();
            bankAccountJhon.DepositMoney(2000, "Open BankAccount");

            unitOfWork.BankAccounts.Add(bankAccountJhon);
            unitOfWork.BankAccounts.Add(bankAccountMay);
        }
Example #21
0
        public void PerformBankTransfer()
        {
            //Arrange

            //--> source bank account data

            var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC");
            var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02");
            var sourceCustomer          = new Customer();

            sourceCustomer.GenerateNewIdentity();

            var source = BankAccountFactory.CreateBankAccount(sourceCustomer, bankAccountNumberSource);

            source.ChangeCurrentIdentity(sourceId);
            source.DepositMoney(1000, "initial");

            var sourceBankAccountDTO = new BankAccountDTO()
            {
                Id = sourceId,
                BankAccountNumber = source.Iban
            };

            //--> target bank account data
            var targetCustomer = new Customer();

            targetCustomer.GenerateNewIdentity();
            var targetId = new Guid("8A091975-F783-4730-9E03-831E9A9435C1");
            var bankAccountNumberTarget = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var target = BankAccountFactory.CreateBankAccount(targetCustomer, bankAccountNumberTarget);

            target.ChangeCurrentIdentity(targetId);


            var targetBankAccountDTO = new BankAccountDTO()
            {
                Id = targetId,
                BankAccountNumber = target.Iban
            };

            var accounts = new List <BankAccount>()
            {
                source, target
            };

            var bankAccountRepository = new Mock <IBankAccountRepository>();

            bankAccountRepository
            .Setup(x => x.Get(It.IsAny <Guid>()))
            .Returns((Guid guid) => {
                return(accounts.Where(ba => ba.Id == guid).SingleOrDefault());
            });

            Mock <MainBCUnitOfWork> _mockContext = new Mock <MainBCUnitOfWork>();

            _mockContext.Setup(c => c.Commit());

            bankAccountRepository
            .Setup(x => x.UnitOfWork).Returns(_mockContext.Object);

            var customerRepository = new Mock <ICustomerRepository>();
            IBankTransferService             transferService = new BankTransferService();
            Mock <ILogger <BankAppService> > _mockLogger     = new Mock <ILogger <BankAppService> >();
            IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object);

            //Act
            bankingService.PerformBankTransfer(sourceBankAccountDTO, targetBankAccountDTO, 100M);

            //Assert
            Assert.Equal(source.Balance, 900);
            Assert.Equal(target.Balance, 100);
        }
        public void PerformBankTransfer()
        {
            //Arrange

            //--> source bank account data
            var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC");
            var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02");
            var sourceCustomer          = new Customer();

            sourceCustomer.GenerateNewIdentity();

            var source = BankAccountFactory.CreateBankAccount(sourceCustomer, bankAccountNumberSource);

            source.ChangeCurrentIdentity(sourceId);
            source.DepositMoney(1000, "initial");

            var sourceBankAccountDto = new BankAccountDto()
            {
                Id = sourceId,
                BankAccountNumber = source.Iban
            };

            //--> target bank account data
            var targetCustomer = new Customer();

            targetCustomer.GenerateNewIdentity();
            var targetId = new Guid("8A091975-F783-4730-9E03-831E9A9435C1");
            var bankAccountNumberTarget = new BankAccountNumber("1111", "2222", "3333333333", "01");
            var target = BankAccountFactory.CreateBankAccount(targetCustomer, bankAccountNumberTarget);

            target.ChangeCurrentIdentity(targetId);

            var targetBankAccountDto = new BankAccountDto()
            {
                Id = targetId,
                BankAccountNumber = target.Iban
            };

            var accounts = new List <BankAccount>()
            {
                source,
                target
            };

            var bankAccountRepository = new StubIBankAccountRepository();

            bankAccountRepository.GetGuid       = (guid) => { return(accounts.Where(ba => ba.Id == guid).SingleOrDefault()); };
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var unitOfWork = new StubIUnitOfWork();
                unitOfWork.Commit = () => { };

                return(unitOfWork);
            };

            var customerRepository = new StubICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            bankingService.PerformBankTransfer(sourceBankAccountDto, targetBankAccountDto, 100M);

            //Assert
            Assert.AreEqual(source.Balance, 900);
            Assert.AreEqual(target.Balance, 100);
        }