public MenuController(
     IMenuService menuService,
     ICookieCachingService cacheService)
 {
     this._menuService  = menuService;
     this._cacheService = cacheService;
 }
 public CartController(
     ICookieCachingService cookieCachingService,
     IProductsService productService,
     IOrdersService ordersService,
     IUsersService usersService)
 {
     this._cookieCachingService = cookieCachingService;
     this._productService       = productService;
     this._ordersService        = ordersService;
     this._usersService         = usersService;
 }
Exemplo n.º 3
0
        public async Task Index_WhenNotEmptyCart_ShouldReturnViewWithNotEmptyList()
        {
            var expectedResult = new ProductViewModel
            {
                Description = "Test Description",
                Quantity    = 3,
                Id          = 1,
                Name        = "Test",
                Price       = 2.5
            };

            var cookieCachingServiceMock = new Mock <ICookieCachingService>();
            var cachedProducts           = new List <ProductShoppingCartCache>
            {
                new ProductShoppingCartCache
                {
                    Id          = 1,
                    ProductName = "Test",
                    Quantity    = 3
                }
            };

            cookieCachingServiceMock.Setup(s => s.Get(It.IsAny <string>()))
            .Returns(JsonConvert.SerializeObject(cachedProducts));
            ICookieCachingService cookieCachingServiceObject = cookieCachingServiceMock.Object;

            var productsServiceMock = new Mock <IProductsService>();

            productsServiceMock
            .Setup(s => s.GetProductsByIDsAsync(It.IsAny <IEnumerable <int> >()))
            .ReturnsAsync(new List <ProductDTO>
            {
                new ProductDTO
                {
                    Id          = 1,
                    Name        = "Test",
                    Description = "Test Description",
                    Price       = 2.5
                }
            });
            IProductsService productsServiceObject = productsServiceMock.Object;

            var cartController = new CartController(cookieCachingServiceObject, productsServiceObject, null, null);

            IActionResult actualResult = await cartController.Index();

            var viewResult = Assert.IsType <ViewResult>(actualResult);
            var model      = Assert.IsAssignableFrom <List <ProductViewModel> >(viewResult.ViewData.Model);

            Assert.Single(model);
            expectedResult.Should().BeEquivalentTo(model.FirstOrDefault());
        }