Ejemplo n.º 1
0
        public void AdaptEnumerableBankActivityToListBankActivityDTO()
        {
            //Arrange
            BankAccountActivity activity = new BankAccountActivity();

            activity.GenerateNewIdentity();
            activity.Date   = DateTime.Now;
            activity.Amount = 1000;
            activity.ActivityDescription = "transfer...";

            IEnumerable <BankAccountActivity> activities = new List <BankAccountActivity>()
            {
                activity
            };

            //Act
            ITypeAdapter adapter       = TypeAdapterFactory.CreateAdapter();
            var          activitiesDTO = adapter.Adapt <IEnumerable <BankAccountActivity>, List <BankActivityDTO> >(activities);

            //Assert
            Assert.NotNull(activitiesDTO);
            Assert.True(activitiesDTO.Count() == 1);

            Assert.Equal(activity.Date, activitiesDTO[0].Date);
            Assert.Equal(activity.Amount, activitiesDTO[0].Amount);
            Assert.Equal(activity.ActivityDescription, activitiesDTO[0].ActivityDescription);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// WithdrawMoney operation over this bankaccount
        /// </summary>
        /// <param name="amount">The amount of money for this withdraw operation</param>
        public void WithdrawMoney(decimal amount, string reason)
        {
            //if ( amount <= 0 )  throw new ArgumentException(Messages.exception_BankAccountInvalidWithdrawAmount);

            //WithdrawMoney is a term of our Ubiquitous Language. Means deducting money to this account
            if (CanBeWithdrawed(amount))
            {
                checked
                {
                    this.Balance -= amount;

                    //anotate activity
                    var activity = new BankAccountActivity()
                    {
                        Date   = DateTime.Now,
                        Amount = -amount,
                        ActivityDescription = reason,
                        BankAccountId       = Id
                    };
                    activity.GenerateNewIdentity();

                    this.BankAccountActivity.Add(activity);
                }
            }
            //else
            //    throw new InvalidOperationException(Messages.exception_BankAccountCannotWithdraw);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deposit momey into this bank account
        /// </summary>
        /// <param name="amount">the amount of money to deposit </param>
        public void DepositMoney(decimal amount, string reason)
        {
            //if (amount < 0) throw new ArgumentException(Messages.exception_BankAccountInvalidWithdrawAmount);

            //DepositMoney is a term of our Ubiquitous Language. Means adding money to this account
            if (!this.Locked)
            {
                //set balance
                checked
                {
                    Balance += amount;

                    //anotate activity
                    var activity = new BankAccountActivity()
                    {
                        Date   = DateTime.UtcNow,
                        Amount = amount,
                        ActivityDescription = reason,
                        BankAccountId       = Id
                    };
                    activity.GenerateNewIdentity();

                    this.BankAccountActivity.Add(activity);
                }
            }
            //else
            //    throw new InvalidOperationException(Messages.exception_BankAccountCannotDeposit);
        }
Ejemplo n.º 4
0
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            var bankAccountRepository = new StubIBankAccountRepository();

            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);
            };

            var customerRepository = new StubICustomerRepository();
            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);
        }
Ejemplo n.º 5
0
        public void FindBankAccountActivitiesReturnAllItems()
        {
            //Arrange
            var bankAccountRepository = new Mock <IBankAccountRepository>();

            bankAccountRepository
            .Setup(x => x.Get(It.IsAny <Guid>()))
            .Returns((Guid 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);
            });

            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
            var result = bankingService.FindBankAccountActivities(Guid.NewGuid());

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 2);
        }
Ejemplo n.º 6
0
        public void AdaptBankActivityToBankActivityDto()
        {
            //Arrange
            var activity = new BankAccountActivity();

            activity.GenerateNewIdentity();
            activity.Date   = DateTime.Now;
            activity.Amount = 1000;
            activity.ActivityDescription = "transfer...";

            //Act
            var adapter     = TypeAdapterFactory.CreateAdapter();
            var activityDto = adapter.Adapt <BankAccountActivity, BankActivityDto>(activity);

            //Assert
            Assert.AreEqual(activity.Date, activityDto.Date);
            Assert.AreEqual(activity.Amount, activityDto.Amount);
            Assert.AreEqual(activity.ActivityDescription, activityDto.ActivityDescription);
        }