Ejemplo n.º 1
0
        public async Task <ActionResult> AddCreditCard(CreditCardViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                await CardService.AddAsync(user, model.CreditCard);

                // TempData.Add("flash", new FlashSuccessViewModel("Your credit card has been saved successfully."));

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task CardsService_AddAsync_AddsModel()
        {
            //Arrange
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(x => x.CardRepository.AddAsync(It.IsAny <Card>()));
            ICardService cardService = new CardService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());
            var          card        = new CardModel {
                Id = 100, Created = DateTime.Today
            };

            //Act
            await cardService.AddAsync(card);

            //Assert
            mockUnitOfWork.Verify(x => x.CardRepository.AddAsync(It.Is <Card>(c => c.Created == card.Created && c.Id == card.Id)), Times.Once);
            mockUnitOfWork.Verify(x => x.SaveAsync(), Times.Once);
        }