public async Task <Result <List <ToDoItem> > > GetAllIncompleteItemsAsync(string searchString) { if (string.IsNullOrEmpty(searchString)) { var errors = new List <ValidationError>(); errors.Add(new ValidationError() { Identifier = nameof(searchString), ErrorMessage = $"{nameof(searchString)} is required." }); return(Result <List <ToDoItem> > .Invalid(errors)); } var incompleteSpec = new IncompleteItemsSpecification(); try { var items = await _repository.ListAsync(incompleteSpec); return(new Result <List <ToDoItem> >(items)); } catch (Exception ex) { // TODO: Log details here return(Result <List <ToDoItem> > .Error(new[] { ex.Message })); } }
public async Task <Result <ToDoItem> > GetNextIncompleteItemAsync() { var incompleteSpec = new IncompleteItemsSpecification(); var items = await _repository.ListAsync(incompleteSpec); if (!items.Any()) { return(Result <ToDoItem> .NotFound()); } return(new Result <ToDoItem>(items.First())); }
public void FilterCollectionToOnlyReturnItemsWithIsDoneFalse() { var item1 = new ToDoItem(); var item2 = new ToDoItem(); var item3 = new ToDoItem(); item3.MarkComplete(); var items = new List <ToDoItem>() { item1, item2, item3 }; var spec = new IncompleteItemsSpecification(); List <ToDoItem> filteredList = items .Where(spec.WhereExpressions.First().Compile()) .ToList(); Assert.Contains(item1, filteredList); Assert.Contains(item2, filteredList); Assert.DoesNotContain(item3, filteredList); }
public async Task OnGetAsync() { var spec = new IncompleteItemsSpecification(); ToDoItems = await _repository.ListAsync(spec); }