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 Task <IList <ProfileDto> > Handle(Query request, CancellationToken cancellationToken) { var query = GetProfileQuery(request.Ids); if (request.SinceId > 0) { query = query.Where(profile => profile.Id > request.SinceId); } IList <Profile> profiles = new ApiList <Profile>(query, request.Page - 1, request.Limit); IList <ProfileDto> profilesAsDto = profiles.Select(profile => _dtoHelper.PrepareProfileDto(profile)).ToList(); return(Task.FromResult(profilesAsDto)); }
public void Should_return_part_of_collection_corresponds_to_page_when_given_limited_devices_collection() { //Arrange var limit = 5; var page = 6; var expectedCollection = new ApiList <Device>(_devices.AsQueryable(), page - 1, limit); //Act var result = _deviceApiService.GetDevices(limit: limit, page: page); //Assert CollectionAssert.IsNotEmpty(result); result.Count.ShouldEqual(expectedCollection.Count); Assert.IsTrue(result.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))); }
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))); }
public void Should_return_first_page_when_called_with_negative_page_parameter() { //Arrange var limit = 5; var page = -30; var expectedCollection = new ApiList <Device>(_devices.AsQueryable(), page - 1, limit); //Act var result = _deviceApiService.GetDevices(limit: limit, page: page); //Assert CollectionAssert.IsNotEmpty(result); result.Count.ShouldEqual(expectedCollection.Count); result.First().Id.ShouldEqual(_devices.First().Id); result.Select(x => x.Id).SequenceEqual(expectedCollection.Select(x => x.Id)).ShouldBeTrue(); }
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 }))); }