Esempio n. 1
0
        private void AssertSearchExecution(Guid employerId, MemberSearch search)
        {
            var executions = _memberSearchesQuery.GetMemberSearchExecutions(employerId);

            // There should be one that corresponds to the search.

            Assert.AreEqual(true, (from e in executions where e.SearchId == search.Id select e).Any());
        }
Esempio n. 2
0
        private IList <NewsletterSearchModel> GetPreviousSearches(IEmployer employer, IEnumerable <Guid> employerIds, DateTimeRange lastMonth)
        {
            var searches = new List <NewsletterSearchModel>();

            // Start with saved searches.

            var memberSearches = _memberSearchesQuery.GetMemberSearches(new[] { employer.Id }, new Range(0, MaxPreviousSearches));

            AddPreviousSearches(searches, employer, from s in memberSearches select s.Criteria, lastMonth);

            // Previous searches.

            if (searches.Count < MaxPreviousSearches)
            {
                var previousSearches = _memberSearchesQuery.GetMemberSearchExecutions(new[] { employer.Id }, new Range(0, MaxPreviousSearches - searches.Count));
                AddPreviousSearches(searches, employer, from s in previousSearches select s.Criteria, lastMonth);
            }

            // Organisation searches.

            if (searches.Count < MaxPreviousSearches)
            {
                // Do not repeat the employer's searches.

                employerIds = employerIds.Except(new[] { employer.Id }).ToList();

                // Saved searches.

                memberSearches = _memberSearchesQuery.GetMemberSearches(employerIds, new Range(0, MaxPreviousSearches - searches.Count));
                AddPreviousSearches(searches, employer, from s in memberSearches select s.Criteria, lastMonth);

                // Previous searches.

                if (searches.Count < MaxPreviousSearches)
                {
                    var previousSearches = _memberSearchesQuery.GetMemberSearchExecutions(employerIds, new Range(0, MaxPreviousSearches - searches.Count));
                    AddPreviousSearches(searches, employer, from s in previousSearches select s.Criteria, lastMonth);
                }
            }

            return(searches.Take(MaxPreviousSearches).ToList());
        }