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 int CreateProduct(string productName, int supplierId, int categoryId, string quantityPerUnit,
            decimal unitPrice, short unitsInStock, short unitsOnOrder, short reorderLevel, bool deleted)
        {
            var newProduct = new Product
            {
                ProductName = productName,
                SupplierID = supplierId,
                CategoryID = categoryId,
                QuantityPerUnit = quantityPerUnit,
                UnitPrice = unitPrice,
                UnitsInStock = unitsInStock,
                UnitsOnOrder = unitsOnOrder,
                ReorderLevel = reorderLevel,
                Discontinued = deleted
            };

            _unitOfWork.GetRepository<Product>().Add(newProduct);

            _unitOfWork.SaveChanges();

            return newProduct.ProductID;
        }
        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");
        }