コード例 #1
0
        public void WhenCalledWithZeroOrNegativePageParameter_ShouldReturnTheFirstPage(int page)
        {
            //Arange
            var limit = 5;
            var expectedCollection = new ApiList <ShoppingCartItem>(_existigShoppingCartItems.AsQueryable(), page - 1, limit);

            //Act
            var result = _shoppingCartItemApiService.GetShoppingCartItems(limit: limit, page: page);

            // Assert
            CollectionAssert.IsNotEmpty(result);
            Assert.AreEqual(expectedCollection.Count(), result.Count);
            Assert.AreEqual(_existigShoppingCartItems.First().Id, result.First().Id);
            Assert.IsTrue(result.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id)));
        }
        public void WhenCalledWithPageParameter_GivenLimitedProductsCollection_ShouldReturnThePartOfTheCollectionThatCorrespondsToThePage()
        {
            //Arange
            var limit = 5;
            var page  = 6;
            var expectedCollection = new ApiList <Product>(_existigProducts.Where(x => !x.Deleted).AsQueryable(), page - 1, limit);

            //Act
            var products = _productApiService.GetProducts(limit: limit, page: page);

            // Assert
            CollectionAssert.IsNotEmpty(products);
            Assert.AreEqual(expectedCollection.Count(), products.Count);
            Assert.IsTrue(products.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id)));
        }
        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)));
        }
コード例 #4
0
        public void WhenCalledWithNegativePageParameter_GivenLimitedOrdersCollection_ShouldReturnTheFirstPage()
        {
            //Arange
            var limit = 5;
            var page  = -30;
            var expectedCollection = new ApiList <Order>(_existigOrders.Where(x => !x.Deleted).AsQueryable(), page - 1, limit);

            //Act
            var orders = _orderApiService.GetOrders(limit: limit, page: page);

            // Assert
            CollectionAssert.IsNotEmpty(orders);
            Assert.AreEqual(expectedCollection.Count(), orders.Count);
            Assert.AreEqual(_existigOrders.First().Id, orders.First().Id);
            Assert.IsTrue(orders.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id)));
        }
コード例 #5
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 })));
        }