Exemplo n.º 1
0
        public async Task AddAndSaveTest()
        {
            var membershipCard1 = new MembershipCard()
            {
                Id = 1, CreatedAt = date1, MemberId = 1
            };
            var membershipCard2 = new MembershipCard()
            {
                Id = 2, CreatedAt = date2, MemberId = 2
            };
            var membershipCards = new List <MembershipCard> {
                membershipCard1, membershipCard2
            };

            var membershipCard3 = new MembershipCard()
            {
                Id = 2, CreatedAt = date3, MemberId = 2
            };

            var fakeMembershipCardRepositoryMock = new Mock <IMembershipCardRepository>();
            var fakeMemberRepositoryMock         = new Mock <IMemberRepository>();

            fakeMembershipCardRepositoryMock.Setup(x => x.Add(It.IsAny <MembershipCard>())).Callback <MembershipCard>(arg => membershipCards.Add(arg));

            var membershipCardService = new MembershipCardService(fakeMembershipCardRepositoryMock.Object, fakeMemberRepositoryMock.Object);

            await membershipCardService.AddAndSave(membershipCard3);


            Assert.Equal(3, membershipCards.Count);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,CreatedAt,MemberId")] MembershipCard membershipCard)
        {
            if (ModelState.IsValid)
            {
                await _membershipCardService.AddAndSave(membershipCard);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MemberId"] = new SelectList(await _membershipCardService.GetAllMembers(), "Id", "Email", membershipCard.MemberId);
            return(View(membershipCard));
        }