public void AdaptEnumerableBankActivityToListBankActivityDto() { //Arrange var activity = new BankAccountActivity(); activity.GenerateNewIdentity(); activity.Date = DateTime.Now; activity.Amount = 1000; activity.ActivityDescription = "transfer..."; IEnumerable<BankAccountActivity> activities = new List<BankAccountActivity>() { activity }; //Act var adapter = TypeAdapterFactory.CreateAdapter(); var activitiesDto = adapter.Adapt<IEnumerable<BankAccountActivity>, List<BankActivityDto>>(activities); //Assert Assert.IsNotNull(activitiesDto); Assert.IsTrue(activitiesDto.Count() == 1); Assert.AreEqual(activity.Date, activitiesDto[0].Date); Assert.AreEqual(activity.Amount, activitiesDto[0].Amount); Assert.AreEqual(activity.ActivityDescription, activitiesDto[0].ActivityDescription); }
/// <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.UtcNow, Amount = -amount, ActivityDescription = reason, BankAccountId = Id }; activity.GenerateNewIdentity(); this.BankAccountActivity.Add(activity); } } else { throw new InvalidOperationException(Messages.exception_BankAccountCannotWithdraw); } }
/// <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); } }
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); }
public void AdaptBankActivityToBankActivityDTO() { //Arrange BankAccountActivity activity = new BankAccountActivity(); activity.Id = IdentityGenerator.NewSequentialGuid(); activity.Date = DateTime.Now; activity.Amount = 1000; activity.ActivityDescription = "transfer..."; //Act ITypeAdapter adapter = PrepareTypeAdapter(); 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); }
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); }
public void AdaptEnumerableBankActivityToListBankActivityDTO() { //Arrange BankAccountActivity activity = new BankAccountActivity(); activity.Id = IdentityGenerator.NewSequentialGuid(); activity.Date = DateTime.Now; activity.Amount = 1000; activity.ActivityDescription = "transfer..."; IEnumerable<BankAccountActivity> activities = new List<BankAccountActivity>() { activity }; //Act ITypeAdapter adapter = PrepareTypeAdapter(); var activitiesDTO = adapter.Adapt<IEnumerable<BankAccountActivity>, List<BankActivityDTO>>(activities); //Assert Assert.IsNotNull(activitiesDTO); Assert.IsTrue(activitiesDTO.Count()==1); Assert.AreEqual(activity.Date, activitiesDTO[0].Date); Assert.AreEqual(activity.Amount, activitiesDTO[0].Amount); Assert.AreEqual(activity.ActivityDescription, activitiesDTO[0].ActivityDescription); }