Ejemplo n.º 1
0
        private static JobAdSearchCriteria GetCriteria(int index)
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(Keywords + index);
            return(criteria);
        }
Ejemplo n.º 2
0
        public void TestPaging()
        {
            var jobAds = CreateJobAds(127);

            const int page = 25;

            for (var index = 0; index *page < 200; ++index)
            {
                var criteria = new JobAdSearchCriteria {
                    SortCriteria = new JobAdSearchSortCriteria {
                        SortOrder = JobAdSortOrder.CreatedTime
                    }
                };
                var execution = _executeJobAdSearchCommand.Search(null, criteria, new Range(index * page, page));

                Assert.AreEqual(jobAds.Count, execution.Results.TotalMatches);
                Assert.IsTrue(jobAds.Skip(index * page).Take(page).SequenceEqual(execution.Results.JobAdIds));

                criteria = new JobAdSearchCriteria {
                    SortCriteria = new JobAdSearchSortCriteria {
                        SortOrder = JobAdSortOrder.CreatedTime, ReverseSortOrder = true
                    }
                };
                execution = _executeJobAdSearchCommand.Search(null, criteria, new Range(index * page, page));

                Assert.AreEqual(jobAds.Count, execution.Results.TotalMatches);
                Assert.IsTrue(jobAds.Reverse().Skip(index * page).Take(page).SequenceEqual(execution.Results.JobAdIds));
            }
        }
Ejemplo n.º 3
0
        public void TestLimitByCriteriaAndModifiedSince()
        {
            var integratorUser = _integrationCommand.CreateTestIntegratorUser();
            var employer       = _employerAccountsCommand.CreateTestEmployer(0, _organisationsCommand.CreateTestOrganisation(0));
            var jobAd          = PostJobAd(employer);

            var criteria = new JobAdSearchCriteria {
                AdvertiserName = "Advertiser"
            };

            _jobAdSearchesCommand.CreateJobAdSearch(integratorUser.Id, new JobAdSearch {
                Criteria = criteria
            });
            // Correct modifiedSince, one job ad found.

            var modifiedSince = "2007-01-01T00:00:00Z";
            var response      = JobAds(integratorUser, null, modifiedSince);

            AssertJobAdFeed(employer, jobAd, GetJobAdFeed(response));

            // 24hr modifiedSince, one job ad found (some integrators send this).

            modifiedSince = "2007-01-01T24:00:00Z";
            response      = JobAds(integratorUser, null, modifiedSince);
            AssertJobAdFeed(employer, jobAd, GetJobAdFeed(response));

            // Date in future, no job ad found.

            modifiedSince = string.Format("{0}-01-01T00:00:00Z", DateTime.Now.AddYears(1).Year);
            response      = JobAds(integratorUser, null, modifiedSince);
            Assert.IsNull(GetJobAdFeed(response));
        }
Ejemplo n.º 4
0
        public void TestRenameName()
        {
            var member = CreateMember();

            LogIn(member);

            // Save a search.

            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(Keywords);
            var search = new JobAdSearch {
                Criteria = criteria, Name = SearchName
            };

            _jobAdSearchesCommand.CreateJobAdSearch(member.Id, search);

            // Rename.

            AssertJsonSuccess(RenameSearch(search.Id, SearchNewName));

            // Check.

            var searches = _jobAdSearchesQuery.GetJobAdSearches(member.Id);

            Assert.AreEqual(1, searches.Count);
            Assert.AreEqual(SearchNewName, searches[0].Name);
            Assert.AreEqual(Keywords, searches[0].Criteria.KeywordsExpression.GetUserExpression());
        }
