public void GetAllWithCategory_ProductsNotFound_ReturnHttpNotFound()
        {
            var mockProductService         = new Mock <IProductService>();
            var mockCategoryService        = new Mock <ICategoryService>();
            var mockCategoryProductService = new Mock <ICategoryAndProductService>();

            var controller = new ProductsController(mockProductService.Object,
                                                    mockCategoryService.Object,
                                                    mockCategoryProductService.Object);

            mockProductService.Setup(x => x.GetAllProductsWithCategory()).Returns(default(List <Product>));

            var result = controller.GetAllWithCategory();
            var model  = result as ViewResult;

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
            Assert.IsNull(model);
        }
        public void GetAllWithCategory_ProductsFound_ReturnsViewResultWithProducts()
        {
            var mockProductService         = new Mock <IProductService>();
            var mockCategoryService        = new Mock <ICategoryService>();
            var mockCategoryProductService = new Mock <ICategoryAndProductService>();

            var controller = new ProductsController(mockProductService.Object,
                                                    mockCategoryService.Object,
                                                    mockCategoryProductService.Object);

            mockProductService.Setup(x => x.GetAllProductsWithCategory()).Returns(GetProducts());

            var result   = controller.GetAllWithCategory() as ViewResult;
            var products = result.ViewData.Model as List <Product>;

            Assert.IsNotNull(products);
            Assert.AreEqual(2, products[1].Id);
            Assert.AreEqual("Test Product 3", products[2].Name);
            Assert.AreEqual("Test Description 1", products[0].Description);
            Assert.AreEqual(4, products[2].CategoryId);
            Assert.AreEqual(4, products.Count);
            Assert.AreEqual("Index", result.ViewName);
        }