Ejemplo n.º 1
0
        // Split at first ','.

        public static string FirstPartDescription(this JobAdSearch item)
        {
            var description = item.Criteria.GetDisplayText();
            var pos         = description.IndexOf(',');

            return(pos == -1 ? description : description.Substring(0, pos));
        }
Ejemplo n.º 2
0
        private JobAdSearchExecution Search(JobAdSearch search, JobAdSearchAlert alert)
        {
            // Set the criteria recency to ensure only recently added jobs are included in the alert results.

            var criteria = search.Criteria.Clone();

            criteria.Recency = DateTime.Now - alert.LastRunTime;

            // Run the search as the owner.

            var member = new Member {
                Id = search.OwnerId
            };

            // Search.

            var execution = new JobAdSearchExecution
            {
                SearcherId = search.OwnerId,
                Criteria   = search.Criteria,
                Context    = "Alert",
                Results    = _executeJobAdSearchCommand.Search(member, criteria, new Range(0, MaximumResults)).Results,
            };

            // Update the last run time for next time.

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now);
            return(execution);
        }
Ejemplo n.º 3
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.º 4
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.º 5
0
        public static string SecondPartDescription(this JobAdSearch item)
        {
            var description = item.Criteria.GetDisplayText();
            var pos         = description.IndexOf(',');

            return(pos == -1 ? string.Empty : description.Substring(pos + 2));
        }
Ejemplo n.º 6
0
        public void TestDeleteSearchExecutionSharedCriteria()
        {
            // For some older searches the criteria are shared between searches and executions.

            var search = new JobAdSearch {
                Name = SearchName, Criteria = CreateCriteria(0)
            };
            var ownerId = Guid.NewGuid();

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search);

            var execution = new JobAdSearchExecution {
                Criteria = CreateCriteria(0), Results = new JobAdSearchResults(), Context = "xxx"
            };

            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            UpdateCriteriaId(search.Id, execution.Criteria.Id);

            // Delete.

            _jobAdSearchesCommand.DeleteJobAdSearch(ownerId, search.Id);

            Assert.IsNull(_jobAdSearchesQuery.GetJobAdSearch(search.Id));
            AssertExecution(execution, _jobAdSearchesQuery.GetJobAdSearchExecution(execution.Id));
        }
Ejemplo n.º 7
0
        public void TestUpdateSameName()
        {
            var ownerId = Guid.NewGuid();

            // Create 2 searches.

            var savedSearch1 = new JobAdSearch
            {
                Name     = "TestName1",
                Criteria = CreateCriteria(1)
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, savedSearch1);

            var savedSearch2 = new JobAdSearch
            {
                Name     = "TestName2",
                Criteria = CreateCriteria(2)
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, savedSearch2);

            // Update the second to match the first.

            savedSearch2.Name = savedSearch1.Name;
            AssertException.Thrown <ValidationErrorsException>(() => _jobAdSearchesCommand.UpdateJobAdSearch(ownerId, savedSearch2), "A 'LinkMe.Framework.Utility.Validation.DuplicateValidationError' error has occurred for the Name property.");
        }
Ejemplo n.º 8
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.º 9
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.º 10
0
        public void TestCreateFromSavedName()
        {
            var member = CreateMember();

            LogIn(member);

            // Save a search.

            var criteria = GetCriteria();
            var search   = new JobAdSearch {
                Criteria = criteria, Name = SearchName
            };

            _jobAdSearchesCommand.CreateJobAdSearch(member.Id, search);

            // Save as alert.

            AssertJsonSuccess(CreateFromSaved(search.Id));

            // Check.

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

            Assert.AreEqual(1, searches.Count);
            Assert.AreEqual(SearchName, searches[0].Name);
            Assert.AreEqual(criteria, searches[0].Criteria);

            var alert = _jobAdSearchAlertsQuery.GetJobAdSearchAlert(searches[0].Id);

            Assert.IsNotNull(alert);
        }
Ejemplo n.º 11
0
        public ActionResult SaveSearch(string name, bool createAlert)
        {
            try
            {
                var currentSearch = MemberContext.CurrentSearch;
                if (currentSearch == null)
                {
                    return(NotFound("current search"));
                }

                var search = new JobAdSearch
                {
                    Criteria = currentSearch.Criteria,
                    Name     = name,
                };

                if (createAlert)
                {
                    _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(CurrentMember.Id, search, DateTime.Now);
                }
                else
                {
                    _jobAdSearchesCommand.CreateJobAdSearch(CurrentMember.Id, search);
                }

                return(RedirectToReturnUrlWithConfirmation("SHOW SAVED NOTIFICATION"));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(MemberContext.CurrentSearch.Criteria));
        }