Ejemplo n.º 5
0
        protected TListModel Search <TListModel>(IMember member, JobAdSearchCriteria criteria, JobAdsPresentationModel presentation, JobAdListType listType)
            where TListModel : JobAdSearchListModel, new()
        {
            presentation = PreparePresentationModel(presentation);

            // Search.

            var execution = _executeJobAdSearchCommand.Search(member, criteria, presentation.Pagination.ToRange());

            var model = new TListModel
            {
                Criteria     = execution.Criteria,
                Presentation = presentation,
                ListType     = listType,
                Results      = new JobAdListResultsModel
                {
                    TotalJobAds  = execution.Results.TotalMatches,
                    IndustryHits = execution.Results.IndustryHits.ToDictionary(i => i.Key.ToString(), i => i.Value),
                    JobTypeHits  = GetEnumHitsDictionary(execution.Results.JobTypeHits, JobTypes.All, JobTypes.None),
                    JobAdIds     = execution.Results.JobAdIds,
                    JobAds       = GetMemberJobAdViews(member, execution.Results.JobAdIds),
                },
                Folders    = GetFoldersModel(),
                BlockLists = GetBlockListsModel(),
            };

            return(model);
        }
Ejemplo n.º 6
0
        public void TestClosedAds()
        {
            var employer = CreateEmployer(0);

            var jobAd = CreateJobAd(employer, JobAdStatus.Closed);

            IndexJobAd(jobAd);

            // Search without filter.

            var jobQuery = new JobAdSearchCriteria();
            var results  = Search(null, jobQuery);

            Assert.AreEqual(0, results.Count);

            //Now add an open one

            jobAd = CreateJobAd(employer, JobAdStatus.Open);
            IndexJobAd(jobAd);

            // Search without filter.

            results = Search(null, jobQuery);
            Assert.AreEqual(1, results.Count);

            //Now add another closed one

            jobAd = CreateJobAd(employer, JobAdStatus.Closed);
            IndexJobAd(jobAd);

            // Search without filter.

            results = Search(null, jobQuery);
            Assert.AreEqual(1, results.Count);
        }
Ejemplo n.º 7
0
        protected override void TestDisplay()
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(BusinessAnalyst);

            criteria.SortCriteria = null;
            TestDisplay(false, criteria);

            criteria.SortCriteria = new JobAdSearchSortCriteria {
                SortOrder = JobAdSortOrder.CreatedTime
            };
            TestDisplay(false, criteria);

            criteria.SortCriteria = new JobAdSearchSortCriteria {
                SortOrder = JobAdSortOrder.Salary
            };
            TestDisplay(false, criteria);

            criteria.SortCriteria = new JobAdSearchSortCriteria {
                SortOrder = JobAdSortOrder.CreatedTime, ReverseSortOrder = true
            };
            TestDisplay(false, criteria);

            criteria.SortCriteria = new JobAdSearchSortCriteria {
                SortOrder = JobAdSortOrder.Salary, ReverseSortOrder = true
            };
            TestDisplay(false, criteria);
        }
Ejemplo n.º 8
0
        public ActionResult Search(JobAdSearchCriteria criteria, JobAdsPresentationModel presentation)
        {
            var member = CurrentMember;

            // Prepare.

            var criteriaIsEmpty = PrepareCriteria(criteria);

            presentation = PreparePresentationModel(presentation);

            if (criteriaIsEmpty || !ModelState.IsValid)
            {
                // Set up defaults.

                SetDefaults(criteria);

                if (member != null && MemberContext.ShowUpdatedTermsReminder())
                {
                    ModelState.AddModelConfirmation("We've made some changes to our terms and conditions. You can review them <a href=\"" + SupportRoutes.Terms.GenerateUrl() + "\">here</a>.");
                }

                return(View(GetSearchModel(criteria, presentation)));
            }

            MemberContext.CurrentSearch = new JobAdSearchNavigation(criteria, presentation);
            MemberContext.IsNewSearch   = true;

            return(RedirectToRoute(SearchRoutes.Results));
        }
Ejemplo n.º 9
0
        public static string GetDisplayText(this JobAdSearchCriteria criteria)
        {
            var sb = new StringBuilder();

            sb.AppendText(criteria);
            return(sb.Length == 0 ? AllJobsText : sb.ToString());
        }
Ejemplo n.º 10
0
        private string AssertHash(JsonSearchResponseModel model, JobAdSearchCriteria criteria)
        {
            var hash = model.Hash;

            Assert.AreEqual(GetHash(criteria), hash);
            return(hash);
        }
