示例#1
0
        public void AddItem(int eventId, string userId)
        {
            var eventCartItem = _eventOrganizerDbContext.EventCartItems.SingleOrDefault
                                    (s => s.EventId == eventId && s.UserId == userId);

            if (eventCartItem == null)
            {
                eventCartItem = new EventCartItem {
                    EventId = eventId, UserId = userId
                };
                _eventOrganizerDbContext.EventCartItems.Add(eventCartItem);
            }

            _eventOrganizerDbContext.SaveChanges();
        }
        public void ListViewTest()
        {
            var userManager           = GetUserManagerMock();
            var eventService          = GetEventServiceMock();
            var eventCartItemsService = GetEventCartItemsServiceMock();

            var eventCartItemsController = new EventCartItemsController(userManager.Object, eventService.Object, eventCartItemsService.Object);

            userManager.Setup(item => item.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(TestObjects.User1.Id);

            var cart = new EventCartItem[]
            {
                new EventCartItem()
                {
                    Id      = 1,
                    UserId  = "1",
                    EventId = 1
                }
            };

            eventCartItemsService.Setup(item => item.GetEventCartItems(It.IsAny <string>()))
            .Returns(cart);
            eventService.Setup(item => item.GetEventById(It.IsAny <int>()))
            .Returns(TestObjects.Event1);
            var result = eventCartItemsController.List();
            var eCIVW  = new EventCartItemsViewModel()
            {
                EventCartItems = new List <Event>()
                {
                    TestObjects.Event1
                }
            };
            var expected = eCIVW.ToString();
            var actual   = eventCartItemsController.ViewData.Model.ToString();

            Assert.NotNull(result);
            Assert.IsAssignableFrom <ViewResult>(result);
            Assert.Equal(expected, actual);
        }
        public void GetEventCartItemsTest()
        {
            var repository = GetMockContext();

            var service = new EventCartItemsService(repository.Object);
            var citems  = new EventCartItem[]
            {
                new EventCartItem()
                {
                    Id      = 1,
                    EventId = 1,
                    UserId  = "1"
                }
            };

            repository.Setup(item => item.GetAllItems(It.IsAny <string>()))
            .Returns(citems);

            var actual = service.GetEventCartItems("1");

            Assert.NotNull(service);
            Assert.Equal(citems.ToString(), actual.ToString());
        }