public IActionResult GetCategories(CategoriesParametersModel parameters) { if (parameters.Page < Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } var allCategories = _categoryApiService.GetCategories(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, 50000, parameters.Page, parameters.SinceId, parameters.ProductId, parameters.PublishedStatus) .Where(c => StoreMappingService.Authorize(c)); IList <CategoryDto> categoriesAsDtos = allCategories.Select(category => { return(_dtoHelper.PrepareCategoryDTO(category)); }).ToList(); var categoriesRootObject = new CategoriesRootObject() { Categories = categoriesAsDtos }; var json = JsonFieldsSerializer.Serialize(categoriesRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public void WhenCalledWithLimitParameter_GivenCategoriesAboveTheLimit_ShouldReturnCollectionWithCountEqualToTheLimit() { //Arange var expectedLimit = 5; //Act var categories = _categoryApiService.GetCategories(limit: expectedLimit); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.AreEqual(expectedLimit, categories.Count); }
public void WhenAskForOnlyThePublishedCategories_ShouldReturnOnlyThePublishedOnesSortedById() { // Arange var expectedCollection = _existigCategories.Where(x => x.Published && !x.Deleted).OrderBy(x => x.Id); // Act var categories = _categoryApiService.GetCategories(publishedStatus: true); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.IsTrue(categories.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
public void WhenCalledWithValidSinceId_ShouldReturnOnlyTheCategoriesAfterThisIdSortedById() { // Arange int sinceId = 3; var expectedCollection = _existigCategories.Where(x => x.Id > sinceId && !x.Deleted).OrderBy(x => x.Id); // Act var categories = _categoryApiService.GetCategories(sinceId: sinceId); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.IsTrue(categories.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
public void WhenCalledWithIdsParameter_GivenCategoriesWithTheSpecifiedIds_ShouldReturnThemSortedById() { var idsCollection = new List <int>() { 1, 5 }; var categories = _categoryApiService.GetCategories(ids: idsCollection); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.AreEqual(idsCollection[0], categories[0].Id); Assert.AreEqual(idsCollection[1], categories[1].Id); }
public void Can_GetCategories() { var categories = _categoryApiService.GetCategories(); // Assert Assert.AreEqual(3, categories.ToList().Count); }
public void WhenCalledWithPageParameter_GivenLimitedCategoriesCollection_ShouldReturnThePartOfTheCollectionThatCorrespondsToThePage() { //Arange var limit = 5; var page = 6; var expectedCollection = new ApiList <Category>(_existigCategories.Where(x => !x.Deleted).AsQueryable(), page - 1, limit); //Act var categories = _categoryApiService.GetCategories(limit: limit, page: page); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.AreEqual(expectedCollection.Count(), categories.Count); Assert.IsTrue(categories.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
public async Task <IActionResult> GetCategories(CategoriesParametersModel parameters) { if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter")); } if (parameters.Page < Constants.Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } var allCategories = _categoryApiService.GetCategories(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId, parameters.ProductId, parameters.PublishedStatus) .WhereAwait(async c => await StoreMappingService.AuthorizeAsync(c)); IList <CategoryDto> categoriesAsDtos = await allCategories.SelectAwait(async category => await _dtoHelper.PrepareCategoryDTOAsync(category)).ToListAsync(); var categoriesRootObject = new CategoriesRootObject { Categories = categoriesAsDtos }; var json = JsonFieldsSerializer.Serialize(categoriesRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public void WhenCalledWithUpdatedAtMinParameter_GivenSomeCategoriesUpdatedAfterThatDate_ShouldReturnThemSortedById() { // Arange DateTime updatedAtMinDate = _baseDate.AddMonths(5); var expectedCollection = _existigCategories.Where(x => x.UpdatedOnUtc > updatedAtMinDate && !x.Deleted).OrderBy(x => x.Id); var expectedCategoriesCount = expectedCollection.Count(); // Act var categories = _categoryApiService.GetCategories(updatedAtMin: updatedAtMinDate); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.AreEqual(expectedCategoriesCount, categories.Count); Assert.IsTrue(categories.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
public IHttpActionResult GetCategories(CategoriesParametersModel parameters) { if (parameters.Limit < Configurations.MinLimit || parameters.Limit > Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter")); } if (parameters.Page < Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } IList <Category> allCategories = _categoryApiService.GetCategories(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId, parameters.ProductId, parameters.PublishedStatus); IList <CategoryDto> categoriesAsDtos = allCategories.Select(category => { CategoryDto categoryDto = category.ToDto(); PrepareDtoAditionalProperties(category, categoryDto); return(categoryDto); }).ToList(); var categoriesRootObject = new CategoriesRootObject() { Categories = categoriesAsDtos }; var json = _jsonFieldsSerializer.Serialize(categoriesRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public void WhenCalledWithValidProductId_ShouldReturnOnlyTheCategoriesMappedToThisProduct() { // Arange int productId = 3; var expectedCollection = (from cat in _existigCategories join mapping in _existingCategoryMappings on cat.Id equals mapping.CategoryId where mapping.ProductId == productId orderby cat.Id select cat); // Act var categories = _categoryApiService.GetCategories(productId: productId); // Assert // Not Empty assert is a good practice when you assert something about collection. Because you can get a false positive if the collection is empty. CollectionAssert.IsNotEmpty(categories); Assert.IsTrue(categories.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id))); }
public async Task <IActionResult> Get() { if (!await _permissionService.Authorize(PermissionSystemName.Categories)) { return(Forbid()); } return(Ok(_categoryApiService.GetCategories())); }