Ejemplo n.º 11
0
        private string AssertHash(JobAdSearchCriteria criteria)
        {
            var hash = GetPageHash();

            Assert.AreEqual(GetHash(criteria), hash);
            return(hash);
        }
        private void TestSearch(JobAdSearchCriteria criteria, ICollection <string> expectedTitles)
        {
            var execution = _executeJobAdSearchCommand.Search(null, criteria, null);

            Assert.AreEqual(expectedTitles.Count, execution.Results.TotalMatches);
            Assert.AreEqual(expectedTitles.Count, execution.Results.JobAdIds.Count);

            foreach (var expectedTitle in expectedTitles)
            {
                var found = false;
                foreach (var jobAdId in execution.Results.JobAdIds)
                {
                    var jobAd = _jobAdsCommand.GetJobAd <JobAdEntry>(jobAdId);
                    if (jobAd.Title == expectedTitle)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Assert.Fail("Could not find job with title '" + expectedTitle + "'.");
                }
            }
        }
Ejemplo n.º 13
0
        public void TestDeleteSearchAndAlert()
        {
            var member = CreateMember();

            LogIn(member);

            // Save a search.

            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(Keywords);
            var search = new JobAdSearch {
                Criteria = criteria, Name = SearchName
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(member.Id, search, DateTime.Now);

            var gotSearch = _jobAdSearchAlertsQuery.GetJobAdSearch(search.Id);

            Assert.AreEqual(SearchName, gotSearch.Name);
            Assert.AreEqual(criteria, gotSearch.Criteria);
            Assert.IsNotNull(_jobAdSearchAlertsQuery.GetJobAdSearchAlert(search.Id));

            // Delete.

            AssertJsonSuccess(DeleteSearch(search.Id));

            // Check.

            Assert.IsNull(_jobAdSearchAlertsQuery.GetJobAdSearch(search.Id));
            Assert.IsNull(_jobAdSearchAlertsQuery.GetJobAdSearchAlert(search.Id));
        }
Ejemplo n.º 14
0
        protected void TestDisplay(JobAdSearchCriteria criteria)
        {
            // Get the page and check that all fields are set properly.

            Get(GetSearchUrl(criteria));
            AssertCriteria(criteria);
        }
Ejemplo n.º 15
0
        public void TestGetJobAdSearches()
        {
            var criteria = new JobAdSearchCriteria {
                AdTitle = "jobTitle"
            };

            criteria.SetKeywords("keywords");
            var execution = new JobAdSearchExecution
            {
                SearcherId = Guid.NewGuid(),
                Criteria   = criteria,
                Context    = "AdvancedJobSearchContext",
                StartTime  = DateTime.Now.AddDays(-1),
                Results    = new JobAdSearchResults()
            };

            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            criteria = new JobAdSearchCriteria {
                AdTitle = "Developer"
            };
            criteria.SetKeywords("Microsoft");
            execution = new JobAdSearchExecution
            {
                SearcherId = Guid.NewGuid(),
                Criteria   = criteria,
                Context    = "AdvancedJobSearchContext",
                StartTime  = DateTime.Now.AddDays(-1),
                Results    = new JobAdSearchResults()
            };
            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            Assert.AreEqual(2, _jobAdSearchReportsQuery.GetJobAdSearches(DayRange.Yesterday));
        }
Ejemplo n.º 16
0
        public static string GetDisplayHtml(this JobAdSearchCriteria criteria)
        {
            var sb = new StringBuilder();

            sb.AppendHtml(criteria);
            return(sb.ToString());
        }
Ejemplo n.º 17
0
        private static JobAdSearchCriteria CreateCriteria(int index)
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(string.Format(KeywordsFormat, index));
            return(criteria);
        }
Ejemplo n.º 18
0
        protected JsonSearchResponseModel ApiSearch(string keywords)
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(keywords);
            return(ApiSearch(criteria));
        }
