コード例 #1
0
        public void LockBankAccountReturnFalseIfBankAccountNotExist()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };
            bankAccountRepository.GetGuid = (guid) =>
            {
                return null;
            };

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

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsFalse(result);
        }
コード例 #2
0
        public void FindBankAccountsReturnAllItems()
        {
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetAll = () =>
            {
                var customer = new Customer();
                customer.GenerateNewIdentity();

                var bankAccount = new BankAccount()
                {
                    BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"),
                };
                bankAccount.SetCustomerOwnerOfThisBankAccount(customer);
                bankAccount.GenerateNewIdentity();

                var accounts = new List <BankAccount>()
                {
                    bankAccount
                };

                return(accounts);
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccounts();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }
コード例 #3
0
        public void LockBankAccountReturnFalseIfIdentifierIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = guid =>
            {
                if (guid == Guid.Empty)
                {
                    return(null);
                }
                else
                {
                    return new BankAccount {
                    }
                };
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

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

            //Act
            var result = bankingService.LockBankAccount(Guid.Empty);

            //Assert
            Assert.IsFalse(result);
        }
コード例 #4
0
        public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = guid =>
            {
                if (guid == Guid.Empty)
                {
                    return(null);
                }
                else
                {
                    return new BankAccount {
                    }
                };
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.Empty);


            //Assert
            Assert.IsNull(result);
        }
コード例 #5
0
        public void LockBankAccountReturnFalseIfBankAccountNotExist()
        {
            //Arrange
            SICustomerRepository    customerRepository    = new SICustomerRepository();
            IBankTransferService    transferService       = new BankTransferService();
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };
            bankAccountRepository.GetGuid = (guid) =>
            {
                return(null);
            };

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

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsFalse(result);
        }
コード例 #6
0
        public void ConstructorThrowExceptionIfBankAccountRepositoryDependencyIsNull()
        {
            //Arrange
            SICustomerRepository    customerRepository     = new SICustomerRepository();
            SIBankAccountRepository bankAcccountRepository = null;
            IBankTransferService    transferService        = new BankTransferService();

            //Act
            IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService);
        }
コード例 #7
0
        public void AddBankAccountThrowArgumentNullExceptionWhenBankAccountDTOIsNull()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository    customerRepository    = new SICustomerRepository();
            IBankTransferService    transferService       = new BankTransferService();

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

            //Act
            var result = bankingService.AddBankAccount(null);

            //Assert

            Assert.IsNull(result);
        }
コード例 #8
0
        public void AddBankAccountReturnDTOWhenSaveSucceed()
        {
            //Arrange
            IBankTransferService transferService = new BankTransferService();

            SICustomerRepository customerRepository = new SICustomerRepository();

            customerRepository.GetGuid = (guid) =>
            {
                var customer = new Customer()
                {
                    FirstName = "Jhon",
                    LastName  = "El rojo"
                };

                customer.ChangeCurrentIdentity(guid);

                return(customer);
            };

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.AddBankAccount = (ba) => { };
            bankAccountRepository.UnitOfWorkGet  = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };


            var dto = new BankAccountDTO()
            {
                CustomerId        = Guid.NewGuid(),
                BankAccountNumber = "BA"
            };

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

            //Act
            var result = bankingService.AddBankAccount(dto);

            //Assert
            Assert.IsNotNull(result);
        }
コード例 #9
0
        public void AddBankAccountReturnNullWhenCustomerIdIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository    customerRepository    = new SICustomerRepository();
            IBankTransferService    transferService       = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.Empty
            };

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

            //Act
            var result = bankingService.AddBankAccount(dto);
        }
コード例 #10
0
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = (guid) =>
            {
                var bActivity1 = new BankAccountActivity()
                {
                    Date = DateTime.Now, Amount = 1000
                };
                bActivity1.GenerateNewIdentity();

                var bActivity2 = new BankAccountActivity()
                {
                    Date = DateTime.Now, Amount = 1000
                };
                bActivity2.GenerateNewIdentity();

                var bankAccount = new BankAccount()
                {
                    BankAccountActivity = new HashSet <BankAccountActivity>()
                    {
                        bActivity1, bActivity2
                    }
                };
                bankAccount.GenerateNewIdentity();

                return(bankAccount);
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #11
0
        public void AddBankAccountReturnDTOWhenSaveSucceed()
        {
            //Arrange
            IBankTransferService transferService = new BankTransferService();

            ITypeAdapter adapter = PrepareTypeAdapter();

            SICustomerRepository customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) =>
            {
                return new Customer()
                {
                    Id = guid,
                    FirstName = "Jhon",
                    LastName = "El rojo"
                };
            };

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.AddBankAccount = (ba) => { };
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid(),
                BankAccountNumber = "BA"
            };

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

            //Act
            var result = bankingService.AddBankAccount(dto);

            //Assert
            Assert.IsNotNull(result);
        }
