Exemplo n.º 1
0
        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));
        }
 private void AddNewCreditCart(RequestAddNewCreditCardCommand command, RequestAddNewCreditCardResponse response)
 {
     try
     {
         _wallet.AddNewCreditCart(AdapterCommandToDomain(command, response));
         _walletService.AddNewCreditCart(_wallet);
     }
     catch (Exception ex)
     {
         response.AddError($"Erro ao adicionar o cartão de crédito a carteira. Erro: {ex.Message}");
     }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void Should_Buy_Success_With_Creditcards()
        {
            var walletRepository     = Substitute.For <IWalletRepository>();
            var creditCardRepository = Substitute.For <ICreditCardRepository>();

            var user = GetUser();

            var wallet = new Wallet(user)
            {
                CreditCards = new List <CreditCard>()
            };

            wallet.AddNewCreditCart(new CreditCard(user, CreditCardType.Visa, 4539012657749922, "MARIA FERNANDES ALVES", "01/18", 3, "669", 400));
            wallet.AddNewCreditCart(new CreditCard(user, CreditCardType.AmericanExpress, 344241982621208, "MARIA FERNANDES ALVES", "05/08", 15, "949", 100));

            walletRepository.UpdateUserCreditLimit(wallet);

            var walletService = new WalletService(walletRepository, creditCardRepository);

            walletService.Buy(wallet);

            walletRepository.Received().UpdateUserCreditLimit(Arg.Any <Wallet>());
        }