public void GetSentFeedBackTest() { var userId = _mockFeedBacks[0].FromUserId; var feedBacks = _dataManager.GetSentFeedBacks(userId); Assert.IsTrue(feedBacks!=null && feedBacks.Count == 5); for (int i = 0; i < 5; i++) { Assert.IsTrue(feedBacks.Exists(f => f.Id == _mockFeedBacks[i].Id)); } var pageInfo = new PagingInfo(); pageInfo.PageSize = 2; for (int i = 0; i < 3; i++) { pageInfo.PageNumber = i + 1; feedBacks = _dataManager.GetSentFeedBacks(userId, pageInfo); if (i != 2) { Assert.IsTrue(feedBacks.Count == 2); } else { Assert.IsTrue(feedBacks.Count == 1); } } }
public void SearchFriendsTest() { var userId = _mockFriends[0].FriendOfUserId; var friends = _dataManager.SearchFriends(userId,""); Assert.IsTrue(friends != null && friends.Count == 12); for (int i = 0; i < 12; i++) { Assert.IsTrue(friends.Exists(f => f.Id == _mockFriends[i].Id)); } //Paging test var pageInfo = new PagingInfo(); pageInfo.PageSize = 5; for (int i = 0; i < 3; i++) { pageInfo.PageNumber = i + 1; friends = _dataManager.SearchFriends(userId, "", pageInfo); if (i != 2) { Assert.IsTrue(friends.Count == 5); } else { Assert.IsTrue(friends.Count == 2); } } //search by name test friends = _dataManager.SearchFriends(userId, "Mahesh"); Assert.IsTrue(friends.Count == 2); friends = _dataManager.SearchFriends(userId, "Tokle"); Assert.IsTrue(friends.Count == 2); }
public List<FeedBack> GetReceivedFeedBacks(string emailId, PagingInfo pagingInfo) { try { if(string.IsNullOrWhiteSpace(emailId)) throw new Exception("Invalid email id"); return _feedBackDataManager.GetReceivedFeedBacks(emailId, pagingInfo); } catch (Exception ex) { Logger.LogException(ex, _source, "GetReceivedFeedBacks", Severity.Normal); } return new List<FeedBack>(); }
public bool SendEmails() { try { PagingInfo pageInfo = new PagingInfo() {PageNumber = 1, PageSize = 20}; var feedBacks = new FeedBackDataManager().GetAllUnseenFeedbacks(pageInfo); while (feedBacks.Count > 0) { foreach (var feedBack in feedBacks) { try { string emailId = feedBack.EmailId.ToLower(); if (!reminderCounts.ContainsKey(emailId)) reminderCounts[emailId] = 0; if (reminderCounts[emailId] < RemConfig.FeedbackReminderCountLimit) { _mailerQueue.Publish(new FeedBackMessageItem() { RoutingKey = RoutingKeys.EMAIL_NOTIFICATION, FeedBack = feedBack, }); reminderCounts[emailId] = reminderCounts[emailId] + 1; } } catch (Exception ex) { ex.Data["EmailId"] = feedBack.EmailId; Logger.LogException(ex, _source, "SendEmails", Severity.Critical); } } pageInfo.PageNumber = pageInfo.PageNumber + 1; feedBacks = new FeedBackDataManager().GetAllUnseenFeedbacks(pageInfo); } //Save new count in the file. StringBuilder emailCount = new StringBuilder(); foreach (var email in reminderCounts.Keys) { emailCount.AppendLine(string.Format("{0}|{1}",email, reminderCounts[email])); } File.WriteAllText(RemConfig.FeedbackReminderCountFilePath, emailCount.ToString()); } catch (Exception ex) { Logger.LogException(ex, _source, "SendEmails", Severity.Critical); return false; } return true; }
private ISearchResponse<Friend> Search(string friendOfUserId, string query, PagingInfo pageInfo) { var baseQueries = Query<Friend>.Term(p => p.FriendOfUserId, friendOfUserId); if (!string.IsNullOrWhiteSpace(query)) { baseQueries = Query<Friend>.Bool(a => a.Should( m => m.Match(f => f.OnField(u => u.FirstName).Query(query).Fuzziness(6)), m => m.Match(f => f.OnField(u => u.LastName).Query(query).Fuzziness(6)) ).MinimumShouldMatch(1)) && baseQueries; } var result = _client.Search<Friend>(d => d .SortDescending(f => f.AddedDate) .From((pageInfo.PageNumber - 1)*pageInfo.PageSize) .Size(pageInfo.PageSize) .Query(baseQueries)); return result; }
public List<Friend> SearchFriends(string friendOfUserId, string query, PagingInfo pageInfo = null) { pageInfo = pageInfo ?? new PagingInfo(); var result = Search(friendOfUserId, query, pageInfo); pageInfo.TotalRecords = (int) result.Total; IsServerError(result); var feedbacks = ExtractFriends(result.Hits); return feedbacks; }
public List<FeedBack> GetAllUnseenFeedbacks(PagingInfo pageInfo) { pageInfo = pageInfo ?? new PagingInfo(); var result = _client.Search<FeedBack>(d => d .From((pageInfo.PageNumber - 1) * pageInfo.PageSize) .Size(pageInfo.PageSize) .Query(q => q.Filtered(t => t.Filter(f => f.Missing(e => e.Status)))) .SortDescending(f => f.UpdatedOn)); IsServerError(result); var feedbacks = ExtractFeedBacks(result.Hits); pageInfo.TotalRecords = (int)result.Total; return feedbacks; }
public List<FeedBack> GetSentFeedBacks(string fromUserId, PagingInfo pageInfo = null) { pageInfo = pageInfo ?? new PagingInfo(); var result = _client.Search<FeedBack>(d => d .From((pageInfo.PageNumber - 1) * pageInfo.PageSize) .Size(pageInfo.PageSize) .Query(q => q.Term(t => t.FromUserId, fromUserId)) .SortDescending(f => f.UpdatedOn)); IsServerError(result); var feedbacks = ExtractFeedBacks(result.Hits); pageInfo.TotalRecords = (int)result.Total; return feedbacks; }