public void WhenAskForOnlyThePublishedCategories_ShouldReturnOnlyThePublishedCategoriesCount() { // Arange var expectedCategoriesCount = _existigCategories.Count(x => x.Published && !x.Deleted); // Act var categoriesCount = _categoryApiService.GetCategoriesCount(publishedStatus: true); // Assert Assert.AreEqual(expectedCategoriesCount, categoriesCount); }
public void WhenCalledWithUpdatedAtMinParameter_GivenSomeCategoriesUpdatedAfterThatDate_ShouldReturnTheirCount() { // Arange DateTime updatedAtMinDate = _baseDate.AddMonths(5); var expectedCollection = _existigCategories.Where(x => x.UpdatedOnUtc > updatedAtMinDate && !x.Deleted); var expectedCategoriesCount = expectedCollection.Count(); // Act var categoriesCount = _categoryApiService.GetCategoriesCount(updatedAtMin: updatedAtMinDate); // Assert Assert.AreEqual(expectedCategoriesCount, categoriesCount); }
public void WhenCalledWithValidProductId_ShouldReturnOnlyTheCountOfTheCategoriesMappedToThisProduct() { // Arange int productId = 3; var expectedCollectionCount = (from cat in _existigCategories join mapping in _existingCategoryMappings on cat.Id equals mapping.CategoryId where mapping.ProductId == productId orderby cat.Id select cat).Count(); // Act var categoriesCount = _categoryApiService.GetCategoriesCount(productId: productId); // Assert Assert.AreEqual(expectedCollectionCount, categoriesCount); }
public IActionResult GetCategoriesCount(CategoriesCountParametersModel parameters) { var allCategoriesCount = _categoryApiService.GetCategoriesCount(parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, parameters.PublishedStatus, parameters.ProductId); var categoriesCountRootObject = new CategoriesCountRootObject() { Count = allCategoriesCount }; return(Ok(categoriesCountRootObject)); }