public void GetResourceBasedOnThresholdAsyncTestsShouldValidateInternalResources() { //arrange luisInput.Sentence = searchText; luisInput.Location = locationInput; var luisResponse = luisProxy.GetIntents(searchText); luisResponse.ReturnsForAnyArgs(properLuisResponse); //arrange PagedResources pagedResources = new PagedResources() { Results = resourcesData, ContinuationToken = "[]", TopicIds = topicIds }; var topicResponse = topicsResourcesBusinessLogic.GetTopicsAsync(keyword, locationInput); topicResponse.Returns(topicsData); var resourceCount = topicsResourcesBusinessLogic.GetResourcesCountAsync(resourceFilter); resourceCount.ReturnsForAnyArgs <dynamic>(allResourcesCount); var paginationResult = topicsResourcesBusinessLogic.ApplyPaginationAsync(resourceFilter); paginationResult.ReturnsForAnyArgs <dynamic>(pagedResources); var internalResponse = luis.GetInternalResourcesAsync(keyword, luisInput, Arg.Any <IEnumerable <string> >()); internalResponse.ReturnsForAnyArgs <dynamic>(internalResponse); //act var result = luisBusinessLogic.GetResourceBasedOnThresholdAsync(luisInput).Result; //assert Assert.Contains(expectedInternalResponse, result.ToString()); }
public void GetInternalResourcesAsyncTestsShouldReturnTopIntent() { //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); //act var result = luisBusinessLogic.GetInternalResourcesAsync(keyword, luisInput, Arg.Any <IEnumerable <string> >()).Result; result = JsonConvert.SerializeObject(result); //assert Assert.Contains(keyword, result); }
public void GetInternalResourcesAsyncTestsShouldReturnEmptyResources() { //arrange PagedResources pagedResources = new PagedResources() { TopicIds = new List <string>() }; var topicResponse = topicsResourcesBusinessLogic.GetTopicsAsync(keyword, location); topicResponse.ReturnsForAnyArgs(topicsData); var resourceCount = topicsResourcesBusinessLogic.GetResourcesCountAsync(resourceFilter); resourceCount.ReturnsForAnyArgs <dynamic>(new List <dynamic>()); 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> QueryItemsPaginationAsync(string collectionId, string query, FeedOptions feedOptions) { var docQuery = documentClient.CreateDocumentQuery <dynamic>( UriFactory.CreateDocumentCollectionUri(cosmosDbSettings.DatabaseId, collectionId), query, feedOptions).AsDocumentQuery(); var results = new PagedResources(); List <dynamic> resources = new List <dynamic>(); var queryResult = await docQuery.ExecuteNextAsync(); if (!queryResult.Any()) { return(results); } results.ContinuationToken = queryResult.ResponseContinuation; resources.AddRange(queryResult); results.Results = resources; return(results); }
private dynamic ResourcesCount(PagedResources resources) { List <dynamic> allResources = new List <dynamic> { new { ResourceName = "All", ResourceCount = resources.Results.Count() } }; var groupedResourceType = resources.Results.GroupBy(u => u.resourceType) .OrderBy(group => group.Key) .Select(n => new { ResourceName = n.Key, ResourceCount = n.Count() }).OrderBy(n => n.ResourceName); dynamic resourceList = allResources.Concat(groupedResourceType); return(resourceList); }
public async Task <dynamic> GetPagedResourceAsync(ResourceFilter resourceFilter) { PagedResourceViewModel pagedResourceViewModel = new PagedResourceViewModel(); if (resourceFilter.IsResourceCountRequired) { var groupedResourceType = await GetResourcesCountAsync(resourceFilter); pagedResourceViewModel.ResourceTypeFilter = JsonUtilities.DeserializeDynamicObject <dynamic>(groupedResourceType); } dynamic searchFilter = new JObject(); searchFilter.OrderByField = resourceFilter.OrderByField; searchFilter.OrderBy = resourceFilter.OrderBy; PagedResources pagedResources = await ApplyPaginationAsync(resourceFilter); dynamic serializedToken = pagedResources?.ContinuationToken ?? Constants.EmptyArray; pagedResourceViewModel.Resources = JsonUtilities.DeserializeDynamicObject <dynamic>(pagedResources?.Results); pagedResourceViewModel.ContinuationToken = JsonConvert.DeserializeObject(serializedToken); pagedResourceViewModel.TopicIds = JsonUtilities.DeserializeDynamicObject <dynamic>(pagedResources?.TopicIds); pagedResourceViewModel.SearchFilter = searchFilter; return(JObject.FromObject(pagedResourceViewModel).ToString()); }
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 }); }
public async Task <dynamic> FindItemsWhereArrayContainsWithAndClauseAsync(string arrayName, string propertyName, string andPropertyName, ResourceFilter resourceFilter, bool isResourceCountCall = false) { EnsureParametersAreNotNullOrEmpty(arrayName, propertyName, andPropertyName, resourceFilter.ResourceType); string arrayContainsWithAndClause = ArrayContainsWithOrClause(arrayName, propertyName, resourceFilter.TopicIds); if (!string.IsNullOrEmpty(arrayContainsWithAndClause)) { arrayContainsWithAndClause = "(" + arrayContainsWithAndClause + ")"; } if (resourceFilter.ResourceType.ToUpperInvariant() != Constants.ResourceTypeAll && !isResourceCountCall) { arrayContainsWithAndClause += string.IsNullOrEmpty(arrayContainsWithAndClause) ? $" c.{andPropertyName} = '" + resourceFilter.ResourceType + "'" : $" AND c.{andPropertyName} = '" + resourceFilter.ResourceType + "'"; } string resourceIsActiveFilter = FindItemsWhereResourceIsActive(resourceFilter.ResourceType); if (!string.IsNullOrEmpty(resourceIsActiveFilter)) { arrayContainsWithAndClause = string.IsNullOrEmpty(arrayContainsWithAndClause) ? resourceIsActiveFilter : arrayContainsWithAndClause + " AND " + resourceIsActiveFilter; } string locationFilter = FindLocationWhereArrayContains(resourceFilter.Location); if (!string.IsNullOrEmpty(locationFilter)) { arrayContainsWithAndClause = string.IsNullOrEmpty(arrayContainsWithAndClause) ? locationFilter : arrayContainsWithAndClause + " AND " + locationFilter; } PagedResources pagedResources = new PagedResources(); if (isResourceCountCall) { var query = $"SELECT c.resourceType FROM c WHERE {arrayContainsWithAndClause}"; pagedResources = await backendDatabaseService.QueryResourcesCountAsync(query); } else { var query = $"SELECT * FROM c WHERE {arrayContainsWithAndClause}"; if (resourceFilter.IsOrder) { if (resourceFilter?.OrderByField == "date") { resourceFilter.OrderByField = "modifiedTimeStamp"; } var orderByField = (resourceFilter.OrderByField != null) ? resourceFilter.OrderByField : "name"; query = $"SELECT * FROM c WHERE {arrayContainsWithAndClause} order by c.{orderByField} {resourceFilter.OrderBy}"; } if (resourceFilter.PageNumber == 0) { pagedResources = await backendDatabaseService.QueryPagedResourcesAsync(query, ""); pagedResources.TopicIds = resourceFilter.TopicIds; } else { pagedResources = await backendDatabaseService.QueryPagedResourcesAsync(query, resourceFilter.ContinuationToken); pagedResources.TopicIds = resourceFilter.TopicIds; } } return(pagedResources); }
public async Task <dynamic> GetResourcesCountAsync(ResourceFilter resourceFilter) { PagedResources pagedResources = await dbClient.FindItemsWhereArrayContainsWithAndClauseAsync("topicTags", "id", "resourceType", resourceFilter, true); return(ResourcesCount(pagedResources)); }
public async Task <dynamic> ApplyPaginationAsync(ResourceFilter resourceFilter) { PagedResources pagedResources = await dbClient.FindItemsWhereArrayContainsWithAndClauseAsync("topicTags", "id", "resourceType", resourceFilter); return(pagedResources); }