Ejemplo n.º 19
0
        private void TestHasApplied(bool?hasApplied)
        {
            var employer = CreateEmployer();
            var jobAd1   = PostJobAd(employer);
            var jobAd2   = PostJobAd(employer);

            var member = CreateMember();

            _internalApplicationsCommand.SubmitApplication(member, jobAd2, null);

            // Search.

            var criteria = new JobAdSearchCriteria
            {
                AdTitle    = BusinessAnalyst,
                HasApplied = hasApplied
            };
            var search = new JobAdSearch {
                Criteria = criteria
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(member.Id, search, DateTime.Now.AddDays(-6));

            // Get the email.

            var email = ExecuteTask();

            var expectedJobAds = hasApplied == null
                ? new[] { jobAd1, jobAd2 }
                : hasApplied.Value
                    ? new[] { jobAd2 }
                    : new[] { jobAd1 };

            AssertJobAds(email, expectedJobAds);
        }
Ejemplo n.º 20
0
        private ReadOnlyUrl Get(ReadOnlyUrl baseUrl, JobAdSearchCriteria criteria, int?page, int?items)
        {
            var url = baseUrl.AsNonReadOnly();

            url.QueryString.Add(new QueryStringGenerator(new JobAdSearchCriteriaConverter(_locationQuery, _industriesQuery)).GenerateQueryString(criteria));

            // In general if all industries are supplied then they are not included in the query string.  However, to simulate the UI
            // which does not make this distinction manually include them here.

            if (criteria.IndustryIds != null && criteria.IndustryIds.CollectionContains(_industriesQuery.GetIndustries().Select(i => i.Id)))
            {
                foreach (var industryId in criteria.IndustryIds)
                {
                    url.QueryString.Add("IndustryIds", industryId.ToString());
                }
            }

            if (page != null)
            {
                url.QueryString["Page"] = page.Value.ToString(CultureInfo.InvariantCulture);
            }
            if (items != null)
            {
                url.QueryString["Items"] = items.Value.ToString(CultureInfo.InvariantCulture);
            }

            return(url);
        }
Ejemplo n.º 21
0
        public void TestRenameToNoName()
        {
            var member = CreateMember();

            LogIn(member);

            // Save a search.

            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(Keywords);
            var search = new JobAdSearch {
                Criteria = criteria, Name = SearchName
            };

            _jobAdSearchesCommand.CreateJobAdSearch(member.Id, search);

            // Rename, can actually remove the name.

            AssertJsonSuccess(RenameSearch(search.Id, null));

            // Check.

            var searches = _jobAdSearchesQuery.GetJobAdSearches(member.Id);

            Assert.AreEqual(1, searches.Count);
            Assert.IsNull(searches[0].Name);
        }
Ejemplo n.º 22
0
        protected void Search(string keywords)
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(keywords);
            Get(GetSearchUrl(criteria));
        }
Ejemplo n.º 23
0
        protected override JobAdSearchCriteria GetCriteria()
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(Keywords);
            return(criteria);
        }
Ejemplo n.º 24
0
        public void TestSnippetContent()
        {
            var employer = _employersCommand.CreateTestEmployer(_organisationsCommand.CreateTestOrganisation(0));

            var poster = new JobPoster {
                Id = employer.Id, SendSuggestedCandidates = false, ShowSuggestedCandidates = true
            };

            _jobPostersCommand.CreateJobPoster(poster);

            var jobAd = _jobAdsCommand.PostTestJobAd(employer, JobAdStatus.Open);

            jobAd.Description.Content += jobAd.Description.Content;
            jobAd.Description.Content += jobAd.Description.Content;

            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords("mutley");
            var highlighter = _highlighterFactory.Create(JobAdHighlighterKind.Full, criteria, new HighlighterConfiguration {
                FragmentSize = 40
            });

            var highlightedText = highlighter.SummarizeContent(jobAd);

            Assert.AreEqual("<span class=\"highlighted-word\">Mutley</span>, you snickering, floppy eared ...  never around.<span class=\"highlighted-word\">Mutley</span>, you snickering, floppy ...  is needed, you're never around.<span class=\"highlighted-word\">Mutley</span>, you snickering", highlightedText);
        }
