Esempio n. 1
0
        public void GetListFromCookies_IfNullReturnNull()
        {
            using (var homeController = new HomeController(MockData.MoqLogger(), MockData.MoqShopContext(),
                                                           MockData.MoqEmailSender(), MockData.MoqMyLogger()))
            {
                var controllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        Session = new MockHttpSession()
                    }
                };

                homeController.ControllerContext = controllerContext;
                homeController.HttpContext.Session.Set(WebConst.SessionCart, (List <OrderedBook>)null);

                var result = homeController.GetListFromCookies();

                Assert.Null(result);
            }
        }
Esempio n. 2
0
        public void GetListFromCookies_IfNotEmptyReturnList()
        {
            using (var homeController = new HomeController(MockData.MoqLogger(), MockData.MoqShopContext(),
                                                           MockData.MoqEmailSender(), MockData.MoqMyLogger()))
            {
                OrderedBook orderedBook1 = new OrderedBook {
                    BookId = 1, Quantity = 3
                };
                OrderedBook orderedBook2 = new OrderedBook {
                    BookId = 2, Quantity = 4
                };
                OrderedBook orderedBook3 = new OrderedBook {
                    BookId = 3, Quantity = 1
                };
                List <OrderedBook> mockOrderedBookList = new List <OrderedBook>();
                mockOrderedBookList.Add(orderedBook1);
                mockOrderedBookList.Add(orderedBook2);
                mockOrderedBookList.Add(orderedBook3);

                var controllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        Session = new MockHttpSession()
                    }
                };

                homeController.ControllerContext = controllerContext;
                homeController.HttpContext.Session.Set(WebConst.SessionCart, mockOrderedBookList);

                var result = homeController.GetListFromCookies();

                Assert.Equal(3, result.Count);
                Assert.Equal(4, result.FirstOrDefault(x => x.BookId == 2)?.Quantity ?? 0);
            }
        }