public void GetInternalResourcesAsyncTestsShouldReturnProperResult() { //arrange PagedResources pagedResources = new PagedResources() { Results = resourcesData, ContinuationToken = "[]", TopicIds = topicIds }; var topicResponse = topicsResourcesBusinessLogic.GetTopicsAsync(keyword, location); topicResponse.ReturnsForAnyArgs(topicsData); var resourceCount = topicsResourcesBusinessLogic.GetResourcesCountAsync(resourceFilter); resourceCount.ReturnsForAnyArgs <dynamic>(allResourcesCount); var paginationResult = topicsResourcesBusinessLogic.ApplyPaginationAsync(resourceFilter); paginationResult.ReturnsForAnyArgs <dynamic>(pagedResources); luisInput.Location = new Location { State = "AK" }; //act var result = luisBusinessLogic.GetInternalResourcesAsync(keyword, luisInput, Arg.Any <IEnumerable <string> >()).Result; result = JsonConvert.SerializeObject(result); //assert Assert.Contains(expectedTopicId, result); }
public async Task <dynamic> GetInternalResourcesAsync(string keyword, LuisInput luisInput, IEnumerable <string> relevantIntents) { CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; Location location = luisInput.Location; var topics = await topicsResourcesBusinessLogic.GetTopicsAsync(textInfo.ToTitleCase(keyword), location); List <string> topicIds = new List <string>(); foreach (var item in topics) { string topicId = item.id; topicIds.Add(topicId); } if (topicIds.Count == 0 || location == null) { return(new LuisViewModel { TopIntent = keyword }); } ResourceFilter resourceFilter = new ResourceFilter { TopicIds = topicIds, PageNumber = 0, ResourceType = Constants.All, Location = location }; var GetResourcesTask = topicsResourcesBusinessLogic.GetResourcesCountAsync(resourceFilter); ResourceFilter sortResourceFilter = resourceFilter; sortResourceFilter.IsOrder = true; sortResourceFilter.OrderByField = luisInput.OrderByField; sortResourceFilter.OrderBy = luisInput.OrderBy; var ApplyPaginationTask = topicsResourcesBusinessLogic.ApplyPaginationAsync(sortResourceFilter); //To get guided assistant id resourceFilter.ResourceType = Constants.GuidedAssistant; var GetGuidedAssistantId = topicsResourcesBusinessLogic.ApplyPaginationAsync(resourceFilter); await Task.WhenAll(GetResourcesTask, ApplyPaginationTask, GetGuidedAssistantId); var groupedResourceType = GetResourcesTask.Result; PagedResources resources = ApplyPaginationTask.Result; PagedResources guidedAssistantResponse = GetGuidedAssistantId.Result; var guidedAssistantResult = guidedAssistantResponse != null?JsonUtilities.DeserializeDynamicObject <GuidedAssistant>(guidedAssistantResponse.Results.FirstOrDefault()) : null; dynamic searchFilter = new JObject(); searchFilter.OrderByField = resourceFilter.OrderByField; searchFilter.OrderBy = resourceFilter.OrderBy; return(new LuisViewModel { TopIntent = keyword, RelevantIntents = relevantIntents != null?JsonUtilities.DeserializeDynamicObject <dynamic>(relevantIntents) : JsonConvert.DeserializeObject(Constants.EmptyArray), Topics = topics != null?JsonUtilities.DeserializeDynamicObject <dynamic>(topics) : JsonConvert.DeserializeObject(Constants.EmptyArray), Resources = resources != null?JsonUtilities.DeserializeDynamicObject <dynamic>(resources.Results) : JsonConvert.DeserializeObject(Constants.EmptyArray), ContinuationToken = resources != null && resources.ContinuationToken != null?JsonConvert.DeserializeObject(resources.ContinuationToken) : JsonConvert.DeserializeObject(Constants.EmptyArray), TopicIds = topicIds != null?JsonUtilities.DeserializeDynamicObject <dynamic>(topicIds) : JsonConvert.DeserializeObject(Constants.EmptyArray), ResourceTypeFilter = groupedResourceType != null?JsonUtilities.DeserializeDynamicObject <dynamic>(groupedResourceType) : JsonConvert.DeserializeObject(Constants.EmptyArray), GuidedAssistantId = guidedAssistantResult != null ? guidedAssistantResult.CuratedExperienceId : string.Empty, SearchFilter = searchFilter }); }