コード例 #12
0
        public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository    customerRepository    = new SICustomerRepository();

            customerRepository.GetGuid = (guid) => { return(null); };

            IBankTransferService transferService = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid()
            };

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

            //Act
            bankingService.AddBankAccount(dto);
        }
コード例 #13
0
        public void FindBankAccountActivitiesReturnNullWhenBankAccountNotExists()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.GetGuid = (guid) =>
            {
                return(null);
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNull(result);
        }
コード例 #14
0
        public void LockBankAccountReturnFalseIfIdentifierIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = guid =>
            {
                if (guid == Guid.Empty)
                    return null;
                else
                    return new BankAccount { };
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

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

            //Act
            var result = bankingService.LockBankAccount(Guid.Empty);

            //Assert
            Assert.IsFalse(result);
        }
コード例 #15
0
        public void LockBankAccountReturnTrueIfBankAccountIsLocked()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService    = new BankTransferService();

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return(uow);
            };

            bankAccountRepository.GetGuid = (guid) =>
            {
                var customer = new Customer();
                customer.GenerateNewIdentity();

                var bankAccount = new BankAccount();
                bankAccount.GenerateNewIdentity();

                bankAccount.SetCustomerOwnerOfThisBankAccount(customer);

                return(bankAccount);
            };

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

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsTrue(result);
        }
コード例 #16
0
        public void AddBankAccountReturnNullWhenCustomerIdIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
          
            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.Empty
            };

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

            //Act
            var result = bankingService.AddBankAccount(dto);
        }
コード例 #17
0
        public void AddBankAccountReturnNullWhenBankAccountDTOIsNull()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

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

            //Act
            var result = bankingService.AddBankAccount(null);

            //Assert

            Assert.IsNull(result);
        }
コード例 #18
0
        public void AddBankAccountThrowArgumentNullExceptionWhenBankAccountDTOIsNull()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            
            IBankAppService bankingService = new BankAppService(bankAccountRepository, customerRepository, transferService);

            //Act
            var result = bankingService.AddBankAccount(null);

            //Assert

            Assert.IsNull(result);
        }
コード例 #19
0
        public void PerformBankTransfer()
        {
            //Arrange
            var sourceId = new Guid("3481009C-A037-49DB-AE05-44FF6DB67DEC");
            var bankAccountNumberSource = new BankAccountNumber("4444", "5555", "3333333333", "02");

            var source = BankAccountFactory.CreateBankAccount(Guid.NewGuid(), bankAccountNumberSource);
            source.Id = sourceId;
            source.DepositMoney(1000,"initial");

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

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

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

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

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

                return unitOfWork;
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

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

            //Act

            bankingService.PerformBankTransfer(sourceBankAccountDTO, targetBankAccountDTO, 100M);
        }
コード例 #20
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
            };


            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();

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

                return(unitOfWork);
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            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);
        }
コード例 #21
0
        public void LockBankAccountReturnTrueIfBankAccountIsLocked()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            bankAccountRepository.GetGuid = (guid) =>
            {
                return new BankAccount() { Id = Guid.NewGuid(), CustomerId = Guid.NewGuid() };
            };

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

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsTrue(result);
        }
コード例 #22
0
        public void LockBankAccountReturnFalseIfIdentifierIsEmpty()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

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

            //Act
            var result = bankingService.LockBankAccount(Guid.Empty);

            //Assert
            Assert.IsFalse(result);
        }
コード例 #23
0
        public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) => { return null; };

            IBankTransferService transferService = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid()
            };

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

            //Act
            bankingService.AddBankAccount(dto);
        }
コード例 #24
0
        public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = guid =>
            {
                if (guid == Guid.Empty)
                    return null;
                else
                    return new BankAccount { };
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.Empty);


            //Assert
            Assert.IsNull(result);
        }
