public void AdaptBankAccountToBankAccountDTO()
        {
            //Arrange
            var customer = CustomerFactory.CreateCustomer("jhon", "el rojo", Guid.NewGuid(), new Address("", "", "", ""));
            customer.Id = IdentityGenerator.NewSequentialGuid();

            BankAccount account = new BankAccount();
            account.Id = IdentityGenerator.NewSequentialGuid();
            account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02");
            account.SetCustomer(customer);
            account.DepositMoney(1000, "reason");
            account.Lock();

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var bankAccountDTO = adapter.Adapt<BankAccount, BankAccountDTO>(account);

            //Assert
            Assert.AreEqual(account.Id, bankAccountDTO.Id);
            Assert.AreEqual(account.Iban, bankAccountDTO.BankAccountNumber);
            Assert.AreEqual(account.Balance, bankAccountDTO.Balance);
            Assert.AreEqual(account.Customer.FirstName, bankAccountDTO.CustomerFirstName);
            Assert.AreEqual(account.Customer.LastName, bankAccountDTO.CustomerLastName);
            Assert.AreEqual(account.Locked, bankAccountDTO.Locked);
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Domain.MainBoundedContext.BankingModule.Services.IBankTransferService"/>
        /// </summary>
        /// <param name="amount"> <see cref="Microsoft.Samples.NLayerApp.Domain.MainBoundedContext.BankingModule.Services.IBankTransferService"/></param>
        /// <param name="originAccount"> <see cref="Microsoft.Samples.NLayerApp.Domain.MainBoundedContext.BankingModule.Services.IBankTransferService"/></param>
        /// <param name="destinationAccount"> <see cref="Microsoft.Samples.NLayerApp.Domain.MainBoundedContext.BankingModule.Services.IBankTransferService"/></param>
        public void PerformTransfer(decimal amount, BankAccount originAccount, BankAccount destinationAccount)
        {
            if (originAccount != null && destinationAccount != null)
            {
                if (originAccount.BankAccountNumber == destinationAccount.BankAccountNumber) // if transfer in same bank account
                    throw new InvalidOperationException(Messages.exception_CannotTransferMoneyWhenFromIsTheSameAsTo);

                // Check if customer has required credit and if the BankAccount is not locked
                if (originAccount.CanBeWithdrawed(amount))
                {
                    //Domain Logic
                    //Process: Perform transfer operations to in-memory Domain-Model objects        
                    // 1.- Charge money to origin acc
                    // 2.- Credit money to destination acc

                    //Charge money
                    originAccount.WithdrawMoney(amount, string.Format(Messages.messages_TransactionFromMessage, destinationAccount.Id));

                    //Credit money
                    destinationAccount.DepositMoney(amount, string.Format(Messages.messages_TransactionToMessage, originAccount.Id));
                }
                else
                    throw new InvalidOperationException(Messages.exception_BankAccountCannotWithdraw);
            }
        }
      public void AdaptBankAccountToBankAccountDto()
      {
         //Arrange
         var country = new Country("Spain", "es-ES");
         country.GenerateNewIdentity();

         var customer = CustomerFactory.CreateCustomer(
            "jhon",
            "el rojo",
            "+3441",
            "company",
            country,
            new Address("", "", "", ""));
         customer.GenerateNewIdentity();

         var account = new BankAccount();
         account.GenerateNewIdentity();
         account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02");
         account.SetCustomerOwnerOfThisBankAccount(customer);
         account.DepositMoney(1000, "reason");
         account.Lock();

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var bankAccountDto = adapter.Adapt<BankAccount, BankAccountDto>(account);

         //Assert
         Assert.AreEqual(account.Id, bankAccountDto.Id);
         Assert.AreEqual(account.Iban, bankAccountDto.BankAccountNumber);
         Assert.AreEqual(account.Balance, bankAccountDto.Balance);
         Assert.AreEqual(account.Customer.FirstName, bankAccountDto.CustomerFirstName);
         Assert.AreEqual(account.Customer.LastName, bankAccountDto.CustomerLastName);
         Assert.AreEqual(account.Locked, bankAccountDto.Locked);
      }
      public void AdaptEnumerableBankAccountToListBankAccountListDto()
      {
         //Arrange

         var country = new Country("spain", "es-ES");
         country.GenerateNewIdentity();

         var customer = CustomerFactory.CreateCustomer(
            "jhon",
            "el rojo",
            "+341232",
            "company",
            country,
            new Address("", "", "", ""));
         customer.GenerateNewIdentity();

         var account = new BankAccount();
         account.GenerateNewIdentity();
         account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02");
         account.SetCustomerOwnerOfThisBankAccount(customer);
         account.DepositMoney(1000, "reason");
         var accounts = new List<BankAccount>()
         {
            account
         };

         //Act
         var adapter = TypeAdapterFactory.CreateAdapter();
         var bankAccountsDto = adapter.Adapt<IEnumerable<BankAccount>, List<BankAccountDto>>(accounts);

         //Assert
         Assert.IsNotNull(bankAccountsDto);
         Assert.IsTrue(bankAccountsDto.Count == 1);

         Assert.AreEqual(account.Id, bankAccountsDto[0].Id);
         Assert.AreEqual(account.Iban, bankAccountsDto[0].BankAccountNumber);
         Assert.AreEqual(account.Balance, bankAccountsDto[0].Balance);
         Assert.AreEqual(account.Customer.FirstName, bankAccountsDto[0].CustomerFirstName);
         Assert.AreEqual(account.Customer.LastName, bankAccountsDto[0].CustomerLastName);
      }
        public void AdaptEnumerableBankAccountToListBankAccountListDTO()
        {
            //Arrange
            var customer = CustomerFactory.CreateCustomer("jhon", "el rojo", Guid.NewGuid(), new Address("", "", "", ""));
            customer.Id = IdentityGenerator.NewSequentialGuid();

            BankAccount account = new BankAccount();
            account.Id = IdentityGenerator.NewSequentialGuid();
            account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02");
            account.SetCustomer(customer);
            account.DepositMoney(1000, "reason");
            var accounts = new List<BankAccount>() { account };

            //Act
            ITypeAdapter adapter = PrepareTypeAdapter();
            var bankAccountsDTO = adapter.Adapt<IEnumerable<BankAccount>, List<BankAccountDTO>>(accounts);

            //Assert
            Assert.IsNotNull(bankAccountsDTO);
            Assert.IsTrue(bankAccountsDTO.Count == 1);

            Assert.AreEqual(account.Id, bankAccountsDTO[0].Id);
            Assert.AreEqual(account.Iban, bankAccountsDTO[0].BankAccountNumber);
            Assert.AreEqual(account.Balance, bankAccountsDTO[0].Balance);
            Assert.AreEqual(account.Customer.FirstName, bankAccountsDTO[0].CustomerFirstName);
            Assert.AreEqual(account.Customer.LastName, bankAccountsDTO[0].CustomerLastName);
        }