Beispiel #1
0
        public IActionResult GetMappings(ProductCategoryMappingsParametersModel 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 <ProductCategoryMappingDto> mappingsAsDtos =
                _productCategoryMappingsService.GetMappings(parameters.ProductId,
                                                            parameters.CategoryId,
                                                            parameters.Limit,
                                                            parameters.Page,
                                                            parameters.SinceId).Select(x => x.ToDto()).ToList();

            var productCategoryMappingRootObject = new ProductCategoryMappingsRootObject()
            {
                ProductCategoryMappingDtos = mappingsAsDtos
            };

            var json = JsonFieldsSerializer.Serialize(productCategoryMappingRootObject, parameters.Fields);

            return(new RawJsonActionResult(json));
        }
Beispiel #2
0
        public void WhenCalledWithLimitParameter_GivenMappingsAboveTheLimit_ShouldReturnCollectionWithCountEqualToTheLimit()
        {
            //Arange
            var expectedLimit = 5;

            //Act
            var categories = _productCategoryMappingsService.GetMappings(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 WhenCalledWithValidSinceId_ShouldReturnOnlyTheMappingsAfterThisIdSortedById()
        {
            // Arange
            var sinceId            = 10;
            var expectedCollection =
                _existigMappings.Where(x => x.Id > sinceId).OrderBy(x => x.Id).Take(Configurations.DefaultLimit);

            // Act
            var mappings = _productCategoryMappingsService.GetMappings(sinceId: 10);

            // 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(mappings);
            Assert.IsTrue(expectedCollection.Select(x => x.Id).SequenceEqual(mappings.Select(x => x.Id)));
        }
Beispiel #4
0
        public void WhenCalledWithLimitAndPageParameter_ShouldReturnTheItemsDeterminedByTheLimiAndPageParameters()
        {
            //Arange
            var limit = 5;
            var page  = 6;
            var expectedCollection = new ApiList <ProductCategory>(_mappings.AsQueryable(), page - 1, limit);

            //Act
            var mappings = _mappingService.GetMappings(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(mappings);
            Assert.AreEqual(expectedCollection.Count(), mappings.Count);
            Assert.IsTrue(mappings.Select(x => new { x.CategoryId, x.ProductId })
                          .SequenceEqual(expectedCollection.Select(x => new { x.CategoryId, x.ProductId })));
        }