Ejemplo n.º 12
0
        public ActionResult CreateSearchFromCurrentSearch(string name, bool createAlert)
        {
            try
            {
                var currentSearch = MemberContext.CurrentSearch;
                if (currentSearch == null)
                {
                    return(JsonNotFound("current search"));
                }

                var search = new JobAdSearch
                {
                    Criteria = currentSearch.Criteria,
                    Name     = name,
                };

                if (createAlert)
                {
                    _jobAdSearchAlertsCommand.CreateJobAdSearchAlert(CurrentMember.Id, search, DateTime.Now);
                }
                else
                {
                    _jobAdSearchesCommand.CreateJobAdSearch(CurrentMember.Id, search);
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }
Ejemplo n.º 13
0
        public void TestMultipleRuns()
        {
            // Create member.

            var member = CreateMember(0);

            // Create a job search.

            var search = new JobAdSearch {
                Criteria = new JobAdSearchCriteria {
                    AdTitle = BusinessAnalyst
                }
            };

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

            // Get the email.

            var employer = CreateEmployer();

            PostJobAd(employer, BusinessAnalyst);

            ExecuteTask();
            _settingsCommand.SetLastSentTime(member.Id, _settingsQuery.GetDefinition("JobSearchAlertEmail").Id, DateTime.Now.AddDays(-1));

            var email = _emailServer.AssertEmailSent();

            email.AssertHtmlViewContains("<strong>1 new job</strong>");

            // Go again.

            ExecuteTask();
            email = _emailServer.AssertEmailSent();
            email.AssertHtmlViewContains("<strong>1 new job</strong>");
        }
Ejemplo n.º 14
0
        void IJobAdsRepository.UpdateJobAdSearch(JobAdSearch search)
        {
            using (var dc = CreateContext())
            {
                var entity = GetSavedJobSearchEntity(dc, search.Id);
                if (entity == null)
                {
                    return;
                }

                // Need to delete all existing criteria.

                if (entity.JobSearchCriteriaSetEntity != null)
                {
                    if (entity.JobSearchCriteriaSetEntity.JobSearchCriteriaEntities != null && entity.JobSearchCriteriaSetEntity.JobSearchCriteriaEntities.Count > 0)
                    {
                        dc.JobSearchCriteriaEntities.DeleteAllOnSubmit(entity.JobSearchCriteriaSetEntity.JobSearchCriteriaEntities);
                    }
                    dc.JobSearchCriteriaSetEntities.DeleteOnSubmit(entity.JobSearchCriteriaSetEntity);
                }

                search.MapTo(entity, _criteriaPersister);

                try
                {
                    dc.SubmitChanges();
                }
                catch (SqlException ex)
                {
                    CheckDuplicates(ex);
                    throw;
                }
            }
        }
Ejemplo n.º 15
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.º 16
0
        public void TestCreateJobAdSearchExecutionWithSearchId()
        {
            // Create the search.

            var ownerId = Guid.NewGuid();
            var search  = new JobAdSearch
            {
                Criteria = CreateCriteria(0),
                Name     = SearchName,
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search);

            // Create the execution.

            var execution = new JobAdSearchExecution
            {
                Criteria   = search.Criteria.Clone(),
                Context    = "Test",
                SearcherId = Guid.NewGuid(),
                SearchId   = search.Id,
                Results    = new JobAdSearchResults
                {
                    JobAdIds = new List <Guid> {
                        Guid.NewGuid()
                    },
                    TotalMatches = 1,
                }
            };

            _jobAdSearchesCommand.CreateJobAdSearchExecution(execution);

            AssertExecution(execution, _jobAdSearchesQuery.GetJobAdSearchExecution(execution.Id));
            AssertExecution(execution, _jobAdSearchesQuery.GetJobAdSearchExecutions(execution.SearcherId.Value, 100)[0]);
        }
Ejemplo n.º 17
0
 private static void AssertSearch(JobAdSearch expectedSearch, JobAdSearch search)
 {
     Assert.AreEqual(expectedSearch.Criteria, search.Criteria);
     Assert.AreEqual(expectedSearch.Name, search.Name);
     Assert.AreEqual(expectedSearch.Id, search.Id);
     Assert.AreEqual(expectedSearch.OwnerId, search.OwnerId);
 }
Ejemplo n.º 18
0
        public void TestDeleteSearchSharedCriteria()
        {
            var ownerId = Guid.NewGuid();

            // For some older searches the criteria are shared between searches.

            var search1 = new JobAdSearch {
                Name = SearchName, Criteria = CreateCriteria(0)
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search1);

            var search2 = new JobAdSearch {
                Name = SearchName2, Criteria = CreateCriteria(0)
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search2);

            UpdateCriteriaId(search1.Id, search2.Criteria.Id);

            // Now delete the first.

            _jobAdSearchesCommand.DeleteJobAdSearch(ownerId, search1.Id);

            Assert.IsNull(_jobAdSearchesQuery.GetJobAdSearch(search1.Id));
            AssertSearch(search2, _jobAdSearchesQuery.GetJobAdSearch(search2.Id));
        }
Ejemplo n.º 19
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.º 20
0
        public void TestNoName()
        {
            var search = new JobAdSearch {
                Name = null, Criteria = CreateCriteria(0)
            };

            _jobAdSearchesCommand.CreateJobAdSearch(Guid.NewGuid(), search);
            AssertSearch(search, _jobAdSearchesQuery.GetJobAdSearch(search.Id));
        }
Ejemplo n.º 21
0
        private void DeleteJobAdSearch(Guid deleterId, JobAdSearch search)
        {
            if (!CanAccessSearch(deleterId, search))
            {
                throw new JobAdSearchesPermissionsException(deleterId, search.Id);
            }

            _repository.DeleteJobAdSearch(search.Id);
        }
Ejemplo n.º 22
0
        public static SavedJobSearchEntity Map(this JobAdSearch search, ICriteriaPersister criteriaPersister)
        {
            var entity = new SavedJobSearchEntity {
                id = search.Id
            };

            search.MapTo(entity, criteriaPersister);
            return(entity);
        }
Ejemplo n.º 23
0
        void IJobAdSearchAlertsCommand.CreateJobAdSearchAlert(Guid creatorId, JobAdSearch search, DateTime lastRunTime)
        {
            // Create the search first.

            _jobAdSearchesCommand.CreateJobAdSearch(creatorId, search);

            // Create the alert.

            CreateJobAdSearchAlert(search.Id, lastRunTime);
        }
Ejemplo n.º 24
0
        public void TestInvalidName()
        {
            var ownerId = Guid.NewGuid();
            var search  = new JobAdSearch
            {
                Criteria = CreateCriteria(0),
                Name     = "#&*&^*(&_(_*()",
            };

            AssertException.Thrown <ValidationErrorsException>(() => _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search), "A 'LinkMe.Framework.Utility.Validation.RegexLengthRangeValidationError' error has occurred for the Name property.");
        }
Ejemplo n.º 25
0
        public void TestDeleteJobAdSearch()
        {
            var search = new JobAdSearch {
                Name = SearchName, Criteria = CreateCriteria(0)
            };
            var ownerId = Guid.NewGuid();

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search);
            _jobAdSearchesCommand.DeleteJobAdSearch(ownerId, search.Id);
            Assert.IsNull(_jobAdSearchesQuery.GetJobAdSearch(search.Id));
        }
