Beispiel #1
0
        public void ReturnsSubcategoryAndItsProducts(int id)
        {
            var result = subcategoryController.Subcategory(id, null, null);

            var expected = new SubcategoryPageDTO
            {
                Subcategory = subcategoriesRepository.GetSubcategory(id),
                Products    = subcategoriesRepository.GetProductsForSubcategory(id)
            };

            Assert.Equal(JsonConvert.SerializeObject(expected),
                         JsonConvert.SerializeObject(result));
        }
        public SubcategoryPageDTO Subcategory(int id, int?page, int?limit)
        {
            var result = new SubcategoryPageDTO
            {
                Subcategory = subcategoriesRepository.GetSubcategory(id),
                Products    = subcategoriesRepository.GetProductsForSubcategory(id, page ?? 1, limit ?? 20)
            };

            foreach (var product in result.Products)
            {
                product.Producer = producerRepository.GetProducer(product.ProducerID);
            }

            return(result);
        }