public void get_shopping_list_should_call_repository_with_paging() { var options = new ShoppingListItemGetList { PageNumber = 2, PageSize = 10 }; _repositoryMock.Setup(x => x.GetItems(options)).Returns(new List <ShoppingListItem>()); var result = _controller.GetItems(options); _repositoryMock.Verify(x => x.GetItems(options)); }
public IHttpActionResult GetItems([FromUri] ShoppingListItemGetList request = null) { List <ShoppingListItem> items; if (request != null) { items = _repository.GetItems(request).ToList(); } else { items = _repository.GetItems().ToList(); } var content = ConvertToShoppingListModel(items); return(Ok <ShoppingList>(content)); }
public void should_not_use_paging_if_page_size_is_invalid(int pageSize) { for (int i = 1; i <= 20; i++) { _dataStore.Add(new ShoppingListItem { ItemName = $"Item{i}", Quantity = 1 }); } var getListOptions = new ShoppingListItemGetList { PageNumber = 10, PageSize = pageSize }; var repository = new ShoppingListRepository(); var items = repository.GetItems(getListOptions); Assert.AreEqual(items.Count, 20); }
public IList <ShoppingListItem> GetItems(ShoppingListItemGetList options) { var items = new List <ShoppingListItem>(); items = _dataStore.ToList(); if (options != null) { if (options.PageNumber.HasValue && options.PageSize.HasValue && options.PageNumber.Value > 0 && options.PageSize > 0) { items = items .Skip((options.PageNumber.Value - 1) * options.PageSize.Value) .Take(options.PageSize.Value) .ToList(); } } return(items); }
public void should_get_shopping_list_from_data_store_with_paging_when_not_first_page() { var pageSize = 10; for (int i = 1; i <= 50; i++) { _dataStore.Add(new ShoppingListItem { ItemName = $"Item{i}", Quantity = 1 }); } var getListOptions = new ShoppingListItemGetList { PageNumber = 3, PageSize = pageSize }; var repository = new ShoppingListRepository(); var items = repository.GetItems(getListOptions); Assert.AreEqual(items.Count, 10); Assert.AreEqual(items[0].ItemName, "Item21"); Assert.AreEqual(items[0].Quantity, 1); Assert.AreEqual(items[pageSize - 1].ItemName, "Item30"); Assert.AreEqual(items[pageSize - 1].Quantity, 1); }