示例#1
0
        public void WhenAskForOnlyThePublishedProducts_ShouldReturnOnlyThePublishedProductsCount()
        {
            // Arange
            var expectedProductsCount = _existigProducts.Count(x => x.Published && !x.Deleted);

            // Act
            var productsCount = _productApiService.GetProductsCount(publishedStatus: true);

            // Assert
            Assert.AreEqual(expectedProductsCount, productsCount);
        }
        public void WhenCalledWithUpdatedAtMinParameter_GivenSomeProductsUpdatedAfterThatDate_ShouldReturnTheirCount()
        {
            // Arange
            DateTime updatedAtMinDate      = _baseDate.AddMonths(5);
            var      expectedCollection    = _existigProducts.Where(x => x.UpdatedOnUtc > updatedAtMinDate && !x.Deleted);
            var      expectedProductsCount = expectedCollection.Count();

            // Act
            var productsCount = _productApiService.GetProductsCount(updatedAtMin: updatedAtMinDate);

            // Assert
            Assert.AreEqual(expectedProductsCount, productsCount);
        }
        public void WhenCalledWithValidCategoryId_ShouldReturnOnlyTheCountOfTheProductsMappedToThisCategory()
        {
            // Arange
            int categoryId = 3;
            var expectedCollectionCount = (from product in _existigProducts
                                           join mapping in _existingCategoryMappings on product.Id equals mapping.ProductId
                                           where mapping.CategoryId == categoryId
                                           select product).Count();

            // Act
            var productsCount = _productApiService.GetProductsCount(categoryId: categoryId);

            // Assert
            Assert.AreEqual(expectedCollectionCount, productsCount);
        }
        public IHttpActionResult GetProductsCount(ProductsCountParametersModel parameters)
        {
            int allProductsCount = _productApiService.GetProductsCount(parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin,
                                                                       parameters.UpdatedAtMax, parameters.PublishedStatus, parameters.VendorName,
                                                                       parameters.CategoryId);

            var productsCountRootObject = new ProductsCountRootObject()
            {
                Count = allProductsCount
            };

            return(Ok(productsCountRootObject));
        }
示例#5
0
        public void WhenCalledWithValidVendorName_ShouldReturnOnlyTheCountOfTheProductsMappedToThisVendor(string vendorName)
        {
            // Arange
            var expectedCollectionCount = (from product in _existigProducts
                                           join vendor in _existingVendors on product.VendorId equals vendor.Id
                                           where vendor.Name == vendorName && !vendor.Deleted && vendor.Active
                                           select product).Count();

            // Act
            var productsCount = _productApiService.GetProductsCount(vendorName: vendorName);

            // Assert
            Assert.AreEqual(expectedCollectionCount, productsCount);
        }