public async Task ReturnsInvalidGivenNullSearchString() { var result = await _searchService.GetAllIncompleteItemsAsync(null); Assert.Equal(Ardalis.Result.ResultStatus.Invalid, result.Status); Assert.Equal("searchString is required.", result.ValidationErrors.First().ErrorMessage); }
public async Task ReturnsListGivenSearchString() { var repo = new Mock <IRepository>(); var service = new ToDoItemSearchService(repo.Object); var result = await service.GetAllIncompleteItemsAsync("foo"); Assert.Equal(Ardalis.Result.ResultStatus.Ok, result.Status); }
public async Task ReturnsInvalidGivenNullSearchString() { var repo = new Mock <IRepository>(); var service = new ToDoItemSearchService(repo.Object); var result = await service.GetAllIncompleteItemsAsync(null); Assert.Equal(Ardalis.Result.ResultStatus.Invalid, result.Status); Assert.Equal("searchString is required.", result.ValidationErrors.First().ErrorMessage); }
public async Task ReturnsErrorGivenDataAccessException() { string expectedErrorMessage = "Database not there."; var repo = new Mock <IRepository>(); var service = new ToDoItemSearchService(repo.Object); repo.Setup(r => r.ListAsync(It.IsAny <ISpecification <ToDoItem> >())) .ThrowsAsync(new System.Exception(expectedErrorMessage)); var result = await service.GetAllIncompleteItemsAsync("something"); Assert.Equal(Ardalis.Result.ResultStatus.Error, result.Status); Assert.Equal(expectedErrorMessage, result.Errors.First()); }