Ejemplo n.º 25
0
        public void TestMaximum()
        {
            var jobAds = CreateJobAds(127);

            for (var max = 0; max < 200; max += 10)
            {
                var criteria = new JobAdSearchCriteria {
                    SortCriteria = new JobAdSearchSortCriteria {
                        SortOrder = JobAdSortOrder.CreatedTime
                    }
                };
                var execution = _executeJobAdSearchCommand.Search(null, criteria, new Range(0, max));

                Assert.AreEqual(jobAds.Count, execution.Results.TotalMatches);
                Assert.IsTrue(jobAds.Take(max).SequenceEqual(execution.Results.JobAdIds));

                criteria = new JobAdSearchCriteria {
                    SortCriteria = new JobAdSearchSortCriteria {
                        SortOrder = JobAdSortOrder.CreatedTime, ReverseSortOrder = true
                    }
                };
                execution = _executeJobAdSearchCommand.Search(null, criteria, new Range(0, max));

                Assert.AreEqual(jobAds.Count, execution.Results.TotalMatches);
                Assert.IsTrue(jobAds.Reverse().Take(max).SequenceEqual(execution.Results.JobAdIds));
            }
        }
Ejemplo n.º 26
0
        protected override void TestDisplay()
        {
            var criteria = new JobAdSearchCriteria();

            criteria.SetKeywords(AllKeywords, null, null, null);
            TestDisplay(false, criteria);

            criteria.SetKeywords(null, ExactPhrase, null, null);
            TestDisplay(false, criteria);

            criteria.SetKeywords(null, null, AnyKeywords, null);
            TestDisplay(false, criteria);

//            criteria.SetKeywords(AllKeywords, null, null, WithoutKeywords);
//            TestDisplay(false, criteria);

            criteria.SetKeywords(Keywords);
            TestDisplay(false, criteria);

            criteria.SetKeywords(QuotedKeywords);
            TestDisplay(false, criteria);

            criteria.SetKeywords(PartlyQuotedKeywords);
            TestDisplay(false, criteria);

//            criteria.SetKeywords(SimplyQuotedKeywords);
//            TestDisplay(false, criteria);
        }
Ejemplo n.º 27
0
        public void TestAnonymousUser()
        {
            PostJobAd();

            // Create member.

            var contact = CreateAnonymousContact(0);

            // Create a job search.

            var criteria = new JobAdSearchCriteria
            {
                AdTitle = BusinessAnalyst,
            };

            var search = new JobAdSearch {
                Criteria = criteria
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(contact.Id, search, DateTime.Now.AddDays(-1));

            // Get the email.

            var email = ExecuteTask();

            email.AssertHtmlViewContains("<strong>1 new job</strong>");
        }
Ejemplo n.º 28
0
        public static string GetHash(this JobAdSearchCriteria criteria)
        {
            if (criteria == null)
            {
                return(null);
            }

            // Do not include certain criteria if they correspond to defaults.

            var isAlreadyCloned = false;

            if (criteria.Location != null && criteria.Location.IsCountry && criteria.Location.Country.Id == ActivityContext.Current.Location.Country.Id)
            {
                Clone(ref isAlreadyCloned, ref criteria);
                criteria.Location = null;
            }

            if (criteria.Distance != null && criteria.Distance.Value == 0)
            {
                Clone(ref isAlreadyCloned, ref criteria);
                criteria.Distance = null;
            }

            if (criteria.Recency != null && criteria.Recency.Value.Days == JobAdSearchCriteria.DefaultRecency)
            {
                Clone(ref isAlreadyCloned, ref criteria);
                criteria.Recency = null;
            }

            var queryString = criteria.GetQueryString();

            return(queryString.Count > 0 ? queryString.ToString() : null);
        }
Ejemplo n.º 29
0
        private void TestTask(ref int index, Country country, int?distance, string location, ICollection <string> titles, int?totalMatches, bool checkEachLocation)
        {
            // Create member.

            var member = CreateMember(++index);

            // Create a job search.

            var criteria = new JobAdSearchCriteria
            {
                AdTitle  = null,
                Location = _locationQuery.ResolveLocation(country, location),
                Distance = distance
            };

            var search = new JobAdSearch {
                OwnerId = member.Id, Criteria = criteria
            };

            _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(member.Id, search, DateTime.Now.AddDays(-1));

            // Get the email.

            var email = ExecuteTask();

            AssertTitles(email, titles, totalMatches == null ? titles.Count : totalMatches.Value, checkEachLocation);
        }
Ejemplo n.º 30
0
 private static void Clone(ref bool isAlreadyCloned, ref JobAdSearchCriteria criteria)
 {
     if (!isAlreadyCloned)
     {
         criteria = criteria.Clone();
     }
     isAlreadyCloned = true;
 }