public void GetProducts_When_Filtered_By_Ids_Returns_CorrectSet()
        {
            // given there are products with suppliers and categories
            var supplier = new Supplier { SupplierID = 1, CompanyName = "Supplier 1" };
            var category = new Category { CategoryID = 1, CategoryName = "Category 1" };
            var products = new List<Product>();

            for (var i = 0; i < 100; i++)
            {
                var product = new Product
                {
                    ProductID = i,
                    ProductName = $"Product {i}",
                    Category = category,
                    Supplier = supplier
                };

                products.Add(product);
            }

            var mockedUnitOfWork = new Mock<IUnitOfWork>();
            var mockedProductRepository = new Mock<IRepository<Product>>();

            mockedUnitOfWork.Setup(e => e.GetRepository<Product>()).Returns(mockedProductRepository.Object);
            mockedProductRepository.Setup(e => e.GetAll()).Returns(products.AsQueryable());

            // when GetProducts is called with id filter
            var productsService = new ProductsService(mockedUnitOfWork.Object);
            var getProductsFilter = new GetProductsFilter {Ids = new[] {1, 7, 15, 22, 9}};
            var productDescriptions = productsService.GetProducts(Int32.MaxValue, 1, getProductsFilter).Data;

            // then correct set of product descriptions are returned
            Assert.IsTrue(productDescriptions.Select(e => e.Id).Intersect(new[] { 1, 7, 15, 22, 9 }).Count() == 5, "Products with ids 1, 7, 15, 22, 9 are returned");
        }
        public void GetCategoryDescriptions_Returns_all_categories()
        {
            // given categories
            var categoryList = new List<Category>();

            for (int i = 0; i < 100; i++)
            {
                var category = new Category
                {
                    CategoryID = i,
                    CategoryName = $"Category {i}"
                };

                categoryList.Add(category);
            }

            var mockedUnitOfWork = new Mock<IUnitOfWork>();
            var mockedCategoryRepository = new Mock<IRepository<Category>>();

            mockedUnitOfWork.Setup(e => e.GetRepository<Category>()).Returns(mockedCategoryRepository.Object);
            mockedCategoryRepository.Setup(e => e.GetAll()).Returns(categoryList.AsQueryable());

            // when GetCategoryDescriptions is called
            var categoryService = new CategoryService(mockedUnitOfWork.Object);
            var categories = categoryService.GetCategoryDescriptions();

            // then all categories are returned
            Assert.IsTrue(categories.Count() == 100);
        }
        public void GetProducts_Returns_ProductDescriptions()
        {
            var entriesPerPage = 5;
            var page = 2;

            // given there are products with suppliers and categories
            var supplier = new Supplier { SupplierID = 1, CompanyName = "Supplier 1" };
            var category = new Category { CategoryID = 1, CategoryName = "Category 1" };
            var products = new List<Product>();

            for (var i = 0; i < 100; i++)
            {
                var product = new Product
                {
                    ProductID = i,
                    ProductName = $"Product {i}",
                    Category = category,
                    Supplier = supplier
                };

                products.Add(product);
            }

            var mockedUnitOfWork = new Mock<IUnitOfWork>();
            var mockedProductRepository = new Mock<IRepository<Product>>();

            mockedUnitOfWork.Setup(e => e.GetRepository<Product>()).Returns(mockedProductRepository.Object);
            mockedProductRepository.Setup(e => e.GetAll()).Returns(products.AsQueryable());

            // when GetProducts is called
            var productsService = new ProductsService(mockedUnitOfWork.Object);
            var productDescriptions = productsService.GetProducts(entriesPerPage, page).Data;

            // then correct set of ProductDescriptions are returned
            Assert.IsTrue(productDescriptions.Count() == 5, "Descriptions for 5 products are returned");
            Assert.IsTrue(productDescriptions.Select(e => e.Id).Intersect(new [] { 5, 6, 7, 8, 9 }).Count() == 5, "Products in page 2 are returned");
        }