public async Task UpdateContactsAsync() { var contacts = await provider.GetContactsAsync(); allContacts = currentlyDisplayedContacts = contacts.ToList(); UpdateNames(); }
public void SetUp() { Provider = A.Fake <IContactProvider <Contact> >(); A.CallTo(() => Provider.GetContactsAsync()) .ReturnsNextFromSequence( Task.FromResult <IEnumerable <Contact> >(FirstProvision), Task.FromResult <IEnumerable <Contact> >(SecondProvision)); }
/// <summary> /// Filters the user's contact list repeatedly based on the user's input to determine the right contact and phone number to call. /// </summary> /// <param name="state">The current conversation state. This will be modified.</param> /// <param name="contactProvider">The provider for the user's contact list. This may be null if the contact list is not to be used.</param> /// <returns>The first boolean indicates whether filtering was actually performed. (In some cases, no filtering is necessary.) /// The second boolean indicates whether any of the contacts has a phone number whose type matches the requested type.</returns> public async Task <(bool, bool)> FilterAsync(PhoneSkillState state, IContactProvider contactProvider) { var isFiltered = false; var searchQuery = string.Empty; if (state.LuisResult.Entities.contactName != null) { searchQuery = string.Join(" ", state.LuisResult.Entities.contactName); } if (searchQuery.Any() && !(searchQuery == state.ContactResult.SearchQuery && state.ContactResult.Matches.Any())) { IList <ContactCandidate> contacts; if (state.ContactResult.Matches.Any()) { contacts = state.ContactResult.Matches; } else if (contactProvider != null) { contacts = await contactProvider.GetContactsAsync(); } else { contacts = new List <ContactCandidate>(); } if (contacts.Any()) { // TODO Adjust max number of returned contacts? var matcher = new EnContactMatcher <ContactCandidate>(contacts, ExtractContactFields); var matches = matcher.FindByName(searchQuery); if (!state.ContactResult.Matches.Any() || matches.Any()) { isFiltered = isFiltered || matches.Count != state.ContactResult.Matches.Count; state.ContactResult.SearchQuery = searchQuery; state.ContactResult.Matches = matches; } } } SetRequestedPhoneNumberType(state); var hasPhoneNumberOfRequestedType = false; (isFiltered, hasPhoneNumberOfRequestedType) = FilterPhoneNumbersByType(state, isFiltered); SetPhoneNumber(state); return(isFiltered, hasPhoneNumberOfRequestedType); }