/// <summary> /// Searches the specified search criteria. /// </summary> /// <param name="searchCriteria">The search criteria.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">searchCriteria</exception> public async Task <bool> SearchAsync(IEnumerable <Search> searches, CancellationToken cancellationToken) { //ToDo Pass in a list of Search Criteria complete with names and loop through taht if (searches == null) { throw new ArgumentNullException(nameof(searches)); } //todo loop by names int runs = 0; foreach (var search in searches) { if (runs > search.Criteria.MaxRuns) { logger.InformationEvent("SearchAsync", "Search stopped after exceeding maximum of {maxRuns}", search.Criteria.MaxRuns); break; } var personSearch = await PersonSearchRequestHelper.SearchAsync(search, SearchWaitMs, cancellationToken); logger.InformationEvent("SearchAsync", "Search number {run} returned {numberOfResults} results", runs, personSearch.NumberOfResults); var people = PersonSearchResultHelper.Process(personSearch); runs++; } return(true); }
public async Task SearchAsync_ValidInput_CreatePersonSearchResult() { // Arrange var maxRuns = 1; // Act var cancellationToken = new CancellationToken(); var search = new Search(); var result = await PersonSearchRequestHelper.SearchAsync(search, maxRuns, cancellationToken); // Assert Assert.IsType <PersonSearch>(result); MockRepository.Verify(c => c.Create(It.IsAny <PersonSearch>()), Times.Once); MockRepository.Verify(c => c.SaveAsync(), Times.Exactly(2)); MockFindPersonController.Verify(c => c.GetFindPerson(It.IsAny <Models.Domain.Api.Request.Person>()), Times.Once); MockExport.Verify(c => c.ToJsonAsync(It.IsAny <JObject>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once); }