public void Should_CannotMakeAPurchase_When_WalletNotContainsAnyCreditCard() { // Arrange var wallet = new Wallet(UserId); // Act Assert.Throws <InvalidOperationException>(() => wallet.Buy(500)); }
public void Cannot_MakeAPurchase_When_InsuficientAvailableCreditLimit() { // Arrange var wallet = new Wallet(UserId); var creditCard = new CreditCard(Guid.NewGuid(), "Wellington", 987654321, 789, 500, DateTime.Now.AddDays(60), DateTime.Now.AddYears(1)); wallet.AddCreditCard(creditCard); // Act and Assert Assert.Throws <InvalidOperationException>(() => wallet.Buy(673)); }
private void RequestBuy(RequestCreditCardBuyCommand command, RequestCreditCardBuyResponse response) { try { _wallet.Buy(command.AmountValue); _walletService.Buy(_wallet); } catch (Exception ex) { response.AddError($"Erro ao realizar a compra. {ex.Message}"); } }
public void Buy_Fail_Without_CreditCards() { var user = GetUser(); var wallet = new Wallet(user); wallet.AddNewCreditCart(new CreditCard(user, CreditCardType.Visa, 4539012657749922, "MELISSA DAVIDSON", "01/18", 15, "669", 1000)); wallet.AddNewCreditCart(new CreditCard(user, CreditCardType.AmericanExpress, 344241982621208, "MELISSA DAVIDSON", "05/08", 4, "949", 100)); wallet.AddNewCreditCart(new CreditCard(user, CreditCardType.Visa, 4532692653021082, "MELISSA DAVIDSON", "10/19", 4, "647", 100)); Assert.Throws <InvalidOperationException>(() => wallet.Buy(1300)); }
public void BuyRandomIngredient() { if (allLocketIngredients > 0 && Wallet.passiveMoney >= GetIngredientCost()) { Wallet.Buy(GetIngredientCost()); _randomPurchasePanel.SetActive(true); IngredientCountRender(); _ingredientCostText.text = GetIngredientCost().ToString(); } else { // no money } }
public void Should_MakeAPurchase_With_MinimumLimitCreditCard() { // Arrange var wallet = new Wallet(UserId); var firstCreditCard = new CreditCard(Guid.NewGuid(), "Katia", 543216789, 432, 500, DateTime.Now.AddDays(30), DateTime.Now.AddYears(1)); var minimumLimitCreditCard = new CreditCard(Guid.NewGuid(), "Wellington", 987654321, 789, 350, DateTime.Now.AddDays(30), DateTime.Now.AddYears(1)); wallet.AddCreditCard(firstCreditCard); wallet.AddCreditCard(minimumLimitCreditCard); wallet.ChangeWalletLimit(wallet.CreditCards.Sum(a => a.CreditLimit)); // Act wallet.Buy(175); // Assert Assert.Equal(175, wallet.CreditCards.First(a => a.Number == minimumLimitCreditCard.Number).AvailableCredit); Assert.Equal(675, wallet.AvailableCreditCardsLimit); }
public void Should_MakeAPurchase_With_MultipleCreditCardsAndSimilarDueDates() { // Arrange var wallet = new Wallet(UserId); var firstCreditCard = new CreditCard(Guid.NewGuid(), "Wellington", 987654321, 789, 500, DateTime.Now.AddDays(60), DateTime.Now.AddYears(1)); var secondCreditCard = new CreditCard(Guid.NewGuid(), "Katia", 123456789, 123, 1000, DateTime.Now.AddDays(60), DateTime.Now.AddYears(1)); wallet.AddCreditCard(firstCreditCard); wallet.AddCreditCard(secondCreditCard); wallet.ChangeWalletLimit(wallet.CreditCards.Sum(a => a.CreditLimit)); // Act wallet.Buy(1450); // Assert Assert.Equal(0, wallet.CreditCards.First(card => card.Number == firstCreditCard.Number).AvailableCredit); Assert.Equal(50, wallet.CreditCards.First(card => card.Number == secondCreditCard.Number).AvailableCredit); Assert.Equal(50, wallet.AvailableCreditCardsLimit); }
public void Should_MakeAPurchase_With_HigherDueDateCreditCard() { // Arrange var wallet = new Wallet(UserId); var higherDueDateCreditCard = new CreditCard(Guid.NewGuid(), "Katia", 987654321, 789, 500, DateTime.Now.AddDays(60), DateTime.Now.AddYears(1)); var anotherCreditCard = new CreditCard(Guid.NewGuid(), "Wellington", 123456789, 123, 1000, DateTime.Now.AddDays(30), DateTime.Now.AddYears(1)); wallet.AddCreditCard(higherDueDateCreditCard); wallet.AddCreditCard(anotherCreditCard); wallet.ChangeWalletLimit(wallet.CreditCards.Sum(a => a.CreditLimit)); // Act wallet.Buy(300); // Assert var selectedCreditCard = wallet.CreditCards.First(a => a.Number == higherDueDateCreditCard.Number); Assert.Equal(200, selectedCreditCard.AvailableCredit); Assert.Equal(1200, wallet.AvailableCreditCardsLimit); }
public void Buy_Success_With_CreditCard_MoreThanOneCard() { var user = GetUser(); var vidaCreditCard = new CreditCard(user, CreditCardType.Visa, 4539012657749922, "MELISSA DAVIDSON", "01/18", 15, "669", 1000); var americanCreditCard = new CreditCard(user, CreditCardType.AmericanExpress, 344241982621208, "MELISSA DAVIDSON", "05/08", 4, "949", 100); var masterCreditCard = new CreditCard(user, CreditCardType.Visa, 4532692653021082, "MELISSA DAVIDSON", "10/19", 4, "647", 250); var wallet = new Wallet(user); wallet.AddNewCreditCart(vidaCreditCard); wallet.AddNewCreditCart(americanCreditCard); wallet.AddNewCreditCart(masterCreditCard); wallet.Buy(1150); Assert.Equal(0, wallet.CreditCards.First(x => x.CreditCardNumber == 4539012657749922 && x.CreditCardType == CreditCardType.Visa).CreditLimit); Assert.Equal(0, wallet.CreditCards.First(x => x.CreditCardNumber == 344241982621208 && x.CreditCardType == CreditCardType.AmericanExpress).CreditLimit); Assert.Equal(200, wallet.CreditCards.First(x => x.CreditCardNumber == 4532692653021082 && x.CreditCardType == CreditCardType.Visa).CreditLimit); Assert.Equal(200, wallet.MaximumCreditLimit); }