Ejemplo n.º 26
0
 void IJobAdSearchesCommand.CreateJobAdSearch(Guid creatorId, JobAdSearch search)
 {
     search.OwnerId = creatorId;
     if (search.Criteria != null)
     {
         search.Criteria.Prepare();
     }
     search.Name = search.Name.NullIfEmpty();
     search.Prepare();
     search.Validate();
     _repository.CreateJobAdSearch(search);
 }
Ejemplo n.º 27
0
        public void TestLastRunTime()
        {
            var definition = _settingsQuery.GetDefinition("JobSearchAlertEmail");
            var employer   = CreateEmployer();
            var jobAd1     = PostJobAd(employer, DateTime.Now.AddDays(-5));
            var jobAd2     = PostJobAd(employer, DateTime.Now.AddDays(-3));
            var jobAd3     = PostJobAd(employer, DateTime.Now.AddDays(-1));

            // Create member.

            var member = CreateMember(0);

            // Create a job search, last run 2 days ago.

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

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

            // Get the email.

            var email = ExecuteTask();

            email.AssertHtmlViewContains("<strong>3 new jobs</strong>");
            AssertJobAds(email, jobAd1, jobAd2, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now.AddDays(-4));
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            email.AssertHtmlViewContains("<strong>2 new jobs</strong>");
            AssertJobAds(email, jobAd2, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now.AddDays(-2));
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            email.AssertHtmlViewContains("<strong>1 new job</strong>");
            AssertJobAds(email, jobAd3);

            _jobAdSearchAlertsCommand.UpdateLastRunTime(search.Id, DateTime.Now);
            _settingsCommand.SetLastSentTime(member.Id, definition.Id, null);

            email = ExecuteTask();
            Assert.IsNull(email);
        }
Ejemplo n.º 28
0
        public void TestRenameJobAdSearch()
        {
            var search = new JobAdSearch {
                Name = SearchName, Criteria = CreateCriteria(0)
            };
            var ownerId = Guid.NewGuid();

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search);

            search.Name = "Another test search";
            _jobAdSearchesCommand.UpdateJobAdSearch(ownerId, search);

            AssertSearch(search, _jobAdSearchesQuery.GetJobAdSearch(search.Id));
        }
Ejemplo n.º 29
0
        void IJobAdSearchesCommand.UpdateJobAdSearch(Guid updaterId, JobAdSearch search)
        {
            if (!CanAccessSearch(updaterId, search))
            {
                throw new JobAdSearchesPermissionsException(updaterId, search.Id);
            }

            if (search.Criteria != null)
            {
                search.Criteria.Prepare();
            }
            search.Name = search.Name.NullIfEmpty();
            search.Validate();
            _repository.UpdateJobAdSearch(search);
        }
Ejemplo n.º 30
0
        private void TestCreate(string name)
        {
            var ownerId = Guid.NewGuid();
            var search  = new JobAdSearch
            {
                Criteria = CreateCriteria(0),
                Name     = name,
            };

            _jobAdSearchesCommand.CreateJobAdSearch(ownerId, search);

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

            Assert.AreEqual(name, gotSearch.Name);
        }