Esempio n. 1
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 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);
      }
        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);
        }