コード例 #25
0
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = (guid) =>
            {
                var bActivity1 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 };
                bActivity1.GenerateNewIdentity();

                var bActivity2 = new BankAccountActivity() { Date = DateTime.Now, Amount = 1000 };
                bActivity2.GenerateNewIdentity();

                var bankAccount = new BankAccount()
                {
                    BankAccountActivity = new HashSet<BankAccountActivity>(){ bActivity1,bActivity2}
                };
                bankAccount.GenerateNewIdentity();

                return bankAccount;
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #26
0
        public void FindBankAccountsReturnAllItems()
        {
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetAll = () =>
            {
                var customer = new Customer();
                customer.GenerateNewIdentity();

                var bankAccount = new BankAccount()
                {
                    BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"),
                };
                bankAccount.SetCustomerOwnerOfThisBankAccount(customer);
                bankAccount.GenerateNewIdentity();

                var accounts = new List<BankAccount>(){ bankAccount };

                return accounts;

            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccounts();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);

        }
コード例 #27
0
        public void AddBankAccountReturnNullWhenCustomerNotExist()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            customerRepository.GetGuid = (guid) => { return null; };

            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid()
            };

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

            //Act
            var result = bankingService.AddBankAccount(dto);

            //Assert

            Assert.IsNull(result);
        }
コード例 #28
0
        public void FindBankAccountActivitiesReturnNullWhenBankAccountNotExists()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = (guid) =>
            {
                return null;
            };
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());


            //Assert
            Assert.IsNull(result);
        }
コード例 #29
0
        public void ConstructorThrowExceptionIfBankTransferServiceDependencyIsNull()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIBankAccountRepository bankAcccountRepository = new SIBankAccountRepository();
            IBankTransferService transferService = null;
            ITypeAdapter adapter = PrepareTypeAdapter();

            //Act
            IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService, adapter);
        }
コード例 #30
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 };


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

                return unitOfWork;
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            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);
        }
コード例 #31
0
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetGuid = (guid) =>
            {
                var bankAccount = new BankAccount()
                {
                    Id = Guid.NewGuid(),
                    BankAccountActivity = new HashSet<BankAccountActivity>()
                    {
                        new BankAccountActivity(){Id = Guid.NewGuid(),Date = DateTime.Now,Amount = 1000},
                        new BankAccountActivity(){Id = Guid.NewGuid(),Date = DateTime.Now,Amount = 1000},
                    }
                };

                return bankAccount;
            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());

            //Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 2);
        }
コード例 #32
0
        public void ConstructorThrowExceptionIfCustomerRepositoryDependencyIsNull()
        {
            //Arrange
            SICustomerRepository customerRepository = null;
            SIBankAccountRepository bankAcccountRepository = new SIBankAccountRepository();
            IBankTransferService transferService = new BankTransferService();
            

            //Act
            IBankAppService bankingService = new BankAppService(bankAcccountRepository, customerRepository, transferService);

        }
コード例 #33
0
        public void FindBankAccountActivitiesReturnNullWhenBankAccountIdIsEmpty()
        {
            //Arrange

            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = new SITypeAdapter();

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

            //Act
            var result = bankingService.FindBankAccountActivities(Guid.Empty);

            //Assert
            Assert.IsNull(result);
        }
コード例 #34
0
        public void LockBankAccountReturnTrueIfBankAccountIsLocked()
        {
            //Arrange
            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.UnitOfWorkGet = () =>
            {
                var uow = new SIUnitOfWork();
                uow.Commit = () => { };

                return uow;
            };

            bankAccountRepository.GetGuid = (guid) =>
            {
                var customer = new Customer();
                customer.GenerateNewIdentity();

                var bankAccount = new BankAccount();
                bankAccount.GenerateNewIdentity();

                bankAccount.SetCustomerOwnerOfThisBankAccount(customer);

                return bankAccount;
            };

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

            //Act
            var result = bankingService.LockBankAccount(Guid.NewGuid());

            //Assert
            Assert.IsTrue(result);
        }
コード例 #35
0
        public void FindBankAccountsReturnAllItems()
        {
            SIBankAccountRepository bankAccountRepository = new SIBankAccountRepository();
            bankAccountRepository.GetAll = ()=>
            {
                var accounts = new List<BankAccount>()
                {
                    new BankAccount()
                    {
                        Id = Guid.NewGuid(),
                        BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"),
                        CustomerId =Guid.NewGuid()
                    }
                };

                return accounts;

            };

            SICustomerRepository customerRepository = new SICustomerRepository();
            IBankTransferService transferService = new BankTransferService();
            ITypeAdapter adapter = PrepareTypeAdapter();

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

            //Act
            var result = bankingService.FindBankAccounts();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count